diff --git a/README.md b/README.md index 5345d17..06173dd 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,13 @@ Readline will support most of features which GNU Readline is supported, and prov You can read the source code in [example/main.go](https://github.com/chzyer/readline/blob/master/example/main.go). +# Todo + +* Auto Completeion +* Vim mode +* Transpose words +* More funny examples + # Usage * Simplest example @@ -107,7 +114,7 @@ Users can change that in terminal simulator(i.e. iTerm2) to `Alt`+`B` | `Meta`+`F` | Forward one word | Yes | | `Ctrl`+`G` | Cancel | Yes | | `Ctrl`+`H` | Delete previous character | Yes | -| `Ctrl`+`I` / `Tab` | Command line completion | NoYet | +| `Ctrl`+`I` / `Tab` | Command line completion | Not Yet | | `Ctrl`+`J` | Line feed | Yes | | `Ctrl`+`K` | Cut text to the end of line | Yes | | `Ctrl`+`L` | Clean screen | NoYet | @@ -117,8 +124,8 @@ Users can change that in terminal simulator(i.e. iTerm2) to `Alt`+`B` | `Ctrl`+`R` | Search backwards in history | Yes | | `Ctrl`+`S` | Search forwards in history | Yes | | `Ctrl`+`T` | Transpose characters | Yes | -| `Meta`+`T` | Transpose words | NoYet | -| `Ctrl`+`U` | Cut text to the beginning of line | NoYet | +| `Meta`+`T` | Transpose words | Not Yet | +| `Ctrl`+`U` | Cut text to the beginning of line | Not Yet | | `Ctrl`+`W` | Cut previous word | Yes | | `Backspace` | Delete previous character | Yes | | `Meta`+`Backspace` | Cut previous word | Yes | diff --git a/char.go b/char.go index b64ebd5..4d42e1f 100644 --- a/char.go +++ b/char.go @@ -9,6 +9,7 @@ const ( CharForward = 6 CharCannel = 7 CharCtrlH = 8 + CharTab = 9 CharCtrlJ = 10 CharKill = 11 CharEnter = 13 diff --git a/example/main.go b/example/main.go index bb966ba..bd380ef 100644 --- a/example/main.go +++ b/example/main.go @@ -18,7 +18,7 @@ bye: quit func main() { l, err := readline.NewEx(&readline.Config{ - Prompt: "home \033[31m»\033[0m ", + Prompt: "\033[31m»\033[0m ", HistoryFile: "/tmp/readline.tmp", }) if err != nil { diff --git a/operation.go b/operation.go index 2080402..27e013e 100644 --- a/operation.go +++ b/operation.go @@ -57,6 +57,10 @@ func (o *Operation) ioloop() { o.ExitSearchMode(true) o.buf.Refresh() } + case CharTab: + if o.cfg.AutoComplete == nil { + break + } case CharBckSearch: o.SearchMode(S_DIR_BCK) keepInSearchMode = true diff --git a/readline.go b/readline.go index e799b62..3bd5603 100644 --- a/readline.go +++ b/readline.go @@ -7,9 +7,14 @@ type Instance struct { o *Operation } +type AutoCompleter interface { + Do(line []rune, pos int) (newLine []rune, newPos int, ok bool) +} + type Config struct { - Prompt string - HistoryFile string + Prompt string + HistoryFile string + AutoComplete AutoCompleter } func NewEx(cfg *Config) (*Instance, error) {