delve/vendor/github.com/peterh/liner
Derek Parker dee4437bd0
pkg/terminal: support ctrlz for shell job control (#2806)
* pkg/terminal: support ctrlz for shell job control

This required forking peterh/liner under the go-delve org and using that
instead since upstream is not open to supporting this feature.

Fixes #2157

* Update liner

* Update liner but correctly this time

* upgrade golang.org/x/tools to 0.1.9
2022-02-10 09:50:55 -08:00
..
bsdinput.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
common.go pkg/terminal: support ctrlz for shell job control (#2806) 2022-02-10 09:50:55 -08:00
COPYING all: Vendor with Godeps & GO15EXPERIMENT 2015-09-30 18:25:02 -07:00
fallbackinput.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
go.mod pkg/terminal: support ctrlz for shell job control (#2806) 2022-02-10 09:50:55 -08:00
go.sum go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
input_darwin.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
input_linux.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
input_solaris.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
input_windows.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
input.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
line.go pkg/terminal: support ctrlz for shell job control (#2806) 2022-02-10 09:50:55 -08:00
output_solaris.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
output_unix.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
output_windows.go vendor: update liner dependency (#2700) 2021-09-22 21:15:02 -07:00
output.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
README.md go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
signal_unix.go pkg/terminal: support ctrlz for shell job control (#2806) 2022-02-10 09:50:55 -08:00
signal_windows.go pkg/terminal: support ctrlz for shell job control (#2806) 2022-02-10 09:50:55 -08:00
unixmode_solaris.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
unixmode.go go.mod: bump liner version (#2874) 2022-01-18 09:02:30 -08:00
width.go vendor: update liner dependency (#2700) 2021-09-22 21:15:02 -07:00

Liner

Liner is a command line editor with history. It was inspired by linenoise; everything Unix-like is a VT100 (or is trying very hard to be). If your terminal is not pretending to be a VT100, change it. Liner also support Windows.

Liner is intended for use by cross-platform applications. Therefore, the decision was made to write it in pure Go, avoiding cgo, for ease of cross compilation. Furthermore, features only supported on some platforms have been intentionally omitted. For example, Ctrl-Z is "suspend" on Unix, but "EOF" on Windows. In the interest of making an application behave the same way on every supported platform, Ctrl-Z is ignored by Liner.

Liner is released under the X11 license (which is similar to the new BSD license).

Line Editing

The following line editing commands are supported on platforms and terminals that Liner supports:

Keystroke Action
Ctrl-A, Home Move cursor to beginning of line
Ctrl-E, End Move cursor to end of line
Ctrl-B, Left Move cursor one character left
Ctrl-F, Right Move cursor one character right
Ctrl-Left, Alt-B Move cursor to previous word
Ctrl-Right, Alt-F Move cursor to next word
Ctrl-D, Del (if line is not empty) Delete character under cursor
Ctrl-D (if line is empty) End of File - usually quits application
Ctrl-C Reset input (create new empty prompt)
Ctrl-L Clear screen (line is unmodified)
Ctrl-T Transpose previous character with current character
Ctrl-H, BackSpace Delete character before cursor
Ctrl-W, Alt-BackSpace Delete word leading up to cursor
Alt-D Delete word following cursor
Ctrl-K Delete from cursor to end of line
Ctrl-U Delete from start of line to cursor
Ctrl-P, Up Previous match from history
Ctrl-N, Down Next match from history
Ctrl-R Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
Ctrl-Y Paste from Yank buffer (Alt-Y to paste next yank instead)
Tab Next completion
Shift-Tab (after Tab) Previous completion

Note that "Previous" and "Next match from history" will retain the part of the line that the user has already typed, similar to zsh's "up-line-or-beginning-search" (which is the default on some systems) or bash's "history-search-backward" (which is my preferred behaviour, but does not appear to be the default Up keybinding on any system).

Getting started

package main

import (
	"log"
	"os"
	"path/filepath"
	"strings"

	"github.com/peterh/liner"
)

var (
	history_fn = filepath.Join(os.TempDir(), ".liner_example_history")
	names      = []string{"john", "james", "mary", "nancy"}
)

func main() {
	line := liner.NewLiner()
	defer line.Close()

	line.SetCtrlCAborts(true)

	line.SetCompleter(func(line string) (c []string) {
		for _, n := range names {
			if strings.HasPrefix(n, strings.ToLower(line)) {
				c = append(c, n)
			}
		}
		return
	})

	if f, err := os.Open(history_fn); err == nil {
		line.ReadHistory(f)
		f.Close()
	}

	if name, err := line.Prompt("What is your name? "); err == nil {
		log.Print("Got: ", name)
		line.AppendHistory(name)
	} else if err == liner.ErrPromptAborted {
		log.Print("Aborted")
	} else {
		log.Print("Error reading line: ", err)
	}

	if f, err := os.Create(history_fn); err != nil {
		log.Print("Error writing history file: ", err)
	} else {
		line.WriteHistory(f)
		f.Close()
	}
}

For documentation, see http://godoc.org/github.com/peterh/liner