I am creating a Go application for use in a terminal. The following code asks the user to enter text into the terminal.
package main import ( "bufio" "fmt" "os" ) func main() { for { fmt.Println("Please input something and use arrows to move along the text left and right") in := bufio.NewReader(os.Stdin) _, err := in.ReadString('\n') if err != nil { fmt.Println(err) } } }
The problem is that the user cannot use the left and right arrows to follow the text just entered to change it. When he presses the arrows, the console prints the signs ^[[D^[[C^[[A^[[B
Exit:
Please input something and use arrows to move along the text left and right hello^[[D^[[C^[[A^[[B
How to make arrow keys more user-friendly and allow a person to navigate the text just entered using the left and right arrows?
I think I should pay attention to libraries such as termbox-go or gocui , but I donβt know how to use them for this purpose.
terminal go
Maxim Yefremov
source share