terminalapi

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 110

Documentation

Overview

Package terminalapi defines the API of all terminal implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorMode

type ColorMode int

ColorMode represents a color mode of a terminal.

const (
	// ColorModeNormal supports 16 Xterm colors.
	// These are defined as constants in the cell package.
	ColorModeNormal ColorMode = iota

	// ColorMode256 enables using any of the 256 terminal colors.
	//     0-7: the 8 Xterm colors accessible in ColorModeNormal.
	//    8-15: the 8 "bright" Xterm colors.
	//  16-231: the 216 different terminal colors.
	// 232-255: the 24 different shades of grey.
	ColorMode256

	// ColorMode216 supports only the third range of the ColorMode256, i.e the
	// 216 different terminal colors. However in this mode the colors are zero
	// based, so the caller doesn't need to provide an offset.
	ColorMode216

	// ColorModeGrayscale supports only the fourth range of the ColorMode256,
	// i.e the 24 different shades of grey. However in this mode the colors are
	// zero based, so the caller doesn't need to provide an offset.
	ColorModeGrayscale
)

Supported color modes.

func (ColorMode) String

func (cm ColorMode) String() string

String implements fmt.Stringer()

type Error

type Error string

Error is an event indicating an error while processing input.

func NewError

func NewError(e string) *Error

NewError returns a new Error event.

func NewErrorf

func NewErrorf(format string, args ...interface{}) *Error

NewErrorf returns a new Error event, arguments are similar to fmt.Sprintf.

func (*Error) Error

func (e *Error) Error() error

Error returns the error that occurred.

func (Error) String

func (e Error) String() string

String implements fmt.Stringer.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event represents an input event.

type Keyboard

type Keyboard struct {
	// Key is the pressed key.
	Key keyboard.Key
}

Keyboard is the event used when a key is pressed. Implements terminalapi.Event.

func (Keyboard) String

func (k Keyboard) String() string

String implements fmt.Stringer.

type Mouse

type Mouse struct {
	// Position of the mouse on the terminal.
	Position image.Point
	// Button identifies the pressed button if any.
	Button mouse.Button
}

Mouse is the event used when the mouse is moved or a mouse button is pressed. Implements terminalapi.Event.

func (Mouse) String

func (m Mouse) String() string

String implements fmt.Stringer.

type Resize

type Resize struct {
	// Size is the new size of the terminal.
	Size image.Point
}

Resize is the event used when the terminal was resized. Implements terminalapi.Event.

func (Resize) String

func (r Resize) String() string

String implements fmt.Stringer.

type Terminal

type Terminal interface {
	// Size returns the terminal width and height in cells.
	Size() image.Point

	// Clear clears the content of the internal back buffer, resetting all
	// cells to their default content and attributes. Sets the provided options
	// on all the cell.
	Clear(opts ...cell.Option) error
	// Flush flushes the internal back buffer to the terminal.
	Flush() error

	// SetCursor sets the position of the cursor.
	SetCursor(p image.Point)
	// HideCursos hides the cursor.
	HideCursor()

	// SetCell sets the value of the specified cell to the provided rune.
	// Use the options to specify which attributes to modify, if an attribute
	// option isn't specified, the attribute retains its previous value.
	SetCell(p image.Point, r rune, opts ...cell.Option) error

	// Event waits for the next event and returns it.
	// This call blocks until the next event or cancellation of the context.
	// Returns nil when the context gets canceled.
	Event(ctx context.Context) Event

	// Close closes the underlying terminal implementation and should be called when
	// the terminal isn't required anymore to return the screen to a sane state.
	Close()
}

Terminal abstracts an implementation of a 2-D terminal. A terminal consists of a number of cells.

Jump to

Keyboard shortcuts

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