Readline is a pure go(golang) implementation for GNU-Readline kind library
Go to file
chzyer 6cbc078c57 let stdin cancelable (#72) 2016-09-01 18:13:06 +08:00
example Dynamic autocompletion (#60) 2016-07-26 21:39:09 +08:00
runes Fix #43 , remove sub-package for gopkg compatiblity 2016-04-05 09:55:46 +08:00
.gitignore update ignore 2015-10-04 22:31:32 +08:00
.travis.yml CI: fix travis 2015-11-21 11:38:21 +08:00
CHANGELOG.md update changelog 2016-07-26 21:51:17 +08:00
LICENSE Initial commit 2015-09-20 23:11:30 +08:00
README.md mylg added to README->Who is using Readline (#70) 2016-08-24 22:42:54 +08:00
ansi_windows.go [windows] fix ansi parse by remove channel 2016-07-24 00:39:44 +08:00
char.go Add ClearScreen operation on Ctrl+L (#56) 2016-05-16 17:59:35 +08:00
complete.go Fix: a backup plan when can't get size of terminal (#71) 2016-08-31 23:51:28 +08:00
complete_helper.go Dynamic autocompletion (#60) 2016-07-26 21:39:09 +08:00
complete_segment.go [completer] add SegmentAutoComplete 2016-04-12 14:04:56 +08:00
complete_segment_test.go [remote] fix test 2016-04-11 01:54:54 +08:00
debug.go refactor 2015-09-27 10:50:14 +08:00
doc.go add doc 2015-09-23 13:55:53 +08:00
history.go Fix deadlock on rewrite of opHistory when history limit is reached (#69) 2016-08-12 10:11:21 +08:00
operation.go Fix: a backup plan when can't get size of terminal (#71) 2016-08-31 23:51:28 +08:00
password.go refactory 2016-03-05 15:45:42 +08:00
rawreader_windows.go add comment 2015-10-09 11:13:07 +08:00
readline.go fix typo 2016-04-21 10:06:19 +08:00
remote.go [remote] fix remote 2016-04-11 01:46:08 +08:00
runebuf.go Fix: a backup plan when can't get size of terminal (#71) 2016-08-31 23:51:28 +08:00
runes.go Auto complete with space prefixed line (#46) 2016-04-08 10:01:57 +08:00
runes_test.go Fix #43 , remove sub-package for gopkg compatiblity 2016-04-05 09:55:46 +08:00
search.go Fix: a backup plan when can't get size of terminal (#71) 2016-08-31 23:51:28 +08:00
std.go let stdin cancelable (#72) 2016-09-01 18:13:06 +08:00
std_windows.go finish windows support 2015-09-29 23:28:12 +08:00
term.go Fix #62: move dependent package "terminal" to "term" (#65) 2016-07-22 00:31:42 +08:00
term_bsd.go Fix #62: move dependent package "terminal" to "term" (#65) 2016-07-22 00:31:42 +08:00
term_linux.go Fix #62: move dependent package "terminal" to "term" (#65) 2016-07-22 00:31:42 +08:00
term_windows.go fix windows compile error 2016-07-22 00:40:16 +08:00
terminal.go let stdin cancelable (#72) 2016-09-01 18:13:06 +08:00
utils.go Fix: a backup plan when can't get size of terminal (#71) 2016-08-31 23:51:28 +08:00
utils_test.go remove test for SplitByMultiLine 2016-03-31 00:19:18 +08:00
utils_unix.go [terminal] fix when only stderr is tty (1>/dev/null) 2016-06-21 17:53:53 +08:00
utils_windows.go Add ClearScreen operation on Ctrl+L (#56) 2016-05-16 17:59:35 +08:00
vim.go fix #36 vim mode: 'e' moves to the beginning of the next word (#64) 2016-07-26 21:40:22 +08:00
windows_api.go finish windows support 2015-09-29 23:28:12 +08:00

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
Shortcut Comment
Ctrl+A Beginning of line
Ctrl+B / Backward one character
Meta+B Backward one word
Ctrl+C Send io.EOF
Ctrl+D Delete one character
Meta+D Delete one word
Ctrl+E End of line
Ctrl+F / Forward one character
Meta+F Forward one word
Ctrl+G Cancel
Ctrl+H Delete previous character
Ctrl+I / Tab Command line completion
Ctrl+J Line feed
Ctrl+K Cut text to the end of line
Ctrl+L Clear screen
Ctrl+M Same as Enter key
Ctrl+N / Next line (in history)
Ctrl+P / Prev line (in history)
Ctrl+R Search backwards in history
Ctrl+S Search forwards in history
Ctrl+T Transpose characters
Meta+T Transpose words (TODO)
Ctrl+U Cut text to the beginning of line
Ctrl+W Cut previous word
Backspace Delete previous character
Meta+Backspace Cut previous word
Enter Line feed
  • Shortcut in Search Mode (Ctrl+S or Ctrl+r to enter this mode)
Shortcut Comment
Ctrl+S Search forwards in history
Ctrl+R Search backwards in history
Ctrl+C / Ctrl+G Exit Search Mode and revert the history
Backspace Delete previous character
Other Exit Search Mode
  • Shortcut in Complete Select Mode (double Tab to enter this mode)
Shortcut Comment
Ctrl+F Move Forward
Ctrl+B Move Backward
Ctrl+N Move to next line
Ctrl+P Move to previous line
Ctrl+A Move to the first candicate in current line
Ctrl+E Move to the last candicate in current line
Tab / Enter Use the word on cursor to complete
Ctrl+C / Ctrl+G Exit Complete Select Mode
Other Exit Complete Select Mode

Tested with

Environment $TERM
Mac OS X iTerm2 xterm
Mac OS X default Terminal.app xterm
Mac OS X iTerm2 Screen screen
Mac OS X iTerm2 Tmux screen
Ubuntu Server 14.04 LTS linux
Centos 7 linux
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]