Documentation
¶
Index ¶
- Constants
- func Clear()
- func ClearCurrentLine()
- func DisableRawMode() error
- func EnableRawMode() error
- func Flush()
- func IsTerminal(fd int) bool
- func MoveCursor(row, col int)
- func MoveCursorBack(n int)
- func MoveCursorDown(n int)
- func MoveCursorForward(n int)
- func MoveCursorUp(n int)
- func ReadKey() (int, error)
- func Size() (cols, rows int)
- func SupportsUnicode() bool
- type LineEditor
- type MouseEvent
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
Variables ¶
This section is empty.
Functions ¶
func DisableRawMode ¶
func DisableRawMode() error
DisableRawMode restores the terminal to its original state.
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 MoveCursor ¶
func MoveCursor(row, col int)
MoveCursor moves the cursor to the specified position (1-based).
func MoveCursorForward ¶
func MoveCursorForward(n int)
MoveCursorForward moves the cursor forward n columns.
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