Skip to content

Commit

Permalink
chore: clean up code slightly
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Gleich <git@mattglei.ch>
  • Loading branch information
gleich committed Aug 5, 2024
1 parent aa75c8a commit 20c995d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cmd/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ import (
)

func main() {
logger := lumber.NewCustomLogger()
nytime, err := time.LoadLocation("America/New_York")
if err != nil {
lumber.Fatal(err, "failed to load new york timezone")
}
logger.Timezone = nytime
lumber.SetLogger(logger)
setupLogger()

err = godotenv.Load()
err := godotenv.Load()
if err != nil {
lumber.Fatal(err, "loading .env failed")
}
Expand All @@ -39,6 +33,16 @@ func main() {
startSSH()
}

func setupLogger() {
logger := lumber.NewCustomLogger()
nytime, err := time.LoadLocation("America/New_York")
if err != nil {
lumber.Fatal(err, "failed to load new york timezone")
}
logger.Timezone = nytime
lumber.SetLogger(logger)
}

func startHTTP() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://github.com/gleich/terminal", http.StatusTemporaryRedirect)
Expand Down Expand Up @@ -69,7 +73,6 @@ func startSSH() {

prefix := out.String("λ ").Foreground(colors.Green)
terminal := term.NewTerminal(s, prefix.String())
consecutiveFails := 0
for {
cmd, err := terminal.ReadLine()
if err == io.EOF {
Expand All @@ -92,10 +95,6 @@ func startSSH() {
out.ClearScreen()
default:
fmt.Fprintf(s, "\nInvalid command '%s'.\n\n", cmd)
consecutiveFails++
if consecutiveFails > 10 {
return
}
}
}
}
Expand Down

0 comments on commit 20c995d

Please sign in to comment.