From ff8e2ee07992b5112d4878dc17c0b0d4dd2011ef Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 8 Dec 2023 13:22:19 -0500 Subject: [PATCH] added tui --- main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 41cb2a5..42d85d0 100644 --- a/main.go +++ b/main.go @@ -6,16 +6,17 @@ import ( "os" "strconv" "strings" + + "github.com/pterm/pterm" ) func main() { - - fmt.Println("Welcome to Checkdigit Calculator") + pterm.DefaultHeader.Println("Welcome to Checkdigit Calculator") directory, err := os.Getwd() Error(err) - fmt.Printf("What is the name of the file in this directory?: ") + pterm.DefaultBasicText.Printf("What is the name of the file in this directory?: ") reader := bufio.NewReader(os.Stdin) input, err := reader.ReadString('\n') Error(err) @@ -34,6 +35,10 @@ func main() { fmt.Println(scanner.Err()) } + upcProgressbar, err := pterm.DefaultProgressbar.WithTotal(len(upcs)).WithTitle("Processing UPCs").Start() + + Error(err) + var gtins []string for _, upc := range upcs { @@ -101,8 +106,11 @@ func main() { remainderString := strconv.Itoa(remainder) gtins = append(gtins, upc+remainderString) + upcProgressbar.Increment() } + answerProgressbar, err := pterm.DefaultProgressbar.WithTotal(len(gtins)).WithTitle("Processing UPCs").Start() + if _, err := os.Stat(directory + "/answer.txt"); err == nil { e := os.Remove(directory + "/answer.txt") Error(e) @@ -116,7 +124,8 @@ func main() { for _, gtin := range gtins { _, err := answerFile.WriteString(gtin + "\n") Error(err) + answerProgressbar.Increment() } - fmt.Println("The answer.txt file has been successfully generated with check digits.") + pterm.DefaultBasicText.Println("The answer.txt file has been successfully generated with check digits.") }