• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H05-Mar-2019-

COPYINGH A D05-Mar-20191.1 KiB

README.mdH A D05-Mar-20192.7 KiB

bsdinput.goH A D05-Mar-2019516

common.goH A D05-Mar-20197.8 KiB

fallbackinput.goH A D05-Mar-20191.2 KiB

go.modH A D05-Mar-201977

go.sumH A D05-Mar-2019177

input.goH A D05-Mar-20197.8 KiB

input_darwin.goH A D05-Mar-2019608

input_linux.goH A D05-Mar-2019414

input_test.goH A D05-Mar-20191.2 KiB

input_windows.goH A D05-Mar-20198.9 KiB

line.goH A D05-Mar-201927.1 KiB

line_test.goH A D05-Mar-20193.2 KiB

output.goH A D05-Mar-20191.5 KiB

output_windows.goH A D05-Mar-20192.2 KiB

prefix_test.goH A D05-Mar-20191 KiB

race_test.goH A D05-Mar-2019658

unixmode.goH A D05-Mar-2019840

width.goH A D05-Mar-20191.6 KiB

width_test.goH A D05-Mar-20192.6 KiB

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, Alt-BackSpace | Delete word leading up to cursor
33Alt-D        | Delete word following cursor
34Ctrl-K       | Delete from cursor to end of line
35Ctrl-U       | Delete from start of line to cursor
36Ctrl-P, Up   | Previous match from history
37Ctrl-N, Down | Next match from history
38Ctrl-R       | Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
39Ctrl-Y       | Paste from Yank buffer (Alt-Y to paste next yank instead)
40Tab          | Next completion
41Shift-Tab    | (after Tab) Previous completion
42
43Getting started
44-----------------
45
46```go
47package main
48
49import (
50	"log"
51	"os"
52	"path/filepath"
53	"strings"
54
55	"github.com/peterh/liner"
56)
57
58var (
59	history_fn = filepath.Join(os.TempDir(), ".liner_example_history")
60	names      = []string{"john", "james", "mary", "nancy"}
61)
62
63func main() {
64	line := liner.NewLiner()
65	defer line.Close()
66
67	line.SetCtrlCAborts(true)
68
69	line.SetCompleter(func(line string) (c []string) {
70		for _, n := range names {
71			if strings.HasPrefix(n, strings.ToLower(line)) {
72				c = append(c, n)
73			}
74		}
75		return
76	})
77
78	if f, err := os.Open(history_fn); err == nil {
79		line.ReadHistory(f)
80		f.Close()
81	}
82
83	if name, err := line.Prompt("What is your name? "); err == nil {
84		log.Print("Got: ", name)
85		line.AppendHistory(name)
86	} else if err == liner.ErrPromptAborted {
87		log.Print("Aborted")
88	} else {
89		log.Print("Error reading line: ", err)
90	}
91
92	if f, err := os.Create(history_fn); err != nil {
93		log.Print("Error writing history file: ", err)
94	} else {
95		line.WriteHistory(f)
96		f.Close()
97	}
98}
99```
100
101For documentation, see http://godoc.org/github.com/peterh/liner
102