vt100

package module
v0.0.0-...-a09f3f8 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 9 Imported by: 2

README

vt100

VT100 and ANSI terminal emulation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black       = color.NRGBA{0x00, 0x00, 0x00, 0xff}
	Red         = color.NRGBA{0xcd, 0x00, 0x00, 0xff}
	Green       = color.NRGBA{0x00, 0xcd, 0x00, 0xff}
	Yellow      = color.NRGBA{0xcd, 0xcd, 0x00, 0xff}
	Blue        = color.NRGBA{0x00, 0x00, 0xee, 0xff}
	Magenta     = color.NRGBA{0xcd, 0x00, 0xcd, 0xff}
	Cyan        = color.NRGBA{0x00, 0xcd, 0xcd, 0xff}
	White       = color.NRGBA{0xe5, 0xe5, 0xe5, 0xff}
	BrightWhite = color.NRGBA{0xff, 0xff, 0xff, 0xff}
)

Emulator color codes.

Functions

func Backspace

func Backspace(out io.Writer) error

Backspace moves cursor one column left. Backspace does nothing if the cursor is already at the leftmost column.

func CursorBackward

func CursorBackward(out io.Writer) error

CursorBackward moves the cursor one column left. Stops at the left edge of screen.

func CursorDown

func CursorDown(out io.Writer) error

CursorDown moves cursor one line down.

func CursorForward

func CursorForward(out io.Writer) error

CursorForward moves the cursor one column right. Stops at the right edge of screen.

func CursorUp

func CursorUp(out io.Writer) error

CursorUp moves cursor one line up.

func DeleteChar

func DeleteChar(out io.Writer) error

DeleteChar deletes character from the current cursor position.

func DisplayWidth

func DisplayWidth(data string) (width, height int, err error)

DisplayWidth computes the character size width of the argument data when all emulator control codes have been removed.

func EraseLine

func EraseLine(out io.Writer) error

EraseLine clears the current line.

func EraseLineHead

func EraseLineHead(out io.Writer) error

EraseLineHead clears the current line from the beginning of the line to cursor position (inclusively).

func EraseLineTail

func EraseLineTail(out io.Writer) error

EraseLineTail clears the current line from the cursor position to the end of line (inclusively).

func EraseScreen

func EraseScreen(out io.Writer) error

EraseScreen clears screen.

func EraseScreenHead

func EraseScreenHead(out io.Writer) error

EraseScreenHead clears the screen from the beginning of the screen to cursor position (inclusively).

func EraseScreenTail

func EraseScreenTail(out io.Writer) error

EraseScreenTail clears the screen from cursor position to the end of screen (inclusively).

func HBlock

func HBlock(width int, fract float64, empty rune) string

HBlock creates a horizontal block that is width characters long. The fract argument specifies the fraction ([0...1]) of the width that is rendered with the Unicode block drawing characters, starting from the left edge. The remaining empty fraction of the block is padded with the empty rune.

func MoveTo

func MoveTo(out io.Writer, row, col int) error

MoveTo moves cursor to the specified row and column.

func ParseHexDump

func ParseHexDump(data []byte) ([]byte, error)

ParseHexDump parses data from the encoding/hex.Dump formatted output.

func ScrollDown

func ScrollDown(out io.Writer) error

ScrollDown scrolls the screen one line down.

func ScrollUp

func ScrollUp(out io.Writer) error

ScrollUp scrolls the screen one line up.

func Sparkline

func Sparkline(values []int) string

Sparkline creates a histogram chart of values. The chart is scaled to [min...max] values in the values array.

func SparklineRange

func SparklineRange(min, max int, values []int) string

SparklineRange creates a histogram chart of values. The chart is scaled to [min...max]. Values smaller than min are rendered with space (u0020) and values larger than max are rendered with 'Light Shade' (u2591).

func Trim

func Trim(data string) (lines []string, err error)

Trim removes all emulator control codes from the argument data.

Types

type Char

type Char struct {
	Code       rune
	Foreground color.NRGBA
	Background color.NRGBA
	Bold       bool
	Italic     bool
	Underline  bool
}

Char defines the column character and properties in emulator display.

func (Char) Clone

func (ch Char) Clone(code rune) Char

Clone creates a new character with the argument code. All other character attributes are copied.

type CharDisplay

type CharDisplay interface {
	// Size returns the display size.
	Size() Point
	// Clear clears the display region (inclusively).
	Clear(from, to Point)
	// DECALN fills the screen with 'E'.
	DECALN(size Point)
	// Set sets the character at the specified point.
	Set(p Point, char Char)
	// InsertChars insert count number of characters to the specified
	// point.
	InsertChars(size, p Point, count int)
	// DeleteChars delets count number of characters from the
	// specified point.
	DeleteChars(size, p Point, count int)
	// ScrollUp scrolls the screen up count lines.
	ScrollUp(top, bottom, count int)
}

CharDisplay implements terminal display.

type Display

type Display struct {
	Blank Char

	Lines [][]Char
	// contains filtered or unexported fields
}

Display implements fixed size CharDisplay.

func NewDisplay

func NewDisplay(width, height int) *Display

NewDisplay creates a display with the given dimensions.

func (*Display) Clear

func (d *Display) Clear(from, to Point)

Clear implements the CharDisplay.Clear function.

func (*Display) DECALN

func (d *Display) DECALN(size Point)

DECALN implements the CharDisplay.DECALN function.

func (*Display) DeleteChars

func (d *Display) DeleteChars(size, p Point, count int)

DeleteChars implements the CharDisplay.DeleteChars function.

func (*Display) InsertChars

func (d *Display) InsertChars(size, p Point, count int)

InsertChars implements the CharDisplay.InsertChars function.

func (*Display) Resize

func (d *Display) Resize(width, height int)

Resize resizes the display to given dimensions.

func (*Display) ScrollUp

func (d *Display) ScrollUp(top, bottom, count int)

ScrollUp implements the CharDisplay.ScrollUp function.

func (*Display) Set

func (d *Display) Set(p Point, char Char)

Set implements the CharDisplay.Set function.

func (*Display) Size

func (d *Display) Size() Point

Size implements the CharDisplay.Size function.

type Emulator

type Emulator struct {
	Size Point

	Cursor  Point
	Default Char
	// contains filtered or unexported fields
}

Emulator implements terminal emulator.

func NewEmulator

func NewEmulator(stdout, stderr io.Writer, display CharDisplay) *Emulator

NewEmulator creates a new terminal emulator.

func (*Emulator) Input

func (e *Emulator) Input(code int)

Input runs the terminal emulation with the next input code.

func (*Emulator) Reset

func (e *Emulator) Reset()

Reset resets the emulator to initial state.

func (*Emulator) Resize

func (e *Emulator) Resize(width, height int)

Resize sets emulator display area.

type Point

type Point struct {
	X int
	Y int
}

Point defines a 2D point.

func (Point) Equal

func (p Point) Equal(o Point) bool

Equal tests if the argument point is equal to this point.

func (Point) String

func (p Point) String() string

type Stringer

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

Stringer implements the CharDisplay interface to create plain-text string versions of the input.

func NewStringer

func NewStringer() *Stringer

NewStringer creates a new stringer display.

func (*Stringer) Clear

func (d *Stringer) Clear(from, to Point)

Clear implements the CharDisplay.Clear function.

func (*Stringer) DECALN

func (d *Stringer) DECALN(size Point)

DECALN implements the CharDisplay.DECALN function.

func (*Stringer) DeleteChars

func (d *Stringer) DeleteChars(size, p Point, count int)

DeleteChars implements the CharDisplay.DeleteChars function.

func (*Stringer) InsertChars

func (d *Stringer) InsertChars(size, p Point, count int)

InsertChars implements the CharDisplay.InsertChars function.

func (*Stringer) ScrollUp

func (d *Stringer) ScrollUp(top, bottom, count int)

ScrollUp implements the CharDisplay.ScrollUp function.

func (*Stringer) Set

func (d *Stringer) Set(p Point, char Char)

Set implements the CharDisplay.Set function.

func (*Stringer) Size

func (d *Stringer) Size() Point

Size implements the CharDisplay.Size function.

Directories

Path Synopsis
apps

Jump to

Keyboard shortcuts

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