diff options
author | Diego Pereira <diegop@pm.me> | 2024-03-31 20:38:09 -0300 |
---|---|---|
committer | Mauricio Antunes <mauricio.abreua@gmail.com> | 2024-04-01 09:45:35 -0300 |
commit | a924f97c55cdcdbca5911a38aa8329977f4fdc7e (patch) | |
tree | fc3b01f6596ac93330fc6769045f036a15853009 | |
parent | aae9d1e020f7fdb1a9a00461c7a15e891d62642d (diff) |
fix: display progress at every exercise output
-rw-r--r-- | golings/cmd/print.go | 9 | ||||
-rw-r--r-- | golings/cmd/watch.go | 9 | ||||
-rw-r--r-- | golings/exercises/list.go | 24 |
3 files changed, 21 insertions, 21 deletions
diff --git a/golings/cmd/print.go b/golings/cmd/print.go index c5565c7..89237ac 100644 --- a/golings/cmd/print.go +++ b/golings/cmd/print.go @@ -1,6 +1,7 @@ package cmd import ( + "fmt" "os" "os/exec" "runtime" @@ -30,6 +31,14 @@ func PrintList(infoFile string) { func RunNextExercise(infoFile string) { ClearScreen() + + progress, err:= exercises.Progress(infoFile) + if err != nil { + fmt.Fprintln(os.Stderr, err) + } else { + color.Blue("%.2f%% done.\n\n", progress * 100) + } + exercise, err := exercises.NextPending(infoFile) if err != nil { color.Red("Failed to find next exercises") diff --git a/golings/cmd/watch.go b/golings/cmd/watch.go index f556f2d..afe488b 100644 --- a/golings/cmd/watch.go +++ b/golings/cmd/watch.go @@ -12,8 +12,6 @@ import ( "github.com/fatih/color" "github.com/fsnotify/fsnotify" "github.com/spf13/cobra" - - "github.com/mauricioabreu/golings/golings/exercises" ) func WatchCmd(infoFile string) *cobra.Command { @@ -34,13 +32,6 @@ func WatchCmd(infoFile string) *cobra.Command { } }() - progress, err:= exercises.Progress(infoFile) - if err != nil { - fmt.Fprintln(os.Stderr, err) - } else { - color.Blue("\n%.2f%% done.", progress * 100) - } - cmdString, err := reader.ReadString('\n') if err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/golings/exercises/list.go b/golings/exercises/list.go index e30fe79..0c477a1 100644 --- a/golings/exercises/list.go +++ b/golings/exercises/list.go @@ -60,16 +60,16 @@ func Find(exercise string, infoFile string) (Exercise, error) { } func Progress(infoFile string) (float32, error) { - allExercises, err := List(infoFile) - if err != nil { - return 0.0, err - } - done := []Exercise{} - for _, exercise := range allExercises { - if exercise.State() == Done { - done = append(done, exercise) - } - } - - return float32(len(done)) / float32(len(allExercises)), nil + allExercises, err := List(infoFile) + if err != nil { + return 0.0, err + } + done := []Exercise{} + for _, exercise := range allExercises { + if exercise.State() == Done { + done = append(done, exercise) + } + } + + return float32(len(done)) / float32(len(allExercises)), nil } |