added tui
This commit is contained in:
parent
ab66c88ffb
commit
ff8e2ee079
17
main.go
17
main.go
@ -6,16 +6,17 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pterm/pterm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
pterm.DefaultHeader.Println("Welcome to Checkdigit Calculator")
|
||||||
fmt.Println("Welcome to Checkdigit Calculator")
|
|
||||||
|
|
||||||
directory, err := os.Getwd()
|
directory, err := os.Getwd()
|
||||||
Error(err)
|
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)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
input, err := reader.ReadString('\n')
|
input, err := reader.ReadString('\n')
|
||||||
Error(err)
|
Error(err)
|
||||||
@ -34,6 +35,10 @@ func main() {
|
|||||||
fmt.Println(scanner.Err())
|
fmt.Println(scanner.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upcProgressbar, err := pterm.DefaultProgressbar.WithTotal(len(upcs)).WithTitle("Processing UPCs").Start()
|
||||||
|
|
||||||
|
Error(err)
|
||||||
|
|
||||||
var gtins []string
|
var gtins []string
|
||||||
|
|
||||||
for _, upc := range upcs {
|
for _, upc := range upcs {
|
||||||
@ -101,8 +106,11 @@ func main() {
|
|||||||
remainderString := strconv.Itoa(remainder)
|
remainderString := strconv.Itoa(remainder)
|
||||||
|
|
||||||
gtins = append(gtins, upc+remainderString)
|
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 {
|
if _, err := os.Stat(directory + "/answer.txt"); err == nil {
|
||||||
e := os.Remove(directory + "/answer.txt")
|
e := os.Remove(directory + "/answer.txt")
|
||||||
Error(e)
|
Error(e)
|
||||||
@ -116,7 +124,8 @@ func main() {
|
|||||||
for _, gtin := range gtins {
|
for _, gtin := range gtins {
|
||||||
_, err := answerFile.WriteString(gtin + "\n")
|
_, err := answerFile.WriteString(gtin + "\n")
|
||||||
Error(err)
|
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.")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user