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