[release] 1.3
1 file changed
tree: 743f05126e5efba1922b78a6e648349cdf415f74
  1. example/
  2. runes/
  3. .gitignore
  4. .travis.yml
  5. ansi_windows.go
  6. CHANGELOG.md
  7. char.go
  8. complete.go
  9. complete_helper.go
  10. complete_segment.go
  11. complete_segment_test.go
  12. debug.go
  13. doc.go
  14. history.go
  15. LICENSE
  16. operation.go
  17. password.go
  18. rawreader_windows.go
  19. readline.go
  20. README.md
  21. remote.go
  22. runebuf.go
  23. runes.go
  24. runes_test.go
  25. search.go
  26. std.go
  27. std_windows.go
  28. terminal.go
  29. utils.go
  30. utils_test.go
  31. utils_unix.go
  32. utils_windows.go
  33. vim.go
  34. windows_api.go
README.md

readline

Software License Build Status GoDoc Gitter OpenCollective OpenCollective

Readline is A Pure Go Implementation of a libreadline-style Library.
The goal is to be a powerful alternater for GNU-Readline.

WHY: Readline will support most of features which GNU Readline is supported, and provide a pure go environment and a MIT license.

It can also provides shell-like interactives by using flagly (demo: flagly-shell)

Demo

demo

Also works fine in windows

demo windows

Todo

  • Vi Mode is not completely finish
  • More funny examples
  • Support dumb/eterm-color terminal in emacs

Features

  • Support emacs/vi mode, almost all basic features that GNU-Readline is supported
  • zsh-style backward/forward history search
  • zsh-style completion
  • Readline auto refresh when others write to Stdout while editing (it needs specify the Stdout/Stderr provided by *readline.Instance to others).
  • Support colourful prompt in all platforms.

Usage

  • Import package
go get gopkg.in/readline.v1

or

go get github.com/chzyer/readline
  • Simplest example
import "gopkg.in/readline.v1"

rl, err := readline.New("> ")
if err != nil {
	panic(err)
}
defer rl.Close()

for {
	line, err := rl.Readline()
	if err != nil { // io.EOF, readline.ErrInterrupt
		break
	}
	println(line)
}
  • Example with durable history
rl, err := readline.NewEx(&readline.Config{
	Prompt: "> ",
	HistoryFile: "/tmp/readline.tmp",
})
if err != nil {
	panic(err)
}
defer rl.Close()

for {
	line, err := rl.Readline()
	if err != nil { // io.EOF, readline.ErrInterrupt
		break
	}
	println(line)
}
  • Example with auto completion
import (
	"gopkg.in/readline.v1"
)

var completer = readline.NewPrefixCompleter(
	readline.PcItem("say",
		readline.PcItem("hello"),
		readline.PcItem("bye"),
	),
	readline.PcItem("help"),
)

rl, err := readline.NewEx(&readline.Config{
	Prompt:       "> ",
	AutoComplete: completer,
})
if err != nil {
	panic(err)
}
defer rl.Close()

for {
	line, err := rl.Readline()
	if err != nil { // io.EOF, readline.ErrInterrupt
		break
	}
	println(line)
}

Shortcut

Meta+B means press Esc and n separately.
Users can change that in terminal simulator(i.e. iTerm2) to Alt+B
Notice: Meta+B is equals with Alt+B in windows.

  • Shortcut in normal mode
ShortcutComment
Ctrl+ABeginning of line
Ctrl+B / Backward one character
Meta+BBackward one word
Ctrl+CSend io.EOF
Ctrl+DDelete one character
Meta+DDelete one word
Ctrl+EEnd of line
Ctrl+F / Forward one character
Meta+FForward one word
Ctrl+GCancel
Ctrl+HDelete previous character
Ctrl+I / TabCommand line completion
Ctrl+JLine feed
Ctrl+KCut text to the end of line
Ctrl+LClean screen (TODO)
Ctrl+MSame as Enter key
Ctrl+N / Next line (in history)
Ctrl+P / Prev line (in history)
Ctrl+RSearch backwards in history
Ctrl+SSearch forwards in history
Ctrl+TTranspose characters
Meta+TTranspose words (TODO)
Ctrl+UCut text to the beginning of line
Ctrl+WCut previous word
BackspaceDelete previous character
Meta+BackspaceCut previous word
EnterLine feed
  • Shortcut in Search Mode (Ctrl+S or Ctrl+r to enter this mode)
ShortcutComment
Ctrl+SSearch forwards in history
Ctrl+RSearch backwards in history
Ctrl+C / Ctrl+GExit Search Mode and revert the history
BackspaceDelete previous character
OtherExit Search Mode
  • Shortcut in Complete Select Mode (double Tab to enter this mode)
ShortcutComment
Ctrl+FMove Forward
Ctrl+BMove Backward
Ctrl+NMove to next line
Ctrl+PMove to previous line
Ctrl+AMove to the first candicate in current line
Ctrl+EMove to the last candicate in current line
Tab / EnterUse the word on cursor to complete
Ctrl+C / Ctrl+GExit Complete Select Mode
OtherExit Complete Select Mode

Tested with

Environment$TERM
Mac OS X iTerm2xterm
Mac OS X default Terminal.appxterm
Mac OS X iTerm2 Screenscreen
Mac OS X iTerm2 Tmuxscreen
Ubuntu Server 14.04 LTSlinux
Centos 7linux
Windows 10-

Notice:

  • Ctrl+A is not working in screen because it used as a control command by default

If you test it otherwhere, whether it works fine or not, please let me know!

Who is using Readline

Feedback

If you have any questions, please submit a github issue and any pull requests is welcomed :)

Backers

Love Readline? Help me keep it alive by donating funds to cover project expenses!
[Become a backer]

Sponsors

Become a sponsor and get your logo here on our Github page. [Become a sponsor]