term

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 7 Imported by: 35

Documentation

Overview

Package term provides information about the terminal that the current process is connected to (if any), for example measuring the dimensions of the terminal and inspecting whether it's safe to output color.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsColorDisabled

func IsColorDisabled() bool

IsColorDisabled returns true if environment variables NO_COLOR or CLICOLOR prohibit usage of color codes in terminal output.

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether a file descriptor is connected to a terminal.

Types

type Term

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

Term represents information about the terminal that a process is connected to.

func FromEnv

func FromEnv() Term

FromEnv initializes a Term from os.Stdout and environment variables:

  • GH_FORCE_TTY
  • NO_COLOR
  • CLICOLOR
  • CLICOLOR_FORCE
  • TERM
  • COLORTERM

func (Term) ErrOut added in v1.2.0

func (t Term) ErrOut() io.Writer

ErrOut is the writer writing to standard error.

func (Term) In added in v1.2.0

func (t Term) In() io.Reader

In is the reader reading from standard input.

func (Term) Is256ColorSupported

func (t Term) Is256ColorSupported() bool

Is256ColorSupported reports whether the terminal advertises ANSI 256 color codes.

func (Term) IsColorEnabled

func (t Term) IsColorEnabled() bool

IsColorEnabled reports whether it's safe to output ANSI color sequences, depending on IsTerminalOutput and environment variables.

func (Term) IsTerminalOutput

func (t Term) IsTerminalOutput() bool

IsTerminalOutput returns true if standard output is connected to a terminal.

func (Term) IsTrueColorSupported

func (t Term) IsTrueColorSupported() bool

IsTrueColorSupported reports whether the terminal advertises support for ANSI true color sequences.

func (Term) Out

func (t Term) Out() io.Writer

Out is the writer writing to standard output.

func (Term) Size

func (t Term) Size() (int, int, error)

Size returns the width and height of the terminal that the current process is attached to. In case of errors, the numeric values returned are -1.

func (Term) Theme added in v0.1.1

func (t Term) Theme() string

Theme returns the theme of the terminal by analyzing the background color of the terminal.

Jump to

Keyboard shortcuts

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