tree: cbf1ddaa2cf7f1183353cca15672b4799f56dbfe
  1. internal/
  2. .check-gofmt.sh
  3. .gitignore
  4. complete.go
  5. complete_helper.go
  6. history.go
  7. LICENSE
  8. Makefile
  9. operation.go
  10. readline.go
  11. README.md
  12. runebuf.go
  13. search.go
  14. terminal.go
  15. undo.go
  16. utils.go
  17. vim.go
vendor/github.com/ergochat/readline/README.md

readline

Godoc

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.

  • Relative to the upstream repository, it is actively maintained and has numerous bug fixes
    • See our changelog for details on fixes and improvements
    • See our migration guide for advice on how to migrate from upstream
  • Relative to x/term, it has more features (e.g. tab-completion)
  • In use by multiple projects: gopass, fq, and ircdog
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)
	}
}