term

package
v0.0.0-...-d195869 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT, BSD-3-Clause Imports: 8 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.ANSIBrightYellow
	DebugColor = termenv.ANSIBrightBlack // Gray
)

Variables

View Source
var (
	IsTerminal  = term.IsTerminal(int(os.Stdout.Fd())) && term.IsTerminal(int(os.Stdin.Fd())) && isTerminal()
	Stdout      = termenv.NewOutput(os.Stdout)
	Stderr      = termenv.NewOutput(os.Stderr)
	CanColor    = DoColor(Stdout)
	CanColorErr = DoColor(Stderr)
	DoDebug     bool
	HadWarnings bool
)
View Source
var ErrClosed = errors.New("closed")

Functions

func Debug

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

func Debugf

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

func DoColor

func DoColor(o *termenv.Output) bool

DoColor returns true if the provided output's profile is not Ascii.

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 Fprint

func Fprint(w *termenv.Output, c Color, v ...any) (int, error)

func Fprintf

func Fprintf(w *termenv.Output, c Color, format string, v ...any) (int, error)

func Fprintln

func Fprintln(w *termenv.Output, c Color, v ...any) (int, error)

func Info

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

func Infof

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

func NewNonBlockingStdin

func NewNonBlockingStdin() io.ReadCloser

func Print

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

func Printf

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

func Println

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

func Restore

func Restore(fd int, oldState *State) error

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

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

Jump to

Keyboard shortcuts

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