Documentation ¶
Overview ¶
Package term provides a portable interface for terminal I/O.
It manages input and output (I/O) for character-mode applications. The high-level functions enable an application to read from standard input to retrieve keyboard input stored in a terminal's input buffer. They also enable an application to write to standard output or standard error to display text in the terminal's screen buffer. And they also support redirection of standard handles and control of terminal modes for different I/O functionality.
The low-level functions enable applications to receive detailed input about keyboard. They also enable greater control of output to the screen.
Usage:
ter, err := term.New() if err != nil { panic(err) } defer func() { if err = ter.Restore(); err != nil { // Handle error } }()
Important ¶
The "go test" tool runs tests with standard input connected to standard error. So whatever program that uses the file descriptor of "/dev/stdin" (which is 0), then it is going to fail. The solution is to use the standard error.
Index ¶
- Constants
- Variables
- func IsTerminal(fd int) bool
- func ReadPassword(password []byte) (n int, err error)
- func Restore(fd int, st State) error
- func SupportANSI() bool
- type State
- type Terminal
- func (t *Terminal) CharMode() error
- func (t *Terminal) EchoMode(echo bool) error
- func (t *Terminal) Fd() int
- func (t *Terminal) GetSize() (row, column int, err error)
- func (t *Terminal) Mode() modeType
- func (t *Terminal) OriginalState() State
- func (t *Terminal) RawMode() error
- func (t *Terminal) Restore() error
- func (t *Terminal) SetMode(state sys.Termios) error
- type WinSize
Constants ¶
const ( RawMode modeType EchoMode CharMode PasswordMode OtherMode )
Variables ¶
var ( InputFD int = syscall.Stdin Input io.Reader = os.Stdin Output io.Writer = os.Stdout )
Default values for input and output.
var PasswordShadowed bool
If it is true, at reading a password it shows characters shadowed by each key pressed.
Functions ¶
func IsTerminal ¶
IsTerminal returns true if the file descriptor is a term.
func ReadPassword ¶
ReadPassword reads characters from the input until press Enter or until fill in the given slice.
Only reads characters that include letters, marks, numbers, punctuation, and symbols from Unicode categories L, M, N, P, S, besides of the ASCII space character. Ctrl-C interrumpts, and backspace removes the last character read.
Returns the number of bytes read.
Types ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
A Terminal represents a general terminal interface.
func New ¶
New creates a new terminal interface in the file descriptor InputFD.
func (*Terminal) CharMode ¶
CharMode sets the terminal to single-character mode.
func (*Terminal) EchoMode ¶
EchoMode turns the echo mode.
func (*Terminal) Fd ¶
Fd returns the file descriptor referencing the term.
func (*Terminal) GetSize ¶
GetSize returns the size of the term.
func (*Terminal) Mode ¶
func (t *Terminal) Mode() modeType
Mode returns the mode set in the terminal, if any.
func (*Terminal) OriginalState ¶
OriginalState returns the terminal's original state.
func (*Terminal) RawMode ¶
RawMode sets the terminal to something like the "raw" mode. Input is available character by character, echoing is disabled, and all special processing of terminal input and output characters is disabled.
NOTE: in tty "raw mode", CR+LF is used for output and CR is used for input.
func (*Terminal) Restore ¶
Restore restores the original settings for the term.
type WinSize ¶
type WinSize struct { Change chan bool // contains filtered or unexported fields }
WinSize represents a channel, Change, to know when the window size has changed through function DetectWinSize.
Directories ¶
Path | Synopsis |
---|---|
Package readline provides simple functions for both line and screen editing.
|
Package readline provides simple functions for both line and screen editing. |
Package sys contains low-level operating system primitives of the term.
|
Package sys contains low-level operating system primitives of the term. |
Package test checks the functions that depend of the standard input, which is changed by `go test` to the standard error.
|
Package test checks the functions that depend of the standard input, which is changed by `go test` to the standard error. |