Documentation ¶
Overview ¶
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Putting a terminal into raw mode is the most common requirement:
oldState, err := terminal.MakeRaw(0) if err != nil { panic(err) } defer terminal.Restore(0, oldState)
Index ¶
- Constants
- func GetSize(fd int) (width, height int, err error)
- func IsTerminal(fd int) bool
- func ReadPassword(fd int) ([]byte, error)
- func Restore(fd int, state *State) error
- type EscapeCodes
- type State
- type Terminal
- func (t *Terminal) GetHistory() (h []string)
- func (t *Terminal) ReadLine() (line string, err error)
- func (t *Terminal) ReadPassword(prompt string) (line string, err error)
- func (t *Terminal) ReleaseFromStdInOut()
- func (t *Terminal) SetHistory(h []string)
- func (t *Terminal) SetPrompt(prompt string)
- func (t *Terminal) SetSize(width, height int)
- func (t *Terminal) Write(buf []byte) (n int, err error)
Constants ¶
const ( KeyCtrlC = 3 KeyCtrlD = 4 KeyEnter = '\r' KeyEscape = 27 KeyBackspace = 127 KeyUnknown = 256 + iota KeyLeft KeyUp KeyRight KeyDown KeyAltLeft KeyAltRight )
Variables ¶
This section is empty.
Functions ¶
func IsTerminal ¶
IsTerminal returns true if the given file descriptor is a terminal.
func ReadPassword ¶
ReadPassword reads a line of input from a terminal without local echo. This is commonly used for inputting passwords and other sensitive data. The slice returned does not include the \n.
Types ¶
type EscapeCodes ¶
type EscapeCodes struct {
// Foreground colors
Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte
// Reset all attributes
Reset []byte
}
EscapeCodes contains escape sequences that can be written to the terminal in order to achieve different styles of text.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State contains the state of a terminal.
type Terminal ¶
type Terminal struct { // AutoCompleteCallback, if non-null, is called for each keypress // with the full input line and the current position of the cursor. // If it returns a nil newLine, the key press is processed normally. // Otherwise it returns a replacement line and the new cursor position. AutoCompleteCallback func(line []byte, pos, key int) (newLine []byte, newPos int) // Escape contains a pointer to the escape codes for this terminal. // It's always a valid pointer, although the escape codes themselves // may be empty if the terminal doesn't support them. Escape *EscapeCodes // contains filtered or unexported fields }
Terminal contains the state for running a VT100 terminal that is capable of reading lines of input.
func NewTerminal ¶
func NewTerminal(c io.ReadWriter, prompt string) *Terminal
NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is a local terminal, that terminal must first have been put into raw mode. prompt is a string that is written at the start.md of each input line (i.e. "> ").
func NewWithStdInOut ¶
func (*Terminal) GetHistory ¶
func (*Terminal) ReadPassword ¶
ReadPassword temporarily changes the prompt and reads a password, without echo, from the terminal.
func (*Terminal) ReleaseFromStdInOut ¶
func (t *Terminal) ReleaseFromStdInOut()