README.md
1Liner
2=====
3
4Liner is a command line editor with history. It was inspired by linenoise;
5everything Unix-like is a VT100 (or is trying very hard to be). If your
6terminal is not pretending to be a VT100, change it. Liner also support
7Windows.
8
9Liner is released under the X11 license (which is similar to the new BSD
10license).
11
12Line Editing
13------------
14
15The following line editing commands are supported on platforms and terminals
16that Liner supports:
17
18Keystroke | Action
19--------- | ------
20Ctrl-A, Home | Move cursor to beginning of line
21Ctrl-E, End | Move cursor to end of line
22Ctrl-B, Left | Move cursor one character left
23Ctrl-F, Right| Move cursor one character right
24Ctrl-Left, Alt-B | Move cursor to previous word
25Ctrl-Right, Alt-F | Move cursor to next word
26Ctrl-D, Del | (if line is *not* empty) Delete character under cursor
27Ctrl-D | (if line *is* empty) End of File - usually quits application
28Ctrl-C | Reset input (create new empty prompt)
29Ctrl-L | Clear screen (line is unmodified)
30Ctrl-T | Transpose previous character with current character
31Ctrl-H, BackSpace | Delete character before cursor
32Ctrl-W | Delete word leading up to cursor
33Ctrl-K | Delete from cursor to end of line
34Ctrl-U | Delete from start of line to cursor
35Ctrl-P, Up | Previous match from history
36Ctrl-N, Down | Next match from history
37Ctrl-R | Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
38Ctrl-Y | Paste from Yank buffer (Alt-Y to paste next yank instead)
39Tab | Next completion
40Shift-Tab | (after Tab) Previous completion
41
42Getting started
43-----------------
44
45```go
46package main
47
48import (
49 "log"
50 "os"
51 "path/filepath"
52 "strings"
53
54 "github.com/peterh/liner"
55)
56
57var (
58 history_fn = filepath.Join(os.TempDir(), ".liner_example_history")
59 names = []string{"john", "james", "mary", "nancy"}
60)
61
62func main() {
63 line := liner.NewLiner()
64 defer line.Close()
65
66 line.SetCtrlCAborts(true)
67
68 line.SetCompleter(func(line string) (c []string) {
69 for _, n := range names {
70 if strings.HasPrefix(n, strings.ToLower(line)) {
71 c = append(c, n)
72 }
73 }
74 return
75 })
76
77 if f, err := os.Open(history_fn); err == nil {
78 line.ReadHistory(f)
79 f.Close()
80 }
81
82 if name, err := line.Prompt("What is your name? "); err == nil {
83 log.Print("Got: ", name)
84 line.AppendHistory(name)
85 } else if err == liner.ErrPromptAborted {
86 log.Print("Aborted")
87 } else {
88 log.Print("Error reading line: ", err)
89 }
90
91 if f, err := os.Create(history_fn); err != nil {
92 log.Print("Error writing history file: ", err)
93 } else {
94 line.WriteHistory(f)
95 f.Close()
96 }
97}
98```
99
100For documentation, see http://godoc.org/github.com/peterh/liner
101