I want to do autocomplete my commands when press "TAB" key "\t" and execute command when press "ENTER" key "\r?\n". This code for example:
package main
import (
"bufio"
"fmt"
)
func main() {
reader := bufio.NewReader(os.Stdin)
command, err := reader.ReadString('\n')
if err != nil {
fmt.Printf("%s\n", err)
} else {
fmt.Printf("%s\n", command)
}
}
If you want bash-like functionality, then it's a lot more complicated than just using a bufio reader.
Check https://github.com/chzyer/readline
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With