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"
"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"
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{...}
var crlf = []byte{...}
const ioctlReadTermios = unix.TIOCGETA
const ioctlReadTermios = unix.TCGETS
const ioctlWriteTermios = unix.TCSETS
const ioctlWriteTermios = unix.TIOCSETA
const keyAltLeft
const keyAltRight
const keyBackspace = 127
const keyClearScreen
const keyCtrlC = 3
const keyCtrlD = 4
const keyCtrlU = 21
const keyDeleteLine
const keyDeleteWord
const keyDown
const keyEnd
const keyEnter = '\r'
const keyEscape = 27
const keyHome
const keyLeft
const keyPasteEnd
const keyPasteStart
const keyRight
const keyUnknown = *ast.BinaryExpr
const keyUp
const maxLineLength = 4096
var pasteEnd = []byte{...}
var pasteStart = []byte{...}
var space = []rune{...}
var vt100EscapeCodes = EscapeCodes{...}
passwordReader is an io.Reader that reads from a specific file descriptor.
type passwordReader int
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 contains the state of a terminal.
type State struct {
state
}
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
}
type pasteIndicatorError struct {
}
stRingBuffer is a ring buffer of strings.
type stRingBuffer struct {
entries []string
max int
head int
size int
}
type state struct {
}
type state struct {
mode uint32
}
type state struct {
}
type state struct {
termios unix.Termios
}
func (s *stRingBuffer) Add(a string)
func (pasteIndicatorError) Error() string
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 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 returns whether the given file descriptor is a terminal.
func IsTerminal(fd int) bool
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 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 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)
func (r passwordReader) Read(buf []byte) (int, error)
ReadLine returns a line of input from the terminal.
func (t *Terminal) ReadLine() (line string, err error)
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 temporarily changes the prompt and reads a password, without echo, from the terminal.
func (t *Terminal) ReadPassword(prompt string) (line string, err error)
Restore restores the terminal connected to the given file descriptor to a previous state.
func Restore(fd int, oldState *State) error
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 sets the prompt to be used when reading subsequent lines.
func (t *Terminal) SetPrompt(prompt string)
func (t *Terminal) SetSize(width int, height int) error
func (t *Terminal) Write(buf []byte) (n int, err error)
addKeyToLine inserts the given key at the current position in the current line.
func (t *Terminal) addKeyToLine(key rune)
func (t *Terminal) advanceCursor(places int)
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)
func (t *Terminal) clearAndRepaintLinePlusNPrevious(numPrevLines int)
func (t *Terminal) clearLineToRight()
countToLeftWord returns then number of characters from the cursor to the start of the previous word.
func (t *Terminal) countToLeftWord() int
countToRightWord returns then number of characters from the cursor to the start of the next word.
func (t *Terminal) countToRightWord() int
func (t *Terminal) eraseNPreviousChars(n int)
func getSize(fd int) (width int, height int, err error)
func getSize(fd int) (width int, height int, err error)
func getSize(fd int) (width int, height int, err error)
func getSize(fd int) (width int, height int, err error)
func getState(fd int) (*State, error)
func getState(fd int) (*State, error)
func getState(fd int) (*State, error)
func getState(fd int) (*State, error)
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)
func isPrintable(key rune) bool
func isTerminal(fd int) bool
func isTerminal(fd int) bool
func isTerminal(fd int) bool
func isTerminal(fd int) bool
func makeRaw(fd int) (*State, error)
func makeRaw(fd int) (*State, error)
func makeRaw(fd int) (*State, error)
func makeRaw(fd int) (*State, error)
func (t *Terminal) move(up int, down int, left int, right int)
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 appends data to the end of t.outBuf
func (t *Terminal) queue(data []rune)
func (t *Terminal) readLine() (line string, err error)
func readPassword(fd int) ([]byte, error)
func readPassword(fd int) ([]byte, error)
func readPassword(fd int) ([]byte, error)
func readPassword(fd int) ([]byte, error)
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)
func restore(fd int, state *State) error
func restore(fd int, state *State) error
func restore(fd int, state *State) error
func restore(fd int, state *State) error
func (t *Terminal) setLine(newLine []rune, newPos int)
visualLength returns the number of visible glyphs in s.
func visualLength(runes []rune) int
func (t *Terminal) writeLine(line []rune)
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