tag | 15a38309e66dde7be211ea063bbb4eb5cd721d96 | |
---|---|---|
tagger | Cheney <me@chenye.org> | Fri Nov 20 15:26:43 2015 |
object | 09b448ca0ba1566ed99bf53ab0f0547ee748cdc9 |
* #12 Add support for key `<Delete>`/`<Home>`/`<End>` * Only enter raw mode as needed (calling `Readline()`), program will receive signal(e.g. Ctrl+C) if not interact with `readline`. * Bugs fixed for `PrefixCompleter` * Press `Ctrl+D` in empty line will cause `io.EOF` in error, Press `Ctrl+C` in anytime will cause `ErrInterrupt` instead of `io.EOF`, this will privodes a shell-like user experience. * Customable Interrupt/EOF prompt in `Config` * #17 Change atomic package to use 32bit function to let it runnable on arm 32bit devices * Provides a new password user experience(`readline.ReadPasswordEx()`).
commit | 09b448ca0ba1566ed99bf53ab0f0547ee748cdc9 | [log] [tgz] |
---|---|---|
author | Cheney <me@chenye.org> | Fri Nov 20 15:25:18 2015 |
committer | Cheney <me@chenye.org> | Fri Nov 20 15:25:18 2015 |
tree | aae132bcd433842cc6619f763902a7d96074dcf9 | |
parent | fb8cb231994e5a8a0368e2efc253b60f68193a4f [diff] |
changelog: fix syntax
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.
Also works fine in windows
You can read the source code in example/main.go.
go get gopkg.in/readline.v1
or
go get github.com/chzyer/readline
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 break } println(line) }
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 break } println(line) }
import ( "log" "gopkg.in/readline.v1" ) rl, err := readline.New("> ") if err != nil { panic(err) } defer rl.Close() log.SetOutput(l.Stderr()) // let "log" write to l.Stderr instead of os.Stderr go func() { for _ = range time.Tick(time.Second) { log.Println("hello") } }() for { line, err := rl.Readline() if err != nil { // io.EOF break } println(line) }
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 break } println(line) }
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 | 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 | Clean screen (TODO) |
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 |
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 |
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 |
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 | - |
Ctrl
+A
is not working in screen
because it used as a control command by defaultIf you test it otherwhere, whether it works fine or not, please let me know!
If you have any questions, please submit a github issue and any pull requests is welcomed :)