liner

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2012 License: MIT Imports: 13 Imported by: 0

README

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 released under the X11 license (which is similar to the new BSD license).

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

Documentation

Overview

Package liner implements a simple command line editor, inspired by linenoise (https://github.com/antirez/linenoise/). This package supports WIN32 in addition to the xterm codes supported by everything else.

Index

Constants

View Source
const HistoryLimit = 100

HistoryLimit is the maximum number of entries saved in the scrollback history.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completer

type Completer func(line string) []string

Completer takes the currently edited line and returns a list of completion candidates.

type State

type State struct {
	// contains filtered or unexported fields
}

func NewLiner

func NewLiner() *State

NewLiner initializes a new *State, and sets the terminal into raw mode. To restore the terminal to its previous state, call State.Close(). NewLiner handles SIGWINCH, so it will leak a channel every time you call it. Therefore, it is recommened that NewLiner only be called once.

func (*State) AppendHistory

func (s *State) AppendHistory(item string)

AppendHistory appends an entry to the scrollback history. AppendHistory should be called iff Prompt returns a valid command.

func (*State) Close

func (s *State) Close() error

Close returns the terminal to its previous mode

func (*State) Prompt

func (s *State) Prompt(p string) (string, error)

Prompt displays p, and then waits for user input. Prompt allows line editing if the terminal supports it.

func (*State) ReadHistory

func (s *State) ReadHistory(r io.Reader) (num int, err error)

ReadHistory reads scrollback history from r. Returns the number of lines read, and any read error (except io.EOF).

func (*State) SetCompleter

func (s *State) SetCompleter(f Completer)

SetCompleter sets the completion function that Liner will call to fetch completion candidates when the user presses tab.

func (*State) WriteHistory

func (s *State) WriteHistory(w io.Writer) (num int, err error)

WriteHistory writes scrollback history to w. Returns the number of lines successfully written, and any write error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL