diff options
author | Joop Kiefte <ikojba@gmail.com> | 2023-09-28 02:19:53 +0100 |
---|---|---|
committer | Joop Kiefte <ikojba@gmail.com> | 2023-09-28 02:19:53 +0100 |
commit | 8522596998d08c317ff8dd6e183f4ed99cd477af (patch) | |
tree | 4a41138ae678777455366a30925d337bff12f80c | |
parent | d6b84a0e738c89c4d699754cd03db3bc6dbfb900 (diff) |
Improve readline
-rw-r--r-- | main.go | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -7,6 +7,7 @@ import ( "os/exec" "strings" "sync" + "bufio" ) var once = sync.Once{} @@ -56,7 +57,7 @@ Running debby with any other arguments will run it as a dolt command.` if query == "" { // Request query fmt.Print("Enter your query: ") - fmt.Scanln(&query) + query = Readline() } // Table name will be empty. Run query @@ -65,7 +66,7 @@ Running debby with any other arguments will run it as a dolt command.` if table == "" { // Request table name fmt.Print("Enter your table name: ") - fmt.Scanln(&table) + table = Readline() } // Run query @@ -74,8 +75,7 @@ Running debby with any other arguments will run it as a dolt command.` if len(args) == 0 { // Request command. Make dolt bold fmt.Print("\033[1mdolt\033[0m ") - argstr := "" - fmt.Scanln(&argstr) + argstr := Readline() args = strings.Split(argstr, " ") } @@ -106,7 +106,8 @@ Running debby with any other arguments will run it as a dolt command.` fmt.Print("- Enter your choice: ") // Read user input - fmt.Scanln(&choice) + choicestr := Readline() + choice = int(choicestr[0] - '0') // Reset all variables except choice table = "" @@ -115,6 +116,13 @@ Running debby with any other arguments will run it as a dolt command.` } } +func Readline() string { + // Read a line from stdin + reader := bufio.NewReader(os.Stdin) + text, _ := reader.ReadString('\n') + return text +} + func ExecuteDoltCommand(args ...string) { cmd := exec.Command("dolt", args...) cmd.Stdout = os.Stdout |