term

package
v0.0.0-...-ba0b20d Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

Variables

This section is empty.

Functions

func Clear

func Clear()

Clear clears the screen.

func ClearCurrentLine

func ClearCurrentLine()

ClearCurrentLine clears the current line.

func DisableRawMode

func DisableRawMode() error

DisableRawMode restores the terminal to its original state.

func EnableRawMode

func EnableRawMode() error

EnableRawMode puts the terminal into raw mode.

func Flush

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

func IsTerminal(fd int) bool

IsTerminal returns true if fd is a terminal.

func MoveCursor

func MoveCursor(row, col int)

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

func MoveCursorBack

func MoveCursorBack(n int)

MoveCursorBack moves the cursor back n columns.

func MoveCursorDown

func MoveCursorDown(n int)

MoveCursorDown moves the cursor down n lines.

func MoveCursorForward

func MoveCursorForward(n int)

MoveCursorForward moves the cursor forward n columns.

func MoveCursorUp

func MoveCursorUp(n int)

MoveCursorUp moves the cursor up n lines.

func ReadKey

func ReadKey() (int, error)

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

func Size

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

func SupportsUnicode() bool

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

Types

type LineEditor

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

LineEditor provides simple line editing capabilities.

func NewLineEditor

func NewLineEditor(prompt string) *LineEditor

NewLineEditor creates a new line editor.

func (*LineEditor) AddHistory

func (le *LineEditor) AddHistory(line string)

AddHistory adds a line to history.

func (*LineEditor) GetHistory

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

GetHistory returns the command history.

func (*LineEditor) ReadLine

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

ReadLine reads a line of input with editing support.

func (*LineEditor) SetPrompt

func (le *LineEditor) SetPrompt(prompt string)

SetPrompt sets the prompt string.

type 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

var LastMouseEvent MouseEvent

Global to store last mouse event

Jump to

Keyboard shortcuts

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