vt10x

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: MIT Imports: 15 Imported by: 5

README

vt10x

Build Status GoDoc

Package vt10x is a vt10x terminal emulation backend, influenced largely by st, rxvt, xterm, and iTerm as reference. Use it for terminal muxing, a terminal emulation frontend, or wherever else you need terminal emulation.

Documentation

Overview

Package terminal is a vt10x terminal emulation backend, influenced largely by st, rxvt, xterm, and iTerm as reference. Use it for terminal muxing, a terminal emulation frontend, or wherever else you need terminal emulation.

In development, but very usable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResizePty

func ResizePty(pty *os.File, cols, rows int) error

Types

type ChangeFlag

type ChangeFlag uint32

ChangeFlag represents possible state changes of the terminal.

const (
	ChangedScreen ChangeFlag = 1 << iota
	ChangedTitle
)

Terminal changes to occur in VT.ReadState

type Color

type Color uint16

Color maps to the ANSI colors [0, 16) and the xterm colors [16, 256).

const (
	Black Color = iota
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	LightGrey
	DarkGrey
	LightRed
	LightGreen
	LightYellow
	LightBlue
	LightMagenta
	LightCyan
	White
)

ANSI color values

const (
	DefaultFG Color = 0xff80 + iota
	DefaultBG
)

Default colors are potentially distinct to allow for special behavior. For example, a transparent background. Otherwise, the simple case is to map default colors to another color.

func (Color) ANSI

func (c Color) ANSI() bool

ANSI returns true if Color is within [0, 16).

type ModeFlag

type ModeFlag uint32

ModeFlag represents various terminal mode states.

const (
	ModeWrap ModeFlag = 1 << iota
	ModeInsert
	ModeAppKeypad
	ModeAltScreen
	ModeCRLF
	ModeMouseButton
	ModeMouseMotion
	ModeReverse
	ModeKeyboardLock
	ModeHide
	ModeEcho
	ModeAppCursor
	ModeMouseSgr
	Mode8bit
	ModeBlink
	ModeFBlink
	ModeFocus
	ModeMouseX10
	ModeMouseMany
	ModeMouseMask = ModeMouseButton | ModeMouseMotion | ModeMouseX10 | ModeMouseMany
)

Terminal modes

type State

type State struct {
	DebugLogger *log.Logger
	// RecordHistory is a flag that when set to true keeps a history of all lines that are scrolled out of view
	RecordHistory bool
	// contains filtered or unexported fields
}

State represents the terminal emulation state. Use Lock/Unlock methods to synchronize data access with VT.

func NewVT10XConsole

func NewVT10XConsole(opts ...expect.ConsoleOpt) (*expect.Console, *State, error)

NewVT10XConsole returns a new expect.Console that multiplexes the Stdin/Stdout to a VT10X terminal, allowing Console to interact with an application sending ANSI escape sequences.

func (*State) Cell

func (t *State) Cell(x, y int) (ch rune, fg Color, bg Color)

Cell returns the character code, foreground color, and background color at position (x, y) relative to the top left of the terminal.

func (*State) Changed

func (t *State) Changed(change ChangeFlag) bool

Changed returns true if change has occured.

func (*State) Cursor

func (t *State) Cursor() (int, int)

Cursor returns the current position of the cursor.

func (*State) CursorVisible

func (t *State) CursorVisible() bool

CursorVisible returns the visible state of the cursor.

func (*State) GlobalCursor added in v1.2.0

func (t *State) GlobalCursor() (int, int)

GlobalCursor returns the current position including the history

func (*State) HasStringBeforeCursor added in v1.2.0

func (t *State) HasStringBeforeCursor(m string, ignoreNewlinesAndSpaces bool) bool

HasStringBeforeCursor checks whether `m` matches the string before the cursor position If ignoreNewlinesAndSpaces is set to true, newline and space characters are skipped over

func (*State) Lock

func (t *State) Lock()

Lock locks the state object's mutex.

func (*State) Mode

func (t *State) Mode(mode ModeFlag) bool

Mode tests if mode is currently set.

func (*State) Size

func (t *State) Size() (rows int, cols int)

Size returns rows and columns of state

func (*State) String

func (t *State) String() string

String returns a string representation of the terminal output

func (*State) StringBeforeCursor added in v1.2.0

func (t *State) StringBeforeCursor() string

StringBeforeCursor returns the terminal output in front of the cursor

func (*State) StringToCursorFrom added in v1.2.0

func (t *State) StringToCursorFrom(row int, col int) string

StringToCursorFrom returns the string before the cursor starting from the global position row and col

func (*State) Title

func (t *State) Title() string

Title returns the current title set via the tty.

func (*State) Unlock

func (t *State) Unlock()

Unlock resets change flags and unlocks the state object's mutex.

func (*State) UnwrappedStringBeforeCursor added in v1.2.0

func (t *State) UnwrappedStringBeforeCursor() string

UnwrappedStringBeforeCursor returns the terminal output in front of the cursor without the automatic line wrapping

func (*State) UnwrappedStringToCursorFrom added in v1.2.0

func (t *State) UnwrappedStringToCursorFrom(row int, col int) string

UnwrappedStringToCursorFrom returns the string before the cursor starting from the global position row and col without the automatic line wrapping

func (*State) WriteString added in v1.2.0

func (t *State) WriteString(s string, rows, cols int)

WriteString processes the given string and updates the state This function is usually used for testing, as it also initializes the states, so previous state modifications are lost

type VT

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

VT represents the virtual terminal emulator.

func Create

func Create(state *State, rwc io.ReadWriteCloser) (*VT, error)

Create initializes a virtual terminal emulator with the target state and io.ReadWriteCloser input.

func New added in v1.0.2

func New(state *State, in io.Reader, out io.Writer) (*VT, error)

func (*VT) Close

func (t *VT) Close() error

Close closes the io.ReadWriteCloser.

func (*VT) Parse

func (t *VT) Parse() error

Parse blocks on read on pty or io.ReadCloser, then parses sequences until buffer empties. State is locked as soon as first rune is read, and unlocked when buffer is empty. TODO: add tests for expected blocking behavior

func (*VT) Resize

func (t *VT) Resize(cols, rows int)

Resize reports new size to pty and updates state.

func (*VT) Write

func (t *VT) Write(p []byte) (int, error)

Write parses input and writes terminal changes to state.

func (*VT) WriteRune added in v1.2.0

func (t *VT) WriteRune(r rune)

WriteRune writes a single rune to the terminal

type VTStrip added in v1.0.3

type VTStrip struct {
	VT
}

func NewStrip added in v1.1.0

func NewStrip() *VTStrip

func (*VTStrip) Strip added in v1.0.3

func (t *VTStrip) Strip(in []byte) ([]byte, error)

Strip returns in with all VT10x escape sequences stripped. An error is also returned if one or more of the stripped escape sequences are invalid.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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