xtermo

package
v0.0.0-...-796497b Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StateDefault     = CellState{Attrib: AttrNone, FGColor: ColorDefault, BGColor: ColorDefault}
	BoldWhiteOnBlack = CellState{Attrib: AttrBold, FGColor: ColorGray.Light(), BGColor: ColorBlack}
	BoldBlackOnWhite = CellState{Attrib: AttrBold, FGColor: ColorBlack, BGColor: ColorGray.Light()}
)

Predefined attributes

View Source
var ErrNotATerminal = errors.New("not running in a terminal")

ErrNotATerminal is the error returned when running termo in an unsupported environment

Functions

func EnableMouseEvents

func EnableMouseEvents()

EnableMouseEvents makes mouse events start arriving through the input read loop

func HideCursor

func HideCursor()

HideCursor makes the cursor invisible

func Init

func Init() error

Init initializes termo to work with the terminal

func SetCursor

func SetCursor(x, y int)

SetCursor positions the cursor at the specified coordinates. Cursor visibility is not affected.

func ShowCursor

func ShowCursor()

ShowCursor makes the cursor visible

func Size

func Size() (int, int, error)

Size returns the current size of the terminal

func StartKeyReadLoop

func StartKeyReadLoop(keyChan chan<- ScanCode, errChan chan<- error)

StartKeyReadLoop runs a goroutine that keeps reading terminal input forever. It returns events through the keyChan param, and errors through the errChan parameter

func Stop

func Stop()

Stop restores the terminal to its original state

Types

type Attribute

type Attribute int

Attribute holds data for each possible visualization mode

const (
	AttrNone  Attribute = 0
	AttrBold  Attribute = 1
	AttrDim   Attribute = 2
	AttrUnder Attribute = 4
	AttrBlink Attribute = 5
	AttrRev   Attribute = 7
	AttrHid   Attribute = 8
)

Attributes for different character visualization modes

type CellState

type CellState struct {
	Attrib  Attribute
	FGColor Color
	BGColor Color
}

CellState holds all the attributes for a cell

type Color

type Color int

Color holds character color information

const (
	ColorBlack Color = 30 + iota
	ColorRed
	ColorGreen
	ColorYellow
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorGray
	ColorDefault Color = 39
)

Different colors to use as attributes

func (Color) Light

func (c Color) Light() Color

Light returns the "ligther" version for that color

type Framebuffer

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

Framebuffer contains the runes and attributes that will be drawn in the terminal

func NewFramebuffer

func NewFramebuffer(w, h int) *Framebuffer

NewFramebuffer creates a Framebuffer with the specified size and initializes it filling it with blank spaces and default attributes

func (*Framebuffer) ASCIIRect

func (f *Framebuffer) ASCIIRect(x0, y0, w, h int, doubleWidth bool, clearInside bool)

ASCIIRect draws an ASCII rectangle. It can either be single-width (─) or double-width (═). It can also clear the inner part of the rectangle, if desired.

func (*Framebuffer) AttribRect

func (f *Framebuffer) AttribRect(x0, y0, w, h int, s CellState)

AttribRect sets the attributes for a rectangular region without changing the runes

func (*Framebuffer) AttribText

func (f *Framebuffer) AttribText(x0, y0 int, s CellState, t string)

AttribText draws a string from left to right, starting at x0,y0 There is no wrapping mechanism, and parts of the text outside the framebuffer will be ignored. This call will also change the written cells' attributes to the specified ones.

func (*Framebuffer) CenterText

func (f *Framebuffer) CenterText(x, y0 int, t string)

CenterText draws a string from left to right and top-to-bottom, starting at x-len(t)/2,y0. There is no wrapping mechanism, and parts of the text outside the framebuffer will be ignored. Attributes for written cells will remain unchanged.

func (*Framebuffer) Clear

func (f *Framebuffer) Clear()

Clear fills the framebuffer with blank spaces and default attributes

func (*Framebuffer) Flush

func (f *Framebuffer) Flush()

Flush pushes the current state of the framebuffer to the terminal

func (*Framebuffer) Get

func (f *Framebuffer) Get(x, y int) (rune, CellState)

Get returns the rune stored in the [x,y] position. If coords are outside the framebuffer size, it returns ' '

func (*Framebuffer) GetAttrNone

func (f *Framebuffer) GetAttrNone() Attribute

func (*Framebuffer) GetBoldWhiteOnBlack

func (f *Framebuffer) GetBoldWhiteOnBlack() CellState

func (*Framebuffer) GetColorBlue

func (f *Framebuffer) GetColorBlue() Color

func (*Framebuffer) GetColorGray

func (f *Framebuffer) GetColorGray() Color

func (*Framebuffer) GetHeight

func (f *Framebuffer) GetHeight() int

func (*Framebuffer) GetWidth

func (f *Framebuffer) GetWidth() int

func (*Framebuffer) NewCellState

func (f *Framebuffer) NewCellState() CellState

func (*Framebuffer) Set

func (f *Framebuffer) Set(x, y int, s CellState, r rune)

Set sets a rune in the specified position with the specified attributes

func (*Framebuffer) SetRect

func (f *Framebuffer) SetRect(x0, y0, w, h int, s CellState, r rune)

SetRect fills a rectangular region with a rune and state

func (*Framebuffer) SetRune

func (f *Framebuffer) SetRune(x, y int, r rune)

SetRune sets a rune in the specified position without modifying its attributes

func (*Framebuffer) SetText

func (f *Framebuffer) SetText(x0, y0 int, t string)

SetText draws a string from left to right, and top-to bottom, starting at x0,y0. There is no wrapping mechanism, and parts of the text outside the framebuffer will be ignored. Attributes for written cells will remain unchanged.

type ScanCode

type ScanCode []byte

ScanCode contains data for a terminal keypress

func ReadScanCode

func ReadScanCode() (ScanCode, error)

ReadScanCode reads a keypress from stdin. It will block until it can read something

func (ScanCode) EscapeCode

func (s ScanCode) EscapeCode() byte

EscapeCode returns the escape code for a keypress

func (ScanCode) IsEscapeCode

func (s ScanCode) IsEscapeCode() bool

IsEscapeCode returns true if the terminal considers it an escape code

func (ScanCode) IsMouseDownEvent

func (s ScanCode) IsMouseDownEvent() bool

IsMouseDownEvent returns wether it is a mouse button down event

func (ScanCode) IsMouseMoveEvent

func (s ScanCode) IsMouseMoveEvent() bool

IsMouseMoveEvent returns wether it is a mouse move event

func (ScanCode) IsMouseUpEvent

func (s ScanCode) IsMouseUpEvent() bool

IsMouseUpEvent returns wether it is a mouse button up event

func (ScanCode) MouseCoords

func (s ScanCode) MouseCoords() (int, int)

MouseCoords returns data for the mouse position. Returned coords start at [0,0] for upper-left corner

func (ScanCode) Rune

func (s ScanCode) Rune() rune

Rune returns the actual key pressed (only for non-escapecode keypresses)

Directories

Path Synopsis
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.

Jump to

Keyboard shortcuts

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