gcmd.Scan supports read line that contains whitespace

This commit is contained in:
qinyuguang
2020-08-01 02:13:42 +08:00
parent 3e1a7953ec
commit ba1a9d9f8e

View File

@ -7,13 +7,21 @@
package gcmd
import "fmt"
import (
"bufio"
"fmt"
"os"
"github.com/gogf/gf/text/gstr"
)
// 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...)
fmt.Scanln(&s)
reader := bufio.NewReader(os.Stdin)
s, _ = reader.ReadString('\n')
s = gstr.Trim(s)
return s
}