fixed accessability colors and cleaned comments

This commit is contained in:
John O'Keefe 2023-12-08 19:05:29 -05:00
parent 7bbfda6409
commit cd941153c6
2 changed files with 11 additions and 11 deletions

View File

@ -1,10 +1,15 @@
package main
import "log"
import (
"os"
"github.com/pterm/pterm"
)
func Error(err error) {
if err != nil {
log.Fatal(err)
pterm.Error.Println(err)
os.Exit(1)
}
return
}

13
main.go
View File

@ -11,12 +11,12 @@ import (
)
func main() {
pterm.DefaultHeader.Println("Welcome to Checkdigit Calculator")
pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgCyan)).WithTextStyle(pterm.NewStyle(pterm.FgCyan)).Println("Welcome to Checkdigit Calculator")
directory, err := os.Getwd()
Error(err)
pterm.DefaultBasicText.Printf("What is the name of the file in this directory?: ")
pterm.Printf(pterm.Cyan("What is the name of the file in this directory?: "))
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
Error(err)
@ -35,8 +35,6 @@ func main() {
fmt.Println(scanner.Err())
}
// upcProgressbar, err := pterm.DefaultProgressbar.WithTotal(len(upcs)).WithTitle("Processing UPCs").Start()
pterm.DefaultSpinner.Start()
Error(err)
@ -108,11 +106,8 @@ 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)
@ -126,10 +121,10 @@ func main() {
for _, gtin := range gtins {
_, err := answerFile.WriteString(gtin + "\n")
Error(err)
// answerProgressbar.Increment()
}
pterm.DefaultSpinner.Stop()
pterm.DefaultBasicText.Println("The answer.txt file has been successfully generated with check digits.")
pterm.Println("\n")
pterm.Success.Println("The answer.txt file has been successfully generated with check digits.")
}