avyos.dev/pkg/term

package term

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants2
Variables0
Functions14
Types2

Constants

const (
	KeyEnter     = 13 // CR (\r) - Note: ReadKey also accepts LF (10/\n) as Enter for VM TTY compatibility
	KeyEscape    = 27
	KeyBackspace = 127
	KeyTab       = 9

	// Extended keys (returned as negative values)
	KeyUp       = -1
	KeyDown     = -2
	KeyRight    = -3
	KeyLeft     = -4
	KeyHome     = -5
	KeyEnd      = -6
	KeyDel      = -7
	KeyPgUp     = -8
	KeyPgDn     = -9
	KeyShiftTab = -10
	KeyF1       = -11
	KeyF2       = -12
	KeyF3       = -13
	KeyF4       = -14
	KeyF5       = -15
	KeyF6       = -16
	KeyF7       = -17
	KeyF8       = -18
	KeyF9       = -19
	KeyF10      = -20
	KeyF11      = -21
	KeyF12      = -22

	// Mouse events (returned as negative values starting from -200)
	KeyMouseEvent = -200

	// Meta/Super key modified keys (returned as negative values starting from -300)
	KeyMetaBase = -300
)

Key constants for special keys

const (
	ClearScreen      = "\033[2J"
	ClearLine        = "\033[2K"
	ClearToEnd       = "\033[K"
	CursorHome       = "\033[H"
	CursorHide       = "\033[?25l"
	CursorShow       = "\033[?25h"
	SaveCursor       = "\033[s"
	RestoreCursor    = "\033[u"
	ScrollUp         = "\033[S"
	ScrollDown       = "\033[T"
	EnableAltScreen  = "\033[?1049h"
	DisableAltScreen = "\033[?1049l"

	// Mouse support (SGR mode for better coordinates)
	EnableMouse  = "\033[?1000h\033[?1002h\033[?1006h" // Basic + button motion + SGR
	DisableMouse = "\033[?1006l\033[?1002l\033[?1000l"
)

ANSI escape codes

Functions

func Clear()

Clear clears the screen.

func ClearCurrentLine()

ClearCurrentLine clears the current line.

func DisableRawMode() error

DisableRawMode restores the terminal to its original state.

func EnableRawMode() error

EnableRawMode puts the terminal into raw mode.

func Flush()

Flush ensures all buffered output is written to stdout. This is important when running inside a PTY to ensure immediate display.

func IsTerminal(fd int) bool

IsTerminal returns true if fd is a terminal.

func MoveCursor(row, col int)

MoveCursor moves the cursor to the specified position (1-based).

func MoveCursorBack(n int)

MoveCursorBack moves the cursor back n columns.

func MoveCursorDown(n int)

MoveCursorDown moves the cursor down n lines.

func MoveCursorForward(n int)

MoveCursorForward moves the cursor forward n columns.

func MoveCursorUp(n int)

MoveCursorUp moves the cursor up n lines.

func ReadKey() (int, error)

ReadKey reads a single key from stdin (requires raw mode).

func Size() (cols, rows int)

Size returns the terminal dimensions (columns, rows). It tries stdout, stdin, and stderr in order to find a valid terminal.

func SupportsUnicode() bool

SupportsUnicode returns true if the terminal likely supports unicode. It checks TERM and LANG environment variables.

Types

LineEditor

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

LineEditor provides simple line editing capabilities.

Functions

func NewLineEditor(prompt string) *LineEditor

NewLineEditor creates a new line editor.

Methods

func (le *LineEditor) AddHistory(line string)

AddHistory adds a line to history.

func (le *LineEditor) GetHistory() []string

GetHistory returns the command history.

func (le *LineEditor) ReadLine() (string, error)

ReadLine reads a line of input with editing support.

func (le *LineEditor) SetPrompt(prompt string)

SetPrompt sets the prompt string.

MouseEvent

type MouseEvent struct {
	Button  int // 0=left, 1=middle, 2=right, 64=wheel up, 65=wheel down
	X, Y    int // 1-based coordinates
	Release bool
	Motion  bool
	Mod     int // modifier bits: 4=shift, 8=meta, 16=ctrl
}

MouseEvent holds mouse event data

Variables

var LastMouseEvent MouseEvent

Global to store last mouse event