gcmd.Scanf supports read line that contains whitespace

This commit is contained in:
qinyuguang
2020-08-03 21:00:02 +08:00
parent ba1a9d9f8e
commit cf88f28519

View File

@ -17,18 +17,20 @@ import (
// Scan prints <info> to stdout, reads and returns user input, which stops by '\n'.
func Scan(info ...interface{}) string {
var s string
fmt.Print(info...)
return readline()
}
// Scanf prints <info> to stdout with <format>, reads and returns user input, which stops by '\n'.
func Scanf(format string, info ...interface{}) string {
fmt.Printf(format, info...)
return readline()
}
func readline() string {
var s string
reader := bufio.NewReader(os.Stdin)
s, _ = reader.ReadString('\n')
s = gstr.Trim(s)
return s
}
// Scanf prints <info> to stdout with <format>, reads and returns user input, which stops by '\n'.
func Scanf(format string, info ...interface{}) string {
var s string
fmt.Printf(format, info...)
fmt.Scanln(&s)
return s
}