mterm

package module
v0.0.4-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: MIT Imports: 10 Imported by: 0

README

mterm

WIP: mterm implements a virtual terminal

Usage

package main

import "github.com/stdiopt/mterm"


func main() {
    t := mterm.New(24,80)
    fmt.Fprintf(t, "\033[1;33mHello world\033[0m", "World")

    // renders the full 24x80 cells in Ansi
    output := t.GetScreenAsAnsi()

    os.Stdout.Write(output)
}

Documentation

Index

Constants

View Source
const (
	Color16  = 1
	Color256 = 2
	Color16M = 3
)
View Source
const (
	FlagBold uint8 = 1 << iota
	FlagDim
	FlagItalic
	FlagUnderline
	FlagBlink
	FlagInverse
	FlagInvisible
	FlagStrike
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Char rune

	SGRState
	// contains filtered or unexported fields
}

Cell is a single cell in the terminal

type Color

type Color [3]byte

type CursorStyle

type CursorStyle int
const (
	CursorBlinkingBlock CursorStyle = iota
	CursorDefault
	CursorSteadyBlock
	CursorBlinkingUnderline
	CursorSteadyUnderline
	CursorBlinkingBar
	CursorSteadyBar
)

type EscapeError

type EscapeError struct {
	Err    error
	Offset int
}

func (EscapeError) Error

func (e EscapeError) Error() string

type Grid

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

func (*Grid) Resize

func (g *Grid) Resize(rows, cols int)

Resize regular resize without reflow, it will chomp any extra lines/columns

func (*Grid) ResizeAndReflow

func (g *Grid) ResizeAndReflow(rows, cols int)

ResizeAndReflow resize the grid and reflow based on newline markers

func (*Grid) Size

func (g *Grid) Size() (rows, cols int)

type SGRState

type SGRState struct {
	FG        Color
	BG        Color
	UL        Color // underline color
	ColorType uint8 // 0b00uubbff (u underline, b BG, f FG color types)
	Flags     uint8
}

func (*SGRState) Set

func (s *SGRState) Set(p ...int) error

Set the Set based on CSI parameters

type Terminal

type Terminal struct {
	Title   string
	TabSize int
	// contains filtered or unexported fields
}

Terminal is an in memory terminal emulator

func New

func New(rows, cols int) *Terminal

New returns a new terminal with the given rows and cols

func (*Terminal) Cells

func (t *Terminal) Cells() []Cell

Cells returns a copy of the underlying screen cells

func (*Terminal) Clear

func (t *Terminal) Clear()

Clear clears the terminal moving cursor to 0,0

func (*Terminal) CursorPos

func (t *Terminal) CursorPos() (int, int)

GetCursorPos returns the current cursor position in lines, cols

func (*Terminal) CursorStyle

func (t *Terminal) CursorStyle() CursorStyle

func (*Terminal) CursorVisible

func (t *Terminal) CursorVisible() bool

func (*Terminal) DBG

func (t *Terminal) DBG() []byte

DBG Similar to GetScreenAsAnsi but with a cursor

func (*Terminal) DBGStateFn

func (t *Terminal) DBGStateFn() string

DBGStateFn returns the state func name

func (*Terminal) FullSize

func (t *Terminal) FullSize() (rows, cols int)

FullSize returns the full size of the terminal, including scrollback

func (*Terminal) GetScreenAsAnsi

func (t *Terminal) GetScreenAsAnsi() []byte

func (*Terminal) Put

func (t *Terminal) Put(r rune) error

Put processes a single rune in the terminal

func (*Terminal) Resize

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

func (*Terminal) ScreenView

func (t *Terminal) ScreenView(buf []Cell) []Cell

ScreenView returns a clone of the current screen view if the buf is too small it will alocate a new one

func (*Terminal) Size

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

func (*Terminal) Updates

func (t *Terminal) Updates() int

Updates returns a sequence number that is incremented every time the screen cells are updated

func (*Terminal) Write

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

Write implements io.Writer and writes the given bytes to the terminal

Jump to

Keyboard shortcuts

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