vt100

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 9 Imported by: 16

README

vt100

Build Status GoDoc License Go Report Card

VT100 Terminal Package
  • Supports colors and attributes.
  • Developed for Linux. May work on other systems, but there are no guarantees.
  • Can detect the terminal size.
  • Can get key-presses, including arrow keys.
  • Has a Canvas struct, for drawing only the updated characters to the terminal.
  • Uses the spec directly, but memoizes the commands sent to the terminal, for speed.
Simple use

Output "hi" in blue:

fmt.Println(vt100.BrightColor("hi", "Blue"))

Erase the current line:

vt100.Do("Erase Line")

Move the cursor 3 steps up (it's a bit verbose, but it's generated directly from spec, memoized for speed and is easy to wrap in a custom function):

vt100.Set("Cursor Up", map[string]string{"{COUNT}": "3"})

The full overview of possible commands are at the top of vt100.go.

Another example

See cmd/move for a more advanced example, where a character can be moved around with the arrow keys.

Features and limitations
  • Can detect letters, arrow keys and space. F12 and similar keys are not supported (they are supported by vt220 but not vt100).
  • Resizing the terminal when using the Canvas struct may cause artifacts, for a brief moment.
  • Holding down a key may trigger key repetition which may speed up the main loop.
General info

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIIOnce added in v0.2.1

func ASCIIOnce() int

func AttributeAndColor

func AttributeAndColor(attr, name string) string

Get the terminal command for setting a terminal attribute and a color

func AttributeOrColor

func AttributeOrColor(name string) string

Execute the terminal command for setting a given display attribute name, like "Bright" or "Blink"

func BrightColor

func BrightColor(text, color string) string

Return text with a bright color applied

func Clear

func Clear()

Clear screen

func ColorNum

func ColorNum(colorNum int) string

Get the terminal command for setting a given color number

func Colors

func Colors() []string

Return all available colors

func Commands

func Commands() []string

Return all available commands

func Do

func Do(command string)

Do the given command, with no parameters

func Down

func Down(n uint)

Move the cursor down

func Get

func Get(command string, replacemap map[string]string) string

Return the terminal command, given a map to replace the values mentioned in the spec. If "dummy" is true, the terminal command will be printed instead of executed.

func Home

func Home()

func KeyCodeOnce added in v0.2.1

func KeyCodeOnce() int

func KeyOnce added in v0.2.1

func KeyOnce() int

func Left

func Left(n uint)

Move the cursor to the left

func NoColor

func NoColor() string

Get the terminal command for setting no colors or other display attributes

func Reset

func Reset()
func Right(n uint)

Move the cursor to the right

func Set

func Set(command string, replacemap map[string]string)

Do the terminal command, given a map to replace the values mentioned in the spec. If "dummy" is true, the terminal command will be printed instead of executed.

func SetAttribute

func SetAttribute(name string)

Execute the terminal command for setting a given display attribute name, like "Bright" or "Blink"

func SetAttributeAndColor

func SetAttributeAndColor(attr, name string)

Execute the terminal command for setting a terminal attribute and a color

func SetColorNum

func SetColorNum(colorNum int)

Execute the terminal command for setting a given color number

func SetLineWrap

func SetLineWrap(enable bool)

func SetNoColor

func SetNoColor()

Execute the terminal command for setting no colors or other display attributes

func SetXY

func SetXY(x, y uint)

Move cursor to the given position (from 0 and up, the terminal code is from 1 and up)

func ShowCursor

func ShowCursor(enable bool)

func Up

func Up(n uint)

Move the cursor up

Types

type Canvas

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

func NewCanvas

func NewCanvas() *Canvas

func (*Canvas) At added in v0.2.1

func (c *Canvas) At(x, y uint) (rune, error)

At returns the rune at the given coordinates, or an error if out of bounds

func (*Canvas) Clear

func (c *Canvas) Clear()

Clear canvas

func (*Canvas) Draw

func (c *Canvas) Draw()

func (*Canvas) H

func (c *Canvas) H() uint

func (*Canvas) Plot

func (c *Canvas) Plot(x, y uint, s rune)

func (*Canvas) PlotC

func (c *Canvas) PlotC(x, y uint, fg string, s rune)

Plot a bright color

func (*Canvas) PlotDC

func (c *Canvas) PlotDC(x, y uint, fg string, s rune)

Plot a dark color

func (*Canvas) Redraw

func (c *Canvas) Redraw()

func (*Canvas) Resize

func (c *Canvas) Resize()

func (*Canvas) Resized

func (c *Canvas) Resized() *Canvas

Check if the canvas was resized, and adjust values accordingly. Returns a new canvas, or nil.

func (*Canvas) Size

func (c *Canvas) Size() (uint, uint)

Return the size of the current canvas

func (*Canvas) String added in v0.2.1

func (c *Canvas) String() string

Bytes returns only the characters, as a long string with a newline after each row

func (*Canvas) W

func (c *Canvas) W() uint

type Char

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

type TTY added in v0.2.1

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

func NewTTY added in v0.2.1

func NewTTY() (*TTY, error)

NewTTY opens /dev/tty in raw and cbreak mode as a term.Term

func (*TTY) ASCII added in v0.2.1

func (tty *TTY) ASCII() int

func (*TTY) Close added in v0.2.1

func (tty *TTY) Close()

Close will Restore and close the raw terminal

func (*TTY) Key added in v0.2.1

func (tty *TTY) Key() int

Return the keyCode or ascii, but ignore repeated keys

func (*TTY) KeyCode added in v0.2.1

func (tty *TTY) KeyCode() int

func (*TTY) NoBlock added in v0.2.1

func (tty *TTY) NoBlock()

NoBlock leaves "cooked" mode and enters "cbreak" mode

func (*TTY) RawMode added in v0.2.1

func (tty *TTY) RawMode()

RawMode will switch the terminal to raw mode

func (*TTY) Restore added in v0.2.1

func (tty *TTY) Restore()

Restore will restore the terminal

func (*TTY) SetTimeout added in v0.2.1

func (tty *TTY) SetTimeout(d time.Duration)

SetTimeout sets a timeout for reading a key

func (*TTY) Term added in v0.2.1

func (tty *TTY) Term() *term.Term

Term will return the underlying term.Term

Directories

Path Synopsis
cmd
key

Jump to

Keyboard shortcuts

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