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 ¶
- func DisableColors() bool
- 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 IsColorful(w io.Writer) (colorful bool)
- func IsCygwinTerminal(fd uintptr) bool
- func IsENOTTY(err error) bool
- func IsRoot() bool
- func IsStartupByDoubleClick() bool
- func IsTerminal(fd int) bool
- func IsTty(w io.Writer) bool
- func MakeNewTerm(ctx context.Context, config *PromptModeConfig) (deferFunc func(), err error)
- func MakeRaw(fd int) (*term.State, error)
- func MakeRawWrapped() (deferFunc func(), err error)
- func ReadPassword(fd int) ([]byte, error)
- func ReadTill(fd int, delim byte) (string, bool, error)
- func Restore(fd int, oldState *term.State) error
- func SetDisableColors(b bool)
- func StatStdout() (normalFile, redirected, piped, term bool)
- func StatStdoutString() (status string)
- func StdoutIsPiped() (b bool)
- func StringToBool(val string, defaultVal ...bool) (ret bool)
- func StripEscapes(str string) (strCleaned string)
- func ToBool(val any, defaultVal ...bool) (ret bool)
- type LooperFunc
- type PromptModeConfig
- type SmallTerm
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableColors ¶
func DisableColors() bool
DisableColors return a state which identify wherher needs disable colorful console output always.
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 IsColorful ¶ added in v0.7.23
IsColorful 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 MakeNewTerm ¶ added in v0.8.26
func MakeNewTerm(ctx context.Context, config *PromptModeConfig) (deferFunc func(), err error)
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 MakeRawWrapped ¶ added in v0.8.26
func MakeRawWrapped() (deferFunc func(), err error)
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 ReadTill ¶ added in v0.8.35
ReadTill reads a line or a string ending with delim of input from a terminal without local echo.
func Restore ¶ added in v0.5.9
Restore restores the terminal connected to the given file descriptor to a previous state.
func SetDisableColors ¶ added in v0.8.35
func SetDisableColors(b bool)
func StatStdout ¶ added in v0.7.23
func StatStdout() (normalFile, redirected, piped, term bool)
func StatStdoutString ¶ added in v0.7.23
func StatStdoutString() (status string)
func StdoutIsPiped ¶ added in v0.7.23
func StdoutIsPiped() (b bool)
func StringToBool ¶ added in v0.5.9
func StripEscapes ¶
StripEscapes removes any ansi color escaped sequences from a string
Types ¶
type LooperFunc ¶ added in v0.8.26
type PromptModeConfig ¶ added in v0.8.46
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package chk provides some checked terminal utilities.
|
Package chk provides some checked terminal utilities. |
Package color provides a wrapped standard output device like printf but with colored enhancements.
|
Package color provides a wrapped standard output device like printf but with colored enhancements. |