2015-09-20 18:11:30 +03:00
|
|
|
# readline
|
2015-09-20 18:16:46 +03:00
|
|
|
|
2015-09-23 08:09:26 +03:00
|
|
|
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)
|
2015-09-23 08:12:20 +03:00
|
|
|
[![Build Status](https://travis-ci.org/chzyer/readline.svg?branch=master)](https://travis-ci.org/chzyer/readline)
|
2015-09-23 08:09:26 +03:00
|
|
|
[![GoDoc](https://godoc.org/github.com/chzyer/readline?status.svg)](https://godoc.org/github.com/chzyer/readline)
|
|
|
|
|
2015-09-23 08:43:48 +03:00
|
|
|
Readline is a pure go implementation for GNU-Readline kind library.
|
|
|
|
|
|
|
|
**WHY:**
|
|
|
|
Readline will support most of features which GNU Readline is supported, and provide a pure go environment and a MIT license.
|
2015-09-23 08:03:18 +03:00
|
|
|
|
2015-09-23 08:09:26 +03:00
|
|
|
# Demo
|
|
|
|
|
|
|
|
![demo](https://raw.githubusercontent.com/chzyer/readline/master/example/demo.gif)
|
|
|
|
|
2015-09-23 08:43:48 +03:00
|
|
|
You can read the source code in [example/main.go](https://github.com/chzyer/readline/blob/master/example/main.go).
|
2015-09-23 08:26:42 +03:00
|
|
|
|
2015-09-25 07:59:36 +03:00
|
|
|
# Todo
|
|
|
|
|
|
|
|
* Auto Completeion
|
|
|
|
* Vim mode
|
|
|
|
* Transpose words
|
|
|
|
* More funny examples
|
|
|
|
|
2015-09-23 08:43:48 +03:00
|
|
|
# Usage
|
2015-09-23 08:35:48 +03:00
|
|
|
|
2015-09-23 08:32:43 +03:00
|
|
|
* Simplest example
|
2015-09-23 08:35:48 +03:00
|
|
|
|
2015-09-23 08:26:42 +03:00
|
|
|
```go
|
|
|
|
import "github.com/chzyer/readline"
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2015-09-23 08:32:43 +03:00
|
|
|
* Example with durable history
|
2015-09-23 08:35:48 +03:00
|
|
|
|
2015-09-23 08:32:43 +03:00
|
|
|
```go
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
* Example with auto refresh
|
2015-09-23 08:35:48 +03:00
|
|
|
|
2015-09-23 08:32:43 +03:00
|
|
|
```go
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"github.com/chzyer/readline"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2015-09-23 08:09:26 +03:00
|
|
|
# Shortcut
|
2015-09-23 08:03:18 +03:00
|
|
|
|
2015-09-23 08:19:53 +03:00
|
|
|
`Meta`+`B` means press `Esc` and `n` separately.
|
|
|
|
Users can change that in terminal simulator(i.e. iTerm2) to `Alt`+`B`
|
2015-09-23 08:03:18 +03:00
|
|
|
|
|
|
|
| Shortcut | Comment | Support |
|
2015-09-23 08:05:11 +03:00
|
|
|
|--------------------|-----------------------------------|---------|
|
2015-09-23 08:03:18 +03:00
|
|
|
| `Ctrl`+`A` | Beginning of line | Yes |
|
|
|
|
| `Ctrl`+`B` / `←` | Backward one character | Yes |
|
|
|
|
| `Meta`+`B` | Backward one word | Yes |
|
|
|
|
| `Ctrl`+`C` | Send io.EOF | Yes |
|
|
|
|
| `Ctrl`+`D` | Delete one character | Yes |
|
|
|
|
| `Meta`+`D` | Delete one word | Yes |
|
|
|
|
| `Ctrl`+`E` | End of line | Yes |
|
|
|
|
| `Ctrl`+`F` / `→` | Forward one character | Yes |
|
|
|
|
| `Meta`+`F` | Forward one word | Yes |
|
|
|
|
| `Ctrl`+`G` | Cancel | Yes |
|
|
|
|
| `Ctrl`+`H` | Delete previous character | Yes |
|
2015-09-25 07:59:36 +03:00
|
|
|
| `Ctrl`+`I` / `Tab` | Command line completion | Not Yet |
|
2015-09-23 08:03:18 +03:00
|
|
|
| `Ctrl`+`J` | Line feed | Yes |
|
|
|
|
| `Ctrl`+`K` | Cut text to the end of line | Yes |
|
2015-09-23 17:18:14 +03:00
|
|
|
| `Ctrl`+`L` | Clean screen | NoYet |
|
2015-09-23 08:03:18 +03:00
|
|
|
| `Ctrl`+`M` | Same as Enter key | Yes |
|
|
|
|
| `Ctrl`+`N` / `↓` | Next line (in history) | Yes |
|
|
|
|
| `Ctrl`+`P` / `↑` | Prev line (in history) | Yes |
|
|
|
|
| `Ctrl`+`R` | Search backwards in history | Yes |
|
|
|
|
| `Ctrl`+`S` | Search forwards in history | Yes |
|
|
|
|
| `Ctrl`+`T` | Transpose characters | Yes |
|
2015-09-25 07:59:36 +03:00
|
|
|
| `Meta`+`T` | Transpose words | Not Yet |
|
|
|
|
| `Ctrl`+`U` | Cut text to the beginning of line | Not Yet |
|
2015-09-23 08:03:18 +03:00
|
|
|
| `Ctrl`+`W` | Cut previous word | Yes |
|
|
|
|
| `Backspace` | Delete previous character | Yes |
|
|
|
|
| `Meta`+`Backspace` | Cut previous word | Yes |
|
|
|
|
| `Enter` | Line feed | Yes |
|
|
|
|
|
2015-09-23 08:43:48 +03:00
|
|
|
|
|
|
|
# Feedback
|
|
|
|
|
|
|
|
If you have any question, please submit an GitHub Issues and any pull request is welcomed :)
|