I have a sample program to accept passwords on my terminal, and I'm using the terminal package for this. However, when I press any of the arrow keys by mistake while inputting my password I get some weird errors.
I wanted to separate my input password and then only use that for authorization. The following is what I tried.
My input string is
// 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))
Here it prints [Aabcd
in the end.
Is there anyway I can only capture/print the input characters without the [A here ?
Thanks