Documentation
¶
Overview ¶
Package term provides support functions for dealing with terminals, as commonly found on UNIX systems.
Putting a terminal into raw mode is the most common requirement:
oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { panic(err) } defer term.Restore(int(os.Stdin.Fd()), oldState)
Note that on non-Unix systems os.Stdin.Fd() may not be 0.
Index ¶
- Variables
- func GetFdSize(fd uintptr) (cols, rows int, err error)
- func GetSize(fd int) (width, height int, err error)
- func GetState(fd int) (*term.State, error)
- func GetTtySize() (cols, rows int)
- func GetTtySizeByFd(fd uintptr) (cols, rows int, err error)
- func GetTtySizeByFile(outf *os.File) (cols, rows int, err error)
- func GetTtySizeByName(fn string) (cols, rows int, err error)
- func IsAnsiEscaped(s string) bool
- func IsCharDevice(f *os.File) bool
- func IsColored(w io.Writer) bool
- func IsCygwinTerminal(fd uintptr) bool
- func IsRoot() bool
- func IsStartupByDoubleClick() bool
- func IsTerminal(fd int) bool
- func IsTty(w io.Writer) bool
- func MakeRaw(fd int) (*term.State, error)
- func ReadPassword(fd int) ([]byte, error)
- func Restore(fd int, oldState *term.State) error
- func StringToBool(val string, defaultVal ...bool) (ret bool)
- func StripEscapes(str string) (strCleaned string)
- func ToBool(val any, defaultVal ...bool) (ret bool)
Constants ¶
This section is empty.
Variables ¶
var ( EnvironmentOverrideColors bool = true DisableColors bool // no colorful paint? false to disable colorful paint. ForceColors bool // always colorful paint? true to enable colorful paint even if the underlying tty cannot support ANSI escaped sequences. )
Functions ¶
func GetSize ¶ added in v0.5.9
GetSize returns the visible dimensions of the given terminal.
These dimensions don't include any scrollback buffer height.
func GetState ¶ added in v0.5.9
GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.
func GetTtySize ¶
func GetTtySize() (cols, rows int)
GetTtySize returns the window size in columns and rows in the active console window. The return value of this function is in the order of cols, rows.
func GetTtySizeByFd ¶ added in v0.5.9
func GetTtySizeByFile ¶ added in v0.5.9
func GetTtySizeByName ¶ added in v0.5.9
func IsAnsiEscaped ¶ added in v0.5.9
IsAnsiEscaped detects a string if it contains ansi color escaped sequences
func IsCharDevice ¶ added in v0.5.9
IsCharDevice detect a file if it's a character device, for unix. Specially used for test if terminal under darwin, since new macOS has a different os.Stdout.
func IsColored ¶
IsColored detects a writer if it is a colorful tty device.
A colorful tty device can receive ANSI escaped sequences and draw its.
func IsCygwinTerminal ¶ added in v0.5.27
IsCygwinTerminal return true if the file descriptor is a cygwin or msys2 terminal. This is also always false on this environment.
func IsStartupByDoubleClick ¶ added in v0.5.9
func IsStartupByDoubleClick() bool
IsStartupByDoubleClick detects if windows golang executable file is running via double click or from cmd/shell terminator
func IsTerminal ¶ added in v0.5.9
IsTerminal returns whether the given file descriptor is a terminal.
func MakeRaw ¶ added in v0.5.9
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 ReadPassword ¶
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 Restore ¶ added in v0.5.9
Restore restores the terminal connected to the given file descriptor to a previous state.
func StringToBool ¶ added in v0.5.9
func StripEscapes ¶
StripEscapes removes any ansi color escaped sequences from a string
Types ¶
This section is empty.