This is a pure Go implementation of functionality comparable to GNU Readline, i.e. line editing and command history for simple TUI programs.
It is a fork of chzyer/readline.
package main import ( "fmt" "log" "github.com/ergochat/readline" ) func main() { // see readline.NewFromConfig for advanced options: rl, err := readline.New("> ") if err != nil { log.Fatal(err) } defer rl.Close() log.SetOutput(rl.Stderr()) // redraw the prompt correctly after log output for { line, err := rl.ReadLine() // `err` is either nil, io.EOF, readline.ErrInterrupt, or an unexpected // condition in stdin: if err != nil { return } // `line` is returned without the terminating \n or CRLF: fmt.Fprintf(rl, "you wrote: %s\n", line) } }