emu

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT, MIT Imports: 17 Imported by: 0

README

emu (formerly vt10x)

Package emu is a emu 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 emu 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

View Source
const (
	AttrReverse = 1 << iota
	AttrUnderline
	AttrBold
	AttrGfx
	AttrItalic
	AttrBlink
	AttrWrap
)

TODO(cfoust): 05/19/23 combine this with above

Variables

View Source
var (
	RGBPattern  = regexp.MustCompile(`^([\da-f]{1})\/([\da-f]{1})\/([\da-f]{1})$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$`)
	HashPattern = regexp.MustCompile(`[\da-f]`)
)

Functions

func ResizePty

func ResizePty(*os.File) error

Types

type Cell

type Cell struct {
	geom.Vec2
	Glyph
	// contains filtered or unexported fields
}

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 uint32

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 = 1<<24 + iota
	DefaultBG
	DefaultCursor
)

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 Cursor

type Cursor struct {
	Attr  Glyph
	X, Y  int
	State uint8
	Style CursorStyle
}

type CursorStyle

type CursorStyle int
const (
	CursorStyleBlock CursorStyle = iota
	CursorStyleSteadyBlock
	CursorStyleUnderline
	CursorStyleBlinkUnderline
	CursorStyleBar
	CursorStyleBlinkBar
)

type Glyph

type Glyph struct {
	Char   rune
	Mode   int16
	FG, BG Color
}

func EmptyGlyph

func EmptyGlyph() Glyph

type Line

type Line []Glyph

func (Line) String

func (l Line) String() (str string)

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 {
	deadlock.RWMutex
	DebugLogger *log.Logger
	// contains filtered or unexported fields
}

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

func (*State) Cell

func (t *State) Cell(x, y int) Glyph

Cell returns the glyph containing the character code, foreground color, and background color at position (x, y) relative to the top left of the terminal. TODO(cfoust): 08/24/23 move this to row, col

func (*State) Changed

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

Changed returns true if change has occured.

func (*State) CsiDispatch

func (t *State) CsiDispatch(params []int64, intermediates []byte, ignore bool, r rune)

func (*State) Cursor

func (t *State) Cursor() Cursor

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) EscDispatch

func (t *State) EscDispatch(intermediates []byte, ignore bool, b byte)

func (*State) Execute

func (t *State) Execute(b byte)

func (*State) History

func (t *State) History() []Line

func (*State) Hook

func (t *State) Hook(params []int64, intermediates []byte, ignore bool, r rune)

func (*State) LastCell

func (t *State) LastCell() (cell Cell, changed bool)

func (*State) Mode

func (t *State) Mode() ModeFlag

Mode returns the current terminal mode.

func (*State) OscDispatch

func (t *State) OscDispatch(params [][]byte, bellTerminated bool)

func (*State) Print

func (t *State) Print(c rune)

func (*State) Put

func (t *State) Put(b byte)

func (*State) Screen

func (t *State) Screen() []Line

func (*State) Size

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

func (*State) String

func (t *State) String() string

func (*State) Title

func (t *State) Title() string

Title returns the current title set via the tty.

func (*State) Unhook

func (t *State) Unhook()

type Terminal

type Terminal interface {
	// View displays the virtual terminal.
	View

	// Write parses input and writes terminal changes to state.
	io.Writer
}

Terminal represents the virtual terminal emulator.

func New

func New(opts ...TerminalOption) Terminal

New returns a new virtual terminal emulator.

type TerminalInfo

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

type TerminalOption

type TerminalOption func(*TerminalInfo)

func WithSize

func WithSize(size geom.Vec2) TerminalOption

func WithWriter

func WithWriter(w io.Writer) TerminalOption

type View

type View interface {
	// String dumps the virtual terminal contents.
	fmt.Stringer

	// Size returns the size of the virtual terminal.
	Size() (cols, rows int)

	// Resize changes the size of the virtual terminal.
	Resize(cols, rows int)

	// Mode returns the current terminal mode.
	Mode() ModeFlag

	// Title represents the title of the console window.
	Title() string

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

	// Cursor returns the current position of the cursor.
	Cursor() Cursor

	// CursorVisible returns the visible state of the cursor.
	CursorVisible() bool

	// Screen gets all of the lines on the screen.
	Screen() []Line

	// History returns the scrollback buffer.
	History() []Line

	LastCell() (cell Cell, changed bool)
}

View represents the view of the virtual terminal emulator.

Jump to

Keyboard shortcuts

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