liner: github.com/sbinet/liner Index | Files

package liner

import "github.com/sbinet/liner"

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

Package Files

common.go input.go input_linux.go line.go output.go signal.go unixmode.go width.go

Constants

const HistoryLimit = 1000

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

const KillRingMax = 60

Max elements to save on the killring

Variables

var ErrNotTerminalOutput = errors.New("standard output is not a terminal")

ErrNotTerminalOutput is returned from Prompt or PasswordPrompt if the platform is normally supported, but stdout has been redirected

var ErrPromptAborted = errors.New("prompt aborted")

ErrPromptAborted is returned from Prompt or PasswordPrompt when the user presses Ctrl-C if SetCtrlCAborts(true) has been called on the State

func TerminalSupported Uses

func TerminalSupported() bool

TerminalSupported returns true if the current terminal supports line editing features, and false if liner will use the 'dumb' fallback for input.

type Completer Uses

type Completer func(line string) []string

Completer takes the currently edited line content at the left of the cursor and returns a list of completion candidates. If the line is "Hello, wo!!!" and the cursor is before the first '!', "Hello, wo" is passed to the completer which may return {"Hello, world", "Hello, Word"} to have "Hello, world!!!".

type ModeApplier Uses

type ModeApplier interface {
    ApplyMode() error
}

ModeApplier is the interface that wraps a representation of the terminal mode. ApplyMode sets the terminal to this mode.

func TerminalMode Uses

func TerminalMode() (ModeApplier, error)

TerminalMode returns the current terminal input mode as an InputModeSetter.

This function is provided for convenience, and should not be necessary for most users of liner.

type State Uses

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

State represents an open terminal

func NewLiner Uses

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().

Note if you are still using Go 1.0: NewLiner handles SIGWINCH, so it will leak a channel every time you call it. Therefore, it is recommened that you upgrade to a newer release of Go, or ensure that NewLiner is only called once.

func (*State) AppendHistory Uses

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 Uses

func (s *State) Close() error

Close returns the terminal to its previous mode

func (*State) PasswordPrompt Uses

func (s *State) PasswordPrompt(prompt string) (string, error)

PasswordPrompt displays p, and then waits for user input. The input typed by the user is not displayed in the terminal.

func (*State) Prompt Uses

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

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

func (*State) ReadHistory Uses

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 Uses

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) SetCtrlCAborts Uses

func (s *State) SetCtrlCAborts(aborts bool)

SetCtrlCAborts sets whether Prompt on a supported terminal will return an ErrPromptAborted when Ctrl-C is pressed. The default is false (will not return when Ctrl-C is pressed). Unsupported terminals typically raise SIGINT (and Prompt does not return) regardless of the value passed to SetCtrlCAborts.

func (*State) SetWordCompleter Uses

func (s *State) SetWordCompleter(f WordCompleter)

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

func (*State) WriteHistory Uses

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.

Unlike the rest of liner's API, WriteHistory is safe to call from another goroutine while Prompt is in progress. This exception is to facilitate the saving of the history buffer during an unexpected exit (for example, due to Ctrl-C being invoked)

type WordCompleter Uses

type WordCompleter func(line string, pos int) (head string, completions []string, tail string)

WordCompleter takes the currently edited line with the cursor position and returns the completion candidates for the partial word to be completed. If the line is "Hello, wo!!!" and the cursor is before the first '!', ("Hello, wo!!!", 9) is passed to the completer which may returns ("Hello, ", {"world", "Word"}, "!!!") to have "Hello, world!!!".

Package liner imports 16 packages (graph) and is imported by 14 packages. Updated 2016-07-23. Refresh now. Tools for package owners.