term

Imports

Imports #

"fmt"
"runtime"
"os"
"golang.org/x/sys/windows"
"bytes"
"io"
"runtime"
"strconv"
"sync"
"unicode/utf8"
"fmt"
"runtime"
"golang.org/x/sys/plan9"
"golang.org/x/sys/unix"
"golang.org/x/sys/unix"
"golang.org/x/sys/unix"

Constants & Variables

ErrPasteIndicator var #

ErrPasteIndicator may be returned from ReadLine as the error, in addition to valid line data. It indicates that bracketed paste mode is enabled and that the returned line consists only of pasted data. Programs may wish to interpret pasted data more literally than typed data.

var ErrPasteIndicator = pasteIndicatorError{...}

crlf var #

var crlf = []byte{...}

ioctlReadTermios const #

const ioctlReadTermios = unix.TIOCGETA

ioctlReadTermios const #

const ioctlReadTermios = unix.TCGETS

ioctlWriteTermios const #

const ioctlWriteTermios = unix.TCSETS

ioctlWriteTermios const #

const ioctlWriteTermios = unix.TIOCSETA

keyAltLeft const #

const keyAltLeft

keyAltRight const #

const keyAltRight

keyBackspace const #

const keyBackspace = 127

keyClearScreen const #

const keyClearScreen

keyCtrlC const #

const keyCtrlC = 3

keyCtrlD const #

const keyCtrlD = 4

keyCtrlU const #

const keyCtrlU = 21

keyDeleteLine const #

const keyDeleteLine

keyDeleteWord const #

const keyDeleteWord

keyDown const #

const keyDown

keyEnd const #

const keyEnd

keyEnter const #

const keyEnter = '\r'

keyEscape const #

const keyEscape = 27

keyHome const #

const keyHome

keyLeft const #

const keyLeft

keyPasteEnd const #

const keyPasteEnd

keyPasteStart const #

const keyPasteStart

keyRight const #

const keyRight

keyUnknown const #

const keyUnknown = *ast.BinaryExpr

keyUp const #

const keyUp

maxLineLength const #

const maxLineLength = 4096

pasteEnd var #

var pasteEnd = []byte{...}

pasteStart var #

var pasteStart = []byte{...}

space var #

var space = []rune{...}

vt100EscapeCodes var #

var vt100EscapeCodes = EscapeCodes{...}

Type Aliases

passwordReader type #

passwordReader is an io.Reader that reads from a specific file descriptor.

type passwordReader int

Structs

EscapeCodes struct #

EscapeCodes contains escape sequences that can be written to the terminal in order to achieve different styles of text.

type EscapeCodes struct {
Black []byte
Red []byte
Green []byte
Yellow []byte
Blue []byte
Magenta []byte
Cyan []byte
White []byte
Reset []byte
}

State struct #

State contains the state of a terminal.

type State struct {
state
}

Terminal struct #

Terminal contains the state for running a VT100 terminal that is capable of reading lines of input.

type Terminal struct {
AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool)
Escape *EscapeCodes
lock sync.Mutex
c io.ReadWriter
prompt []rune
line []rune
pos int
echo bool
pasteActive bool
cursorX int
cursorY int
maxLine int
termWidth int
termHeight int
outBuf []byte
remainder []byte
inBuf [256]byte
history stRingBuffer
historyIndex int
historyPending string
}

pasteIndicatorError struct #

type pasteIndicatorError struct {

}

stRingBuffer struct #

stRingBuffer is a ring buffer of strings.

type stRingBuffer struct {
entries []string
max int
head int
size int
}

state struct #

type state struct {

}

state struct #

type state struct {
mode uint32
}

state struct #

type state struct {

}

state struct #

type state struct {
termios unix.Termios
}

Functions

Add method #

func (s *stRingBuffer) Add(a string)

Error method #

func (pasteIndicatorError) Error() string

GetSize function #

GetSize returns the visible dimensions of the given terminal. These dimensions don't include any scrollback buffer height.

func GetSize(fd int) (width int, height int, err error)

GetState function #

GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.

func GetState(fd int) (*State, error)

IsTerminal function #

IsTerminal returns whether the given file descriptor is a terminal.

func IsTerminal(fd int) bool

MakeRaw function #

MakeRaw puts the terminal connected to the given file descriptor into raw mode and returns the previous state of the terminal so that it can be restored.

func MakeRaw(fd int) (*State, error)

NewTerminal function #

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 of each input line (i.e. "> ").

func NewTerminal(c io.ReadWriter, prompt string) *Terminal

NthPreviousEntry method #

NthPreviousEntry returns the value passed to the nth previous call to Add. If n is zero then the immediately prior value is returned, if one, then the next most recent, and so on. If such an element doesn't exist then ok is false.

func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool)

Read method #

func (r passwordReader) Read(buf []byte) (int, error)

ReadLine method #

ReadLine returns a line of input from the terminal.

func (t *Terminal) ReadLine() (line string, err error)

ReadPassword function #

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.

func ReadPassword(fd int) ([]byte, error)

ReadPassword method #

ReadPassword temporarily changes the prompt and reads a password, without echo, from the terminal.

func (t *Terminal) ReadPassword(prompt string) (line string, err error)

Restore function #

Restore restores the terminal connected to the given file descriptor to a previous state.

func Restore(fd int, oldState *State) error

SetBracketedPasteMode method #

SetBracketedPasteMode requests that the terminal bracket paste operations with markers. Not all terminals support this but, if it is supported, then enabling this mode will stop any autocomplete callback from running due to pastes. Additionally, any lines that are completely pasted will be returned from ReadLine with the error set to ErrPasteIndicator.

func (t *Terminal) SetBracketedPasteMode(on bool)

SetPrompt method #

SetPrompt sets the prompt to be used when reading subsequent lines.

func (t *Terminal) SetPrompt(prompt string)

SetSize method #

func (t *Terminal) SetSize(width int, height int) error

Write method #

func (t *Terminal) Write(buf []byte) (n int, err error)

addKeyToLine method #

addKeyToLine inserts the given key at the current position in the current line.

func (t *Terminal) addKeyToLine(key rune)

advanceCursor method #

func (t *Terminal) advanceCursor(places int)

bytesToKey function #

bytesToKey tries to parse a key sequence from b. If successful, it returns the key and the remainder of the input. Otherwise it returns utf8.RuneError.

func bytesToKey(b []byte, pasteActive bool) (rune, []byte)

clearAndRepaintLinePlusNPrevious method #

func (t *Terminal) clearAndRepaintLinePlusNPrevious(numPrevLines int)

clearLineToRight method #

func (t *Terminal) clearLineToRight()

countToLeftWord method #

countToLeftWord returns then number of characters from the cursor to the start of the previous word.

func (t *Terminal) countToLeftWord() int

countToRightWord method #

countToRightWord returns then number of characters from the cursor to the start of the next word.

func (t *Terminal) countToRightWord() int

eraseNPreviousChars method #

func (t *Terminal) eraseNPreviousChars(n int)

getSize function #

func getSize(fd int) (width int, height int, err error)

getSize function #

func getSize(fd int) (width int, height int, err error)

getSize function #

func getSize(fd int) (width int, height int, err error)

getSize function #

func getSize(fd int) (width int, height int, err error)

getState function #

func getState(fd int) (*State, error)

getState function #

func getState(fd int) (*State, error)

getState function #

func getState(fd int) (*State, error)

getState function #

func getState(fd int) (*State, error)

handleKey method #

handleKey processes the given key and, optionally, returns a line of text that the user has entered.

func (t *Terminal) handleKey(key rune) (line string, ok bool)

isPrintable function #

func isPrintable(key rune) bool

isTerminal function #

func isTerminal(fd int) bool

isTerminal function #

func isTerminal(fd int) bool

isTerminal function #

func isTerminal(fd int) bool

isTerminal function #

func isTerminal(fd int) bool

makeRaw function #

func makeRaw(fd int) (*State, error)

makeRaw function #

func makeRaw(fd int) (*State, error)

makeRaw function #

func makeRaw(fd int) (*State, error)

makeRaw function #

func makeRaw(fd int) (*State, error)

move method #

func (t *Terminal) move(up int, down int, left int, right int)

moveCursorToPos method #

moveCursorToPos appends data to t.outBuf which will move the cursor to the given, logical position in the text.

func (t *Terminal) moveCursorToPos(pos int)

queue method #

queue appends data to the end of t.outBuf

func (t *Terminal) queue(data []rune)

readLine method #

func (t *Terminal) readLine() (line string, err error)

readPassword function #

func readPassword(fd int) ([]byte, error)

readPassword function #

func readPassword(fd int) ([]byte, error)

readPassword function #

func readPassword(fd int) ([]byte, error)

readPassword function #

func readPassword(fd int) ([]byte, error)

readPasswordLine function #

readPasswordLine reads from reader until it finds \n or io.EOF. The slice returned does not include the \n. readPasswordLine also ignores any \r it finds. Windows uses \r as end of line. So, on Windows, readPasswordLine reads until it finds \r and ignores any \n it finds during processing.

func readPasswordLine(reader io.Reader) ([]byte, error)

restore function #

func restore(fd int, state *State) error

restore function #

func restore(fd int, state *State) error

restore function #

func restore(fd int, state *State) error

restore function #

func restore(fd int, state *State) error

setLine method #

func (t *Terminal) setLine(newLine []rune, newPos int)

visualLength function #

visualLength returns the number of visible glyphs in s.

func visualLength(runes []rune) int

writeLine method #

func (t *Terminal) writeLine(line []rune)

writeWithCRLF function #

writeWithCRLF writes buf to w but replaces all occurrences of \n with \r\n.

func writeWithCRLF(w io.Writer, buf []byte) (n int, err error)

Generated with Arrow