Added loading bar to the generator

This commit is contained in:
raul 2024-03-19 11:34:09 +01:00
parent 87483309be
commit 5df3e0d2c7
1 changed files with 26 additions and 3 deletions

29
main.go
View File

@ -22,6 +22,24 @@ func main() {
minNumInt, _ := strconv.Atoi(minNum) minNumInt, _ := strconv.Atoi(minNum)
maxNumInt, _ := strconv.Atoi(maxNum) maxNumInt, _ := strconv.Atoi(maxNum)
//var writerIsFinished bool
// go func() {
// loading := "Loading"
// for {
// for i := 0; i <= 3; i++ {
// fmt.Printf("\r")
// fmt.Printf("\r%v", loading)
// loading = loading + "."
// time.Sleep(time.Second)
// if writerIsFinished == true {
// fmt.Printf("\rFinished!\n")
// os.Exit(2)
// }
// }
// loading = "Loading"
// }
// }()
writer(name, minNumInt, maxNumInt) writer(name, minNumInt, maxNumInt)
@ -35,7 +53,7 @@ func reverseString(str string) (revStr string) {
return revStr return revStr
} }
func writer(name string, low int, high int) { func writer(name string, low int, high int) (finished bool) {
file, err := os.OpenFile("./passwords.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0640) file, err := os.OpenFile("./passwords.txt", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0640)
if err != nil { if err != nil {
log.Fatalf("Error occurred: %v\n", err) log.Fatalf("Error occurred: %v\n", err)
@ -45,10 +63,15 @@ func writer(name string, low int, high int) {
reverseName := reverseString(name) reverseName := reverseString(name)
nameToWrite := fmt.Sprintf("%v_%v_", name, reverseName) nameToWrite := fmt.Sprintf("%v_%v_", name, reverseName)
//fmt.Println(name, reverseName, nameToWrite) //fmt.Println(name, reverseName, nameToWrite)
highFloat := float64(high)
for i := low; i <= high; i++ { for i := low; i <= high; i++ {
fmt.Printf("Writing \"%v%v\" to passwords.txt...\n", nameToWrite, i) lowfloat := float64(i)
//fmt.Printf("Writing \"%v%v\" to passwords.txt...\n", nameToWrite, i)
fmt.Printf("\r%.2f%% / 100%%", (lowfloat/highFloat)*100)
file.WriteString(nameToWrite + fmt.Sprintln(i)) file.WriteString(nameToWrite + fmt.Sprintln(i))
//time.Sleep(time.Millisecond * 50)
} }
fmt.Println()
finished = true
return true
} }