From e4161a83adadaf085caf180430b7888d9d0387a9 Mon Sep 17 00:00:00 2001 From: 兔子 Date: Wed, 27 Feb 2019 14:40:45 +0800 Subject: [PATCH] add more cli support --- starainrt.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/starainrt.go b/starainrt.go index ebf7750..582034b 100644 --- a/starainrt.go +++ b/starainrt.go @@ -21,8 +21,10 @@ import ( "os" "os/exec" "regexp" + "runtime" "strconv" "strings" + "syscall" "time" ) @@ -985,3 +987,45 @@ func (this suncli) WriteCmd(cmdstr string) { this.infile.Write([]byte(cmdstr + "\n")) return } + +func (this suncli) ExitCode() int { + return this.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() +} + +func MsgBox(text, defaults string) string { + var input string + input = defaults + fmt.Print(text) + fmt.Scanln(&input) + return strings.TrimSpace(input) +} + +func MessageBox(text, defaults string) string { + fmt.Print(text) + inputReader := bufio.NewReader(os.Stdin) + str, _ := inputReader.ReadString('\n') + if runtime.GOOS == "windows" { + str = str[0 : len(str)-2] + } else { + str = str[0 : len(str)-1] + } + if str == "" { + str = defaults + } + return strings.TrimSpace(str) +} + +func YesNo(text string, defaults bool) bool { + res := strings.ToUpper(MsgBox(text, "")) + if res == "" { + return defaults + } + res = res[0:1] + if res == "Y" { + return true + } else if res == "N" { + return false + } else { + return defaults + } +}