Documentation
¶
Index ¶
- Constants
- func CaptureKeyboardEvents() (chan KeyEvent, chan os.Signal)
- func CheckPrimitive(s any) (res byte)
- func GetB(v any) (bool, error)
- func GetF32(v any) (float32, error)
- func GetF64(v any) (float64, error)
- func GetI(v any) (int, error)
- func GetI16(v any) (int16, error)
- func GetI32(v any) (int32, error)
- func GetI64(v any) (int64, error)
- func GetI8(v any) (int8, error)
- func GetS(v any) (string, error)
- func GetV(v any) (string, error)
- func GetVP(v any) (string, error)
- func RenderMenu(list []string, selectedIndex int, prevIndex int)
- func RenderTable(list [][]any, selectedIndex int) error
- func SelectString(list []string) (string, error)
- func SelectTableRow(list [][]any) ([]any, error)
- type CursorPosition
- type Editor
- func (e *Editor) Down()
- func (e *Editor) Edit() string
- func (e *Editor) GetCurrentLine() string
- func (e *Editor) GetCurrentLineLength() int
- func (e *Editor) GetLineMaxX() int
- func (e *Editor) GetLineVisibleLength() int
- func (e *Editor) GetLineVisibleXPosition() int
- func (e *Editor) GetTextMaxY() int
- func (e *Editor) GoToLineHead()
- func (e *Editor) IsDocumentHead() bool
- func (e *Editor) IsNotOnLastLine() bool
- func (e *Editor) IsOnBlankLine() bool
- func (e *Editor) IsOnLineEnd() bool
- func (e *Editor) IsOnLineHead() bool
- func (e *Editor) IsOnUtf8Boundary() bool
- func (e *Editor) Left()
- func (e *Editor) PutBackspace()
- func (e *Editor) PutDelete()
- func (e *Editor) PutEnter()
- func (e *Editor) PutS(key []byte)
- func (e *Editor) Reposition()
- func (e *Editor) Right()
- func (e *Editor) Up()
- type KeyEvent
- type Selector
Constants ¶
const ( ClearScreen = "\x1b[2J" // Clear entire screen use with print functions ClearScreenFromCursor = "\x1b[J" // Clear all character after the cursor in the current line ClearLine = "\x1b[2K" // Clear current line with print functions ClearLineFromCursor = "\x1b[K" // Clear all character after the cursor in the current line ResetCursor = "\x1b[H" // Move cursor to top-left cursor position CursorUp = "\x1b[1A" // Move cursor up one line CursorDown = "\x1b[1B" // Move cursor down one line CursorRight = "\x1b[1C" // Move cursor right one character CursorLeft = "\x1b[1D" // Move cursor left one character HideCursor = "\x1b[?25l" // Hide cursor with print functions ShowCursor = "\x1b[?25h" // Show cursor with print functions MoveTo = "\x1b[%d;%dH" // Move cursor to position with fmt.Printf BS = 0x08 ENTER = 0x0a ESC = 0x1b DEL = 0x7f CmdLeft = 0x37 CmdRight = 0x36 UP = 0x1b5b41 DOWN = 0x1b5b42 RIGHT = 0x1b5b43 LEFT = 0x1b5b44 END = 0x1b5b46 HOME = 0x1b5b48 PAGEUP = 0x1b357e PAGEDOWN = 0x1b367e CtrlA = 0x01 CtrlB = 0x01 CtrlC = 0x03 CtrlD = 0x04 CtrlE = 0x05 CtrlF = 0x06 CtrlG = 0x07 CtrlH = 0x08 CtrlJ = 0x0a CtrlK = 0x0b CtrlN = 0x0e CtrlO = 0x0f CtrlP = 0x10 CtrlS = 0x13 CtrlU = 0x15 CtrlX = 0x18 CtrlY = 0x19 CtrlZ = 0x1a NonUtf8UpperBits = 0x80 )
Terminal control escape sequences
Variables ¶
This section is empty.
Functions ¶
func CaptureKeyboardEvents ¶
CaptureKeyboardEvents starts capturing keyboard events in a background goroutine. Returns a channel that delivers KeyEvent structs. The channel should be properly handled and the goroutine will exit when the channel is closed.
func CheckPrimitive ¶ added in v0.1.3
func GetB ¶
GetB extracts a bool value from an any type. Returns an error if the value cannot be converted to a bool.
func GetF32 ¶
GetF32 extracts an int value from an any type. Returns an error if the value cannot be converted to an int32.
func GetF64 ¶
GetF64 extracts an int value from an any type. Returns an error if the value cannot be converted to an int64.
func GetI ¶
GetI extracts an int value from an any type. Returns an error if the value cannot be converted to an int.
func GetI16 ¶
GetI16 extracts an int value from an any type. Returns an error if the value cannot be converted to an int16.
func GetI32 ¶
GetI32 extracts an int value from an any type. Returns an error if the value cannot be converted to an int32.
func GetI64 ¶
GetI64 extracts an int value from an any type. Returns an error if the value cannot be converted to an int64.
func GetI8 ¶
GetI8 extracts an int value from an any type. Returns an error if the value cannot be converted to an int8.
func GetS ¶
GetS extracts a string value from an any type. Returns an error if the value cannot be converted to a string.
func GetV ¶
GetV is a generic extract function for interface values. Returns the value as string if it can be converted, or an error otherwise.
func GetVP ¶ added in v0.1.3
GetVP is a generic extract function for interface values for pointer types. Returns the value as string if it can be converted, or an error otherwise.
func RenderMenu ¶
RenderMenu draws the menu with the current selection (internal use)
func RenderTable ¶
RenderTable draws the table with a row cursor. (internal use)
func SelectString ¶
SelectString presents a list of strings for selection and returns the selected string. It displays an interactive cursor that can be moved with arrow keys. Returns the selected string or an error if: - the provided slice is empty - the keyboard event channel closes - the user quits (q or Ctrl+C)
func SelectTableRow ¶
SelectTableRow presents a table of mixed data types for selection and returns the selected row. Each row can contain different data types (string, int, float, bool, etc.). Returns the selected row as []any or an error if: - the provided slice is empty - the keyboard event channel closes - the user quits (q or Ctrl+C)
Types ¶
type CursorPosition ¶ added in v0.1.3
type CursorPosition struct {
X, Y int
}
CursorPosition represents the X,Y coordinates of the cursor in the editor
type Editor ¶ added in v0.1.3
Editor provides a simple terminal-based text editor
func NewEditor ¶ added in v0.1.3
func NewEditor() *Editor
NewEditor creates a new Editor instance with default settings
func (*Editor) Down ¶ added in v0.1.3
func (e *Editor) Down()
Down moves the cursor down one line, adjusting X position if needed
func (*Editor) Edit ¶ added in v0.1.3
Edit starts the editing session and returns the edited text when complete (with Ctrl-D)
func (*Editor) GetCurrentLine ¶ added in v0.1.3
GetCurrentLine returns the text of the current line
func (*Editor) GetCurrentLineLength ¶ added in v0.1.3
GetCurrentLineLength returns the length of the current line in bytes
func (*Editor) GetLineMaxX ¶ added in v0.1.3
GetLineMaxX returns the maximum valid X position for the current line
func (*Editor) GetLineVisibleLength ¶ added in v0.1.3
GetLineVisibleLength returns the visible line length on the console. It can be used to calculate the real width for the line, which consists of multibyte (and double-width) characters.
func (*Editor) GetLineVisibleXPosition ¶ added in v0.1.3
GetLineVisibleXPosition returns the visible cursor position on the console. It can be used to calculate the real cursor position for the line, which consists of multibyte (and double-width) characters.
func (*Editor) GetTextMaxY ¶ added in v0.1.3
GetTextMaxY returns the maximum valid Y position (last line index)
func (*Editor) GoToLineHead ¶ added in v0.1.3
func (e *Editor) GoToLineHead()
GoToLineHead moves the cursor to the beginning of the current line
func (*Editor) IsDocumentHead ¶ added in v0.1.3
IsDocumentHead returns true if the cursor at the beginning of the document
func (*Editor) IsNotOnLastLine ¶ added in v0.1.3
IsNotOnLastLine returns true if the cursor is not on the last line
func (*Editor) IsOnBlankLine ¶ added in v0.1.3
IsOnBlankLine returns true if the current line is empty
func (*Editor) IsOnLineEnd ¶ added in v0.1.3
IsOnLineEnd returns true if the cursor is at the end of a line
func (*Editor) IsOnLineHead ¶ added in v0.1.3
IsOnLineHead returns true if the cursor is at the beginning of a line
func (*Editor) IsOnUtf8Boundary ¶ added in v0.1.3
IsOnUtf8Boundary returns true if the cursor is on a valid UTF-8 character boundary
func (*Editor) Left ¶ added in v0.1.3
func (e *Editor) Left()
Left moves the cursor one position to the right, respecting UTF-8 boundaries
func (*Editor) PutBackspace ¶ added in v0.1.3
func (e *Editor) PutBackspace()
PutBackspace removes the previous character at the current cursor position. If it is performed at the beginning of a line, two lines are concatenated to one.
func (*Editor) PutDelete ¶ added in v0.1.3
func (e *Editor) PutDelete()
PutDelete removes the character at the current cursor position
func (*Editor) PutEnter ¶ added in v0.1.3
func (e *Editor) PutEnter()
PutEnter inserts a new line at the current cursor position
func (*Editor) Reposition ¶ added in v0.1.3
func (e *Editor) Reposition()
Reposition moves the terminal cursor to match the editor's cursor position
type KeyEvent ¶
type KeyEvent struct {
Key rune // The character pressed
Code int // Numeric key code
Ctrl bool // Whether Ctrl was pressed
Alt bool // Whether Alt was pressed
Shift bool // Whether Shift was pressed
Special int // Special key name (UP, DOWN, ENTER, etc.)
IsRuneStart bool // Whether the character is UTF-8 multibyte character or not
Runes []byte // Raw key bytes
}
KeyEvent represents a keyboard input event with information about special keys and modifiers.
type Selector ¶ added in v0.1.3
Selector represents a selectable dataset with an optional header
func NewSelectorFrom ¶ added in v0.1.3
NewSelectorFrom creates a new Selector from a slice of any type