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