I have the following program that reads user input from stdin:
var input string = ""
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
var b []byte = make([]byte, 1)
for {
input += string(b)
}
I want to place some kind of condition inside the for loop so that i can "break" when the user presses "enter" (for example) or remove one char from a string when the user presses (backspace). However, i can't figure out what the byte array or string representation of those two keys are. How do i go about figuring this out ? enter just prints a \w and backspace prins an undefined character.
Your use case is explained in this blog post. Just cross posting the necessary solution from the referenced blog:-
Sample Output
If you don't mind hitting the Enter button then the above code looks like below:-