termo: github.com/jonvaldes/termo Index | Files | Directories

package termo

import "github.com/jonvaldes/termo"


Package Files



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

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

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

func EnableMouseEvents Uses

func EnableMouseEvents()

EnableMouseEvents makes mouse events start arriving through the input read loop

func HideCursor Uses

func HideCursor()

HideCursor makes the cursor invisible

func Init Uses

func Init() error

Init initializes termo to work with the terminal

func SetCursor Uses

func SetCursor(x, y int)

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

func ShowCursor Uses

func ShowCursor()

ShowCursor makes the cursor visible

func Size Uses

func Size() (int, int, error)

Size returns the current size of the terminal

func StartKeyReadLoop Uses

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 Uses

func Stop()

Stop restores the terminal to its original state

type Attribute Uses

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 Uses

type CellState struct {
    Attrib  Attribute
    FGColor Color
    BGColor Color

CellState holds all the attributes for a cell

type Color Uses

type Color int

Color holds character color information

const (
    ColorBlack Color = 30 + iota
    ColorDefault Color = 39

Different colors to use as attributes

func (Color) Light Uses

func (c Color) Light() Color

Light returns the "ligther" version for that color

type Framebuffer Uses

type Framebuffer struct {
    // contains filtered or unexported fields

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

func NewFramebuffer Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (f *Framebuffer) Clear()

Clear fills the framebuffer with blank spaces and default attributes

func (*Framebuffer) Flush Uses

func (f *Framebuffer) Flush()

Flush pushes the current state of the framebuffer to the terminal

func (*Framebuffer) Get Uses

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) Set Uses

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 Uses

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 Uses

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

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

func (*Framebuffer) SetText Uses

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 Uses

type ScanCode []byte

ScanCode contains data for a terminal keypress

func ReadScanCode Uses

func ReadScanCode() (ScanCode, error)

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

func (ScanCode) EscapeCode Uses

func (s ScanCode) EscapeCode() byte

EscapeCode returns the escape code for a keypress

func (ScanCode) IsEscapeCode Uses

func (s ScanCode) IsEscapeCode() bool

IsEscapeCode returns true if the terminal considers it an escape code

func (ScanCode) IsMouseDownEvent Uses

func (s ScanCode) IsMouseDownEvent() bool

IsMouseDownEvent returns wether it is a mouse button down event

func (ScanCode) IsMouseMoveEvent Uses

func (s ScanCode) IsMouseMoveEvent() bool

IsMouseMoveEvent returns wether it is a mouse move event

func (ScanCode) IsMouseUpEvent Uses

func (s ScanCode) IsMouseUpEvent() bool

IsMouseUpEvent returns wether it is a mouse button up event

func (ScanCode) MouseCoords Uses

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 Uses

func (s ScanCode) Rune() rune

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


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

Package termo imports 6 packages (graph). Updated 2016-07-20. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).