term

package
v0.0.0-...-da6177f Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT, BSD-3-Clause Imports: 10 Imported by: 0

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

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 DefaultTerm = NewTerm(os.Stdout, os.Stderr)
View Source
var ErrClosed = errors.New("closed")

Functions

func ClearLine

func ClearLine()

func Debug

func Debug(v ...any) (int, error)

func Debugf

func Debugf(format string, v ...any) (int, error)

func DoDebug

func DoDebug() bool

func EnableANSI

func EnableANSI() func()

func Error

func Error(v ...any) (int, error)

func Errorf

func Errorf(format string, v ...any) (int, error)

func Fatal

func Fatal(msg any)

func Fatalf

func Fatalf(format string, v ...any)

func ForceColor

func ForceColor(color bool)

func HadWarnings

func HadWarnings() bool

func HasDarkBackground

func HasDarkBackground() bool

func HideCursor

func HideCursor()

func Info

func Info(v ...any) (int, error)

func Infof

func Infof(format string, v ...any) (int, error)

func IsTerminal

func IsTerminal() bool

func NewNonBlockingStdin

func NewNonBlockingStdin() io.ReadCloser

func Print

func Print(v ...any) (int, error)

func Printc

func Printc(c Color, v ...any) (int, error)

func Printf

func Printf(format string, v ...any) (int, error)

func Printfc

func Printfc(c Color, format string, v ...any) (int, error)

func Println

func Println(v ...any) (int, error)

func Printlnc

func Printlnc(c Color, v ...any) (int, error)

func Reset

func Reset()

func Restore

func Restore(fd int, oldState *State) error

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

func SetDebug

func SetDebug(debug bool)

func SetHadWarnings

func SetHadWarnings(had bool)

func ShowCursor

func ShowCursor()

func StderrCanColor

func StderrCanColor() bool

func StdoutCanColor

func StdoutCanColor() bool

func StripAnsi

func StripAnsi(s string) string

func Warn

func Warn(v ...any) (int, error)

func Warnf

func Warnf(format string, v ...any) (int, error)

Types

type Color

type Color = termenv.ANSIColor

type MessageBuilder

type MessageBuilder struct {
	strings.Builder
	// contains filtered or unexported fields
}

func NewMessageBuilder

func NewMessageBuilder(canColor bool) *MessageBuilder

func (*MessageBuilder) Printc

func (b *MessageBuilder) Printc(c Color, v ...any) (int, error)

type State

type State struct {
	// contains filtered or unexported fields
}

State contains the state of a terminal.

func MakeUnbuf

func MakeUnbuf(fd int) (*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.

type Term

type Term struct {
	// contains filtered or unexported fields
}

func NewTerm

func NewTerm(stdout, stderr io.Writer) *Term

func (*Term) ClearLine

func (t *Term) ClearLine()

func (*Term) Debug

func (t *Term) Debug(v ...any) (int, error)

func (*Term) Debugf

func (t *Term) Debugf(format string, v ...any) (int, error)

func (*Term) DoDebug

func (t *Term) DoDebug() bool

func (*Term) Error

func (t *Term) Error(v ...any) (int, error)

func (*Term) Errorf

func (t *Term) Errorf(format string, v ...any) (int, error)

func (*Term) Fatal

func (t *Term) Fatal(msg any)

func (*Term) Fatalf

func (t *Term) Fatalf(format string, v ...any)

func (*Term) ForceColor

func (t *Term) ForceColor(color bool)

func (*Term) HadWarnings

func (t *Term) HadWarnings() bool

func (*Term) HasDarkBackground

func (t *Term) HasDarkBackground() bool

func (*Term) HideCursor

func (t *Term) HideCursor()

func (*Term) Info

func (t *Term) Info(v ...any) (int, error)

func (*Term) Infof

func (t *Term) Infof(format string, v ...any) (int, error)

func (*Term) IsTerminal

func (t *Term) IsTerminal() bool

func (*Term) Print

func (t *Term) Print(v ...any) (int, error)

func (*Term) Printc

func (t *Term) Printc(c Color, v ...any) (int, error)

func (*Term) Printf

func (t *Term) Printf(format string, v ...any) (int, error)

func (*Term) Printfc

func (t *Term) Printfc(c Color, format string, v ...any) (int, error)

func (*Term) Println

func (t *Term) Println(v ...any) (int, error)

func (*Term) Printlnc

func (t *Term) Printlnc(c Color, v ...any) (int, error)

func (*Term) Reset

func (t *Term) Reset()

func (*Term) SetDebug

func (t *Term) SetDebug(debug bool)

func (*Term) SetHadWarnings

func (t *Term) SetHadWarnings(had bool)

func (*Term) ShowCursor

func (t *Term) ShowCursor()

func (*Term) StderrCanColor

func (t *Term) StderrCanColor() bool

func (*Term) StdoutCanColor

func (t *Term) StdoutCanColor() bool

func (*Term) Warn

func (t *Term) Warn(v ...any) (int, error)

func (*Term) Warnf

func (t *Term) Warnf(format string, v ...any) (int, error)

Jump to

Keyboard shortcuts

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