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
- Variables
- func ClearLine()
- func Debug(v ...any) (int, error)
- func Debugf(format string, v ...any) (int, error)
- func DoDebug() bool
- func EnableANSI() func()
- func Error(v ...any) (int, error)
- func Errorf(format string, v ...any) (int, error)
- func Fatal(msg any)
- func Fatalf(format string, v ...any)
- func ForceColor(color bool)
- func HadWarnings() bool
- func HasDarkBackground() bool
- func HideCursor()
- func Info(v ...any) (int, error)
- func Infof(format string, v ...any) (int, error)
- func IsTerminal() bool
- func NewNonBlockingStdin() io.ReadCloser
- func Print(v ...any) (int, error)
- func Printc(c Color, v ...any) (int, error)
- func Printf(format string, v ...any) (int, error)
- func Printfc(c Color, format string, v ...any) (int, error)
- func Println(v ...any) (int, error)
- func Printlnc(c Color, v ...any) (int, error)
- func Reset()
- func Restore(fd int, oldState *State) error
- func SetDebug(debug bool)
- func SetHadWarnings(had bool)
- func ShowCursor()
- func StderrCanColor() bool
- func StdoutCanColor() bool
- func StripAnsi(s string) string
- func Warn(v ...any) (int, error)
- func Warnf(format string, v ...any) (int, error)
- type Color
- type MessageBuilder
- type State
- type Term
- func (t *Term) ClearLine()
- func (t *Term) Debug(v ...any) (int, error)
- func (t *Term) Debugf(format string, v ...any) (int, error)
- func (t *Term) DoDebug() bool
- func (t *Term) Error(v ...any) (int, error)
- func (t *Term) Errorf(format string, v ...any) (int, error)
- func (t *Term) Fatal(msg any)
- func (t *Term) Fatalf(format string, v ...any)
- func (t *Term) ForceColor(color bool)
- func (t *Term) HadWarnings() bool
- func (t *Term) HasDarkBackground() bool
- func (t *Term) HideCursor()
- func (t *Term) Info(v ...any) (int, error)
- func (t *Term) Infof(format string, v ...any) (int, error)
- func (t *Term) IsTerminal() bool
- func (t *Term) Print(v ...any) (int, error)
- func (t *Term) Printc(c Color, v ...any) (int, error)
- func (t *Term) Printf(format string, v ...any) (int, error)
- func (t *Term) Printfc(c Color, format string, v ...any) (int, error)
- func (t *Term) Println(v ...any) (int, error)
- func (t *Term) Printlnc(c Color, v ...any) (int, error)
- func (t *Term) Reset()
- func (t *Term) SetDebug(debug bool)
- func (t *Term) SetHadWarnings(had bool)
- func (t *Term) ShowCursor()
- func (t *Term) StderrCanColor() bool
- func (t *Term) StdoutCanColor() bool
- func (t *Term) Warn(v ...any) (int, error)
- func (t *Term) Warnf(format string, v ...any) (int, error)
Constants ¶
View Source
const ( BrightCyan = termenv.ANSIBrightCyan InfoColor = termenv.ANSIBrightMagenta ErrorColor = termenv.ANSIBrightRed WarnColor = termenv.ANSIYellow // not bright to improve readability on light backgrounds DebugColor = termenv.ANSIBrightBlack // Gray )
View Source
const ResetColorStr = termenv.CSI + termenv.ResetSeq + "m"
Variables ¶
View Source
var ErrClosed = errors.New("closed")
Functions ¶
func EnableANSI ¶
func EnableANSI() func()
func ForceColor ¶
func ForceColor(color bool)
func HadWarnings ¶
func HadWarnings() bool
func HasDarkBackground ¶
func HasDarkBackground() bool
func HideCursor ¶
func HideCursor()
func IsTerminal ¶
func IsTerminal() bool
func NewNonBlockingStdin ¶
func NewNonBlockingStdin() io.ReadCloser
func Restore ¶
Restore restores the terminal connected to the given file descriptor to a previous state.
func SetHadWarnings ¶
func SetHadWarnings(had bool)
func ShowCursor ¶
func ShowCursor()
func StderrCanColor ¶
func StderrCanColor() bool
func StdoutCanColor ¶
func StdoutCanColor() bool
Types ¶
type MessageBuilder ¶
func NewMessageBuilder ¶
func NewMessageBuilder(canColor bool) *MessageBuilder
type State ¶
type State struct {
// contains filtered or unexported fields
}
State contains the state of a terminal.
type Term ¶
type Term struct {
// contains filtered or unexported fields
}
func (*Term) ForceColor ¶
func (*Term) HadWarnings ¶
func (*Term) HasDarkBackground ¶
func (*Term) HideCursor ¶
func (t *Term) HideCursor()
func (*Term) IsTerminal ¶
func (*Term) SetHadWarnings ¶
func (*Term) ShowCursor ¶
func (t *Term) ShowCursor()
func (*Term) StderrCanColor ¶
func (*Term) StdoutCanColor ¶
Click to show internal directories.
Click to hide internal directories.