tree: c857731f06477fb51aba5eabc8c6b518eece8449 [path history] [tgz]
  1. bsdinput.go
  2. common.go
  4. fallbackinput.go
  5. input.go
  6. input_darwin.go
  7. input_linux.go
  8. input_test.go
  9. input_windows.go
  10. line.go
  11. line_test.go
  12. output.go
  13. output_windows.go
  14. prefix_test.go
  15. race_test.go
  17. signal.go
  18. signal_legacy.go
  19. unixmode.go
  20. width.go
  21. width_test.go


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 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:

Ctrl-A, HomeMove cursor to beginning of line
Ctrl-E, EndMove cursor to end of line
Ctrl-B, LeftMove cursor one character left
Ctrl-F, RightMove cursor one character right
Ctrl-Left, Alt-BMove cursor to previous word
Ctrl-Right, Alt-FMove 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-CReset input (create new empty prompt)
Ctrl-LClear screen (line is unmodified)
Ctrl-TTranspose previous character with current character
Ctrl-H, BackSpaceDelete character before cursor
Ctrl-WDelete word leading up to cursor
Ctrl-KDelete from cursor to end of line
Ctrl-UDelete from start of line to cursor
Ctrl-P, UpPrevious match from history
Ctrl-N, DownNext match from history
Ctrl-RReverse Search history (Ctrl-S forward, Ctrl-G cancel)
Ctrl-YPaste from Yank buffer (Alt-Y to paste next yank instead)
TabNext completion
Shift-Tab(after Tab) Previous completion

Getting started

package main

import (


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.SetCompleter(func(line string) (c []string) {
		for _, n := range names {
			if strings.HasPrefix(n, strings.ToLower(line)) {
				c = append(c, n)

	if f, err := os.Open(history_fn); err == nil {

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

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

For documentation, see