aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/main.go b/main.go
index 1a5a72b..d7acac1 100644
--- a/main.go
+++ b/main.go
@@ -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