added tui
This commit is contained in:
		
							
								
								
									
										17
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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.")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user