Added "clear" command to tile38-cli

issue #633
This commit is contained in:
tidwall 2022-03-08 16:13:50 -07:00
parent 10f85640c0
commit e72b0e8f81
1 changed files with 21 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import (
"io" "io"
"net" "net"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort" "sort"
@ -145,7 +146,7 @@ func main() {
return return
} }
if len(oneCommand) > 0 && (oneCommand[0] == 'h' || oneCommand[0] == 'H') && strings.Split(strings.ToLower(oneCommand), " ")[0] == "help" { if len(oneCommand) > 0 && strings.Split(strings.ToLower(oneCommand), " ")[0] == "help" {
showHelp() showHelp()
return return
} }
@ -305,20 +306,24 @@ func main() {
if !nohist { if !nohist {
line.AppendHistory(command) line.AppendHistory(command)
} }
if (command[0] == 'e' || command[0] == 'E') && strings.ToLower(command) == "exit" { if strings.ToLower(command) == "exit" {
return return
} }
if (command[0] == 'q' || command[0] == 'Q') && strings.ToLower(command) == "quit" { if strings.ToLower(command) == "quit" {
return return
} }
if (command[0] == 'h' || command[0] == 'H') && (strings.ToLower(command) == "help" || strings.HasPrefix(strings.ToLower(command), "help")) { if strings.ToLower(command) == "clear" {
clearScreen()
continue
}
if strings.ToLower(command) == "help" || strings.HasPrefix(strings.ToLower(command), "help") {
err = help(strings.TrimSpace(command[4:])) err = help(strings.TrimSpace(command[4:]))
if err != nil { if err != nil {
return return
} }
continue continue
} }
aof = (command[0] == 'a' || command[0] == 'A') && strings.HasPrefix(strings.ToLower(command), "aof ") aof = strings.HasPrefix(strings.ToLower(command), "aof ")
tryAgain: tryAgain:
if conn == nil { if conn == nil {
connDial() connDial()
@ -665,3 +670,14 @@ func plainToCompat(message string) []byte {
} }
return []byte(strings.Join(args, " ") + "\r\n") return []byte(strings.Join(args, " ") + "\r\n")
} }
func clearScreen() {
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", "cls")
} else {
cmd = exec.Command("clear")
}
cmd.Stdout = os.Stdout
cmd.Run()
}