term.go

 1package term
 2
 3// State contains platform-specific state of a terminal.
 4type State struct {
 5	state
 6}
 7
 8// IsTerminal returns whether the given file descriptor is a terminal.
 9func IsTerminal(fd uintptr) bool {
10	return isTerminal(fd)
11}
12
13// MakeRaw puts the terminal connected to the given file descriptor into raw
14// mode and returns the previous state of the terminal so that it can be
15// restored.
16func MakeRaw(fd uintptr) (*State, error) {
17	return makeRaw(fd)
18}
19
20// GetState returns the current state of a terminal which may be useful to
21// restore the terminal after a signal.
22func GetState(fd uintptr) (*State, error) {
23	return getState(fd)
24}
25
26// SetState sets the given state of the terminal.
27func SetState(fd uintptr, state *State) error {
28	return setState(fd, state)
29}
30
31// Restore restores the terminal connected to the given file descriptor to a
32// previous state.
33func Restore(fd uintptr, oldState *State) error {
34	return restore(fd, oldState)
35}
36
37// GetSize returns the visible dimensions of the given terminal.
38//
39// These dimensions don't include any scrollback buffer height.
40func GetSize(fd uintptr) (width, height int, err error) {
41	return getSize(fd)
42}
43
44// ReadPassword reads a line of input from a terminal without local echo.  This
45// is commonly used for inputting passwords and other sensitive data. The slice
46// returned does not include the \n.
47func ReadPassword(fd uintptr) ([]byte, error) {
48	return readPassword(fd)
49}