【发布时间】:2016-08-26 23:09:40
【问题描述】:
我有一个示例程序可以在我的终端上接受密码,为此我正在使用终端包。但是,当我在输入密码时误按任何箭头键时,会出现一些奇怪的错误。
我想将我的输入密码分开,然后仅将其用于授权。以下是我尝试过的。
我的输入字符串是
// Accept password using terminal.ReadPassword() which returns []byte
// password entered is "\x1b[Aabcd"
// where \x1b[A is the up arrow key and abcd is my input entry.
for _, c := range bytes.Runes(password) {
if !unicode.IsPrint(c) {
fmt.Printf("\nINVALID PWD ")
} else {
d = append(d, c)
}
}
fmt.Println("\n\n", fmt.Sprintf("%c", d))
这里最后打印[Aabcd。
无论如何我只能在没有 [A here 的情况下捕获/打印输入字符吗?
谢谢
【问题讨论】:
标签: go