Is there any way to control terminal input and output? For example, I press left arrow key and console print "left".
I'll try to use https://github.com/eiannone/keyboard but it isn't working. https://github.com/nsf/termbox-go and others similar is too complex.
bufio.NewReader(os.Stdin)
bufio.NewScanner(os.Stdin)
fmt.Scanln(&input)
require to hit enter
func main() {
e := make(chan bool)
go changeInput()
<-e
}
func changeInput() {
for {
inp := "" // ????
if inp == "Left arrow" {
fmt.Println("left")
}
}
}
Solutions that I've found are not working. I want to real time get data from user input.
You might want to read a bit about "raw" terminal mode, the chapters 2 and 3 of this article give you more details (in C, but applies to Go as well): https://viewsourcecode.org/snaptoken/kilo/index.html