Skip to content
malklera edited this page Sep 28, 2025 · 4 revisions

Documentation

Constants

Variables

func TerminalSupported() bool

func TerminalMode() (ModeApplier, error)

func NewLiner() *State

type ModeApplier

type ShouldRestart

type State

Constants

KillRingMax is the max number of elements to save on the killring.

const KillRingMax = 60

Variables

ErrCloseChannel is returned when a channel is closed unexpectedly

var ErrCloseChannel = errors.New("channel is closed")

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

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

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

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

ErrZeroColumns is returned if the number of colums becomes zero during an active call to Prompt

var ErrZeroColums = errors.New("number of colums is zero")

Functions

func TerminalSupported

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. Note that TerminalSupported does not check all factors that may cause liner to not fully support the terminal (such as stdin redirection)

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

Types

type ModeApplier

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

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 ShouldRestart

type ShouldRestart func(err error) bool

ShouldRestart is passed the error generated by readNext and returns true if the the read should be restarted or false if the error should be returned.

type State

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

State represents an open terminal

func (*State) Close

func (s *State) Close() error

Close returns the terminal to its previous mode

func (*State) PrefilledInput

func (s *State) PrefilledInput(text string, pos int) (string, error)

PrefilledInput displays an editable text field with cursor at given position. The cursor will be set to the end of the line if given position is negative or greater than length of text (in runes). Returns a line of user input, not including a trailing newline character. An io.EOF error is returned if the user signals end-of-file by pressing Ctrl-D.