term

package
v1.121.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MPL-2.0 Imports: 7 Imported by: 4

Documentation

Overview

Package term provides terminal utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(f io.Writer) bool

IsTerminal returns true if the writer's file descriptor is a terminal.

func Read

func Read() (ch byte, ok bool)

Read a byte from the terminal.

func Size

func Size() (columns, rows int)

Size returns the number of columns and rows comprising the terminal.

func WrapText

func WrapText(out io.Writer, prefix, text string)

WrapText prints the 'prefix' to 'out' and then wraps 'text' in the remaining space.

Types

type ANSI

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

ANSI provides support for ANSI terminal escape sequences.

func NewANSI

func NewANSI(out io.Writer) *ANSI

NewANSI creates a new ANSI terminal and attaches it to 'out'.

func (*ANSI) Background

func (a *ANSI) Background(color Color)

Background sets the background color for subsequent output.

func (*ANSI) Bell

func (a *ANSI) Bell()

Bell causes the bell to sound.

func (*ANSI) Clear

func (a *ANSI) Clear()

Clear the screen and position the cursor at row 1, column 1.

func (*ANSI) ClearToEnd

func (a *ANSI) ClearToEnd()

ClearToEnd clears the screen from the cursor to the end of the screen.

func (*ANSI) ClearToStart

func (a *ANSI) ClearToStart()

ClearToStart clears the screen from the cursor to the beginning of the screen.

func (*ANSI) Down

func (a *ANSI) Down(count int)

Down moves the cursor down 'count' rows. If this would put it beyond the bottom edge of the screen, it will instead go to the bottom edge of the screen.

func (*ANSI) EraseLine

func (a *ANSI) EraseLine()

EraseLine clears the current row.

func (*ANSI) EraseLineToEnd

func (a *ANSI) EraseLineToEnd()

EraseLineToEnd clears from the cursor position to the end of the current row.

func (*ANSI) EraseLineToStart

func (a *ANSI) EraseLineToStart()

EraseLineToStart clears from the cursor position to the start of the current row.

func (*ANSI) Foreground

func (a *ANSI) Foreground(color Color, style Style)

Foreground sets the foreground color and style for subsequent output.

func (*ANSI) HideCursor

func (a *ANSI) HideCursor()

HideCursor makes the cursor invisible.

func (*ANSI) Left

func (a *ANSI) Left(count int)

Left moves the cursor left 'count' columns. If this would put it beyond the left edge of the screen, it will instead go to the left edge of the screen.

func (*ANSI) Position

func (a *ANSI) Position(row, column int)

Position the cursor at 'row' and 'column'. Both values are 1-based.

func (*ANSI) Reset

func (a *ANSI) Reset()

Reset colors and styles.

func (*ANSI) RestorePosition

func (a *ANSI) RestorePosition()

RestorePosition restores the previously saved cursor position.

func (*ANSI) Right

func (a *ANSI) Right(count int)

Right moves the cursor right 'count' columns. If this would put it beyond the right edge of the screen, it will instead go to the right edge of the screen.

func (*ANSI) SavePosition

func (a *ANSI) SavePosition()

SavePosition saves the current cursor position.

func (*ANSI) ShowCursor

func (a *ANSI) ShowCursor()

ShowCursor makes the cursor visible.

func (*ANSI) Up

func (a *ANSI) Up(count int)

Up moves the cursor up 'count' rows. If this would put it beyond the top edge of the screen, it will instead go to the top edge of the screen.

func (*ANSI) Write

func (a *ANSI) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

type Color

type Color int

Color represents an ANSI terminal color

const (
	Black Color = iota
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

ANSI color constants

type Style

type Style int

Style represents an ANSI terminal style. Multiple styles may be or'd together.

const (
	Bold Style = 1 << iota
	Underline
	Blink
	Normal = 0
)

ANSI style constants. Multiple styles may be or'd together.

Jump to

Keyboard shortcuts

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