add more cli support

master
兔子 6 years ago
parent dbdb0de0f3
commit e4161a83ad

@ -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
}
}

Loading…
Cancel
Save