avyos.dev/pkg/term
package term
Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 2 |
| Variables | 0 |
| Functions | 14 |
| Types | 2 |
Constants
KeyEnter, KeyEscape, KeyBackspace, KeyTab, KeyUp, KeyDown, KeyRight, KeyLeft, KeyHome, KeyEnd, KeyDel, KeyPgUp, KeyPgDn, KeyShiftTab, KeyF1, KeyF2, KeyF3, KeyF4, KeyF5, KeyF6, KeyF7, KeyF8, KeyF9, KeyF10, KeyF11, KeyF12, KeyMouseEvent, KeyMetaBase
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
ClearScreen, ClearLine, ClearToEnd, CursorHome, CursorHide, CursorShow, SaveCursor, RestoreCursor, ScrollUp, ScrollDown, EnableAltScreen, DisableAltScreen, EnableMouse, DisableMouse
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
Clear
func Clear()Clear clears the screen.
ClearCurrentLine
func ClearCurrentLine()ClearCurrentLine clears the current line.
DisableRawMode
func DisableRawMode() errorDisableRawMode restores the terminal to its original state.
EnableRawMode
func EnableRawMode() errorEnableRawMode puts the terminal into raw mode.
Flush
func Flush()Flush ensures all buffered output is written to stdout. This is important when running inside a PTY to ensure immediate display.
IsTerminal
func IsTerminal(fd int) boolIsTerminal returns true if fd is a terminal.
MoveCursor
func MoveCursor(row, col int)MoveCursor moves the cursor to the specified position (1-based).
MoveCursorBack
func MoveCursorBack(n int)MoveCursorBack moves the cursor back n columns.
MoveCursorDown
func MoveCursorDown(n int)MoveCursorDown moves the cursor down n lines.
MoveCursorForward
func MoveCursorForward(n int)MoveCursorForward moves the cursor forward n columns.
MoveCursorUp
func MoveCursorUp(n int)MoveCursorUp moves the cursor up n lines.
ReadKey
func ReadKey() (int, error)ReadKey reads a single key from stdin (requires raw mode).
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.
SupportsUnicode
func SupportsUnicode() boolSupportsUnicode 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
NewLineEditor
func NewLineEditor(prompt string) *LineEditorNewLineEditor creates a new line editor.
Methods
AddHistory
func (le *LineEditor) AddHistory(line string)AddHistory adds a line to history.
GetHistory
func (le *LineEditor) GetHistory() []stringGetHistory returns the command history.
ReadLine
func (le *LineEditor) ReadLine() (string, error)ReadLine reads a line of input with editing support.
SetPrompt
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
LastMouseEvent
var LastMouseEvent MouseEventGlobal to store last mouse event