term

package
v0.5.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

README

term package

term.go and its sub-sequences (term_unix...) are copied from golang.org/x/term, and:

  • disable err returned by readPassword when unsupported (and plan9, maybe nacl)

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

Constants

This section is empty.

Variables

View Source
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 GetFdSize added in v0.5.9

func GetFdSize(fd uintptr) (cols, rows int, err error)

func GetSize added in v0.5.9

func GetSize(fd int) (width, height int, err error)

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

func GetState(fd int) (*term.State, error)

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 GetTtySizeByFd(fd uintptr) (cols, rows int, err error)

func GetTtySizeByFile added in v0.5.9

func GetTtySizeByFile(outf *os.File) (cols, rows int, err error)

func GetTtySizeByName added in v0.5.9

func GetTtySizeByName(fn string) (cols, rows int, err error)

func IsAnsiEscaped added in v0.5.9

func IsAnsiEscaped(s string) bool

IsAnsiEscaped detects a string if it contains ansi color escaped sequences

func IsCharDevice added in v0.5.9

func IsCharDevice(f *os.File) bool

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

func IsColored(w io.Writer) bool

IsColored detects a writer if it is a colorful tty device.

A colorful tty device can receive ANSI escaped sequences and draw its.

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

func IsTerminal(fd int) bool

IsTerminal returns whether the given file descriptor is a terminal.

func IsTty

func IsTty(w io.Writer) bool

IsTty detects a writer if it is abstracting from a tty (console, terminal) device.

func MakeRaw added in v0.5.9

func MakeRaw(fd int) (*term.State, error)

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

func ReadPassword(fd int) ([]byte, error)

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

func Restore(fd int, oldState *term.State) error

Restore restores the terminal connected to the given file descriptor to a previous state.

func StringToBool added in v0.5.9

func StringToBool(val string, defaultVal ...bool) (ret bool)

func StripEscapes

func StripEscapes(str string) (strCleaned string)

StripEscapes removes any ansi color escaped sequences from a string

func ToBool added in v0.5.9

func ToBool(val any, defaultVal ...bool) (ret bool)

ToBool translate a value (int, bool, string) to boolean

Types

This section is empty.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL