Documentation
¶
Index ¶
- Constants
- Variables
- func Bold()
- func ClearLine()
- func CloseProps()
- func ColorBgBlack()
- func ColorBgBlue()
- func ColorBgCyan()
- func ColorBgGreen()
- func ColorBgMagenta()
- func ColorBgRed()
- func ColorBgWhite()
- func ColorBgYellow()
- func ColorBlack()
- func ColorBlue()
- func ColorBrBlack()
- func ColorBrBlue()
- func ColorBrCyan()
- func ColorBrGreen()
- func ColorBrMagenta()
- func ColorBrRed()
- func ColorBrWhite()
- func ColorBrYellow()
- func ColorCyan()
- func ColorGreen()
- func ColorMagenta()
- func ColorRed()
- func ColorWhite()
- func ColorYellow()
- func CurDown(n int)
- func CurLeft(n int)
- func CurRight(n int)
- func CurUp(n int)
- func DisplayBlock(bloc env.Block, idx *env.Idxs) (env.Object, bool)
- func DisplayDateInput(initialDate string, right int) (env.Object, bool)
- func DisplayDict(bloc env.Dict, idx *env.Idxs) (env.Object, bool)
- func DisplayError(e *env.Error, idx *env.Idxs) (env.Object, bool)
- func DisplayInputField(right int, mlen int) (env.Object, bool)
- func DisplayIntInput(initialNum string, right int) (env.Object, bool)
- func DisplayMarkdown(items []env.Object, idx *env.Idxs) (env.Object, bool)
- func DisplayMarkdownItems(items interface{}, idx *env.Idxs) (env.Object, bool)
- func DisplaySelection(bloc env.Block, idx *env.Idxs, right int) (env.Object, bool)
- func DisplayTable(bloc env.Table, idx *env.Idxs) (env.Object, bool)
- func DisplayTableCustom(bloc env.Table, myfn func(row env.Object, iscurr env.Integer), idx *env.Idxs) (env.Object, bool)
- func DisplayTableRow(bloc env.TableRow, idx *env.Idxs) (env.Object, bool)
- func DisplayTextArea(width, height int, text string) (env.Object, bool)
- func FindWordInfo(ps *env.ProgramState, word string) string
- func GetChar() (ascii int, keyCode int, err error)
- func GetChar2() (letter string, ascii int, keyCode int, err error)
- func GetCurrentColumn() (int, error)
- func GetCurrentRow() (int, error)
- func GetTerminalColumns() int
- func GetTerminalHeight() int
- func HideCur()
- func IsNearBottomOfTerminal(threshold int) (bool, error)
- func Italic()
- func ResetBold()
- func RestoreCurPos()
- func RunWidget(w Widget) (env.Object, bool)
- func RyeHighlight(s string, inStrX bool, inStrX2 bool, columns int) (string, bool, bool)
- func SaveCurPos()
- func SetTerminalRestoreFunc(restoreFunc func() error)
- func ShowCur()
- func StrBold() string
- func StrCloseProps() string
- func StrColorBgBlack() string
- func StrColorBgBlue() string
- func StrColorBgCyan() string
- func StrColorBgGreen() string
- func StrColorBgMagenta() string
- func StrColorBgRed() string
- func StrColorBgWhite() string
- func StrColorBgYellow() string
- func StrColorBlack() string
- func StrColorBlue() string
- func StrColorBrBlack() string
- func StrColorBrBlue() string
- func StrColorBrCyan() string
- func StrColorBrGreen() string
- func StrColorBrMagenta() string
- func StrColorBrRed() string
- func StrColorBrWhite() string
- func StrColorBrYellow() string
- func StrColorCyan() string
- func StrColorGreen() string
- func StrColorMagenta() string
- func StrColorRed() string
- func StrColorWhite() string
- func StrColorYellow() string
- func StrResetBold() string
- func StrUnderline() string
- func SuspendProcess() error
- func Underline()
- type BaseWidget
- type Completer
- type CursorPosition
- type DateWidget
- type HighlightedStringBuilder
- type HistoryItem
- type ImprovedMLState
- type InputWidget
- type KeyEvent
- type MLState
- func (s *MLState) AppendHistory(item string)
- func (s *MLState) ClearHistory()
- func (s *MLState) DeleteHistoryAt(idx int)
- func (s *MLState) GetHistoryLast(n int) []string
- func (s *MLState) GetKeyChan() <-chan KeyEvent
- func (s *MLState) MicroPrompt(prompt string, text string, pos int, ctx1 context.Context) (string, error)
- func (s *MLState) ReadHistory(r io.Reader) (num int, err error)
- func (s *MLState) SetColumns(cols int) bool
- func (s *MLState) SetCompleter(f Completer)
- func (s *MLState) SetDisplayValueFunc(fn func(*env.ProgramState, env.Object, bool) (env.Object, string))
- func (s *MLState) SetOnValueSelectedFunc(fn func(env.Object))
- func (s *MLState) SetProgramState(ps *env.ProgramState)
- func (s *MLState) SetPromptFunc(fn func() string)
- func (s *MLState) SetWasmMode(enabled bool)
- func (s *MLState) WriteHistory(w io.Writer) (num int, err error)
- type PaginatedSelectWidget
- type SelectWidget
- type TerminalSize
- type TerminalState
- type TextAreaWidget
- type Theme
- type Widget
- type WidgetKey
- type WordCompleter
Constants ¶
const ( // Default terminal dimensions DefaultColumns = 80 DefaultRows = 24 // Minimum terminal width for proper operation MinTerminalWidth = 6 )
Constants for key codes and terminal behavior
const ( KeyCtrlC = 3 KeyCtrlD = 4 KeyEnter = 13 KeyEsc = 27 KeyBackspace = 127 KeyCodeUp = 38 KeyCodeDown = 40 KeyCodeLeft = 37 KeyCodeRight = 39 )
Key constants for better readability
const HistoryLimit = 1000
HistoryLimit is the maximum number of entries saved in the scrollback history.
Variables ¶
var DefaultTheme = Theme{ Selected: func() { ColorBrGreen() Bold() }, Normal: func() { CloseProps() }, Header: func() { Bold() }, Cursor: "» ", CursorNormal: " ", }
DefaultTheme is the default color theme
Functions ¶
func CloseProps ¶
func CloseProps()
func ColorBgBlue ¶ added in v0.0.31
func ColorBgBlue()
func ColorBgCyan ¶ added in v0.0.31
func ColorBgCyan()
func ColorBgGreen ¶ added in v0.0.31
func ColorBgGreen()
func ColorBgMagenta ¶ added in v0.0.31
func ColorBgMagenta()
func ColorBgRed ¶ added in v0.0.31
func ColorBgRed()
func ColorBgWhite ¶ added in v0.0.31
func ColorBgWhite()
func ColorBgYellow ¶ added in v0.0.31
func ColorBgYellow()
func ColorBrBlue ¶ added in v0.0.31
func ColorBrBlue()
func ColorBrCyan ¶ added in v0.0.31
func ColorBrCyan()
func ColorBrGreen ¶
func ColorBrGreen()
func ColorBrMagenta ¶ added in v0.0.31
func ColorBrMagenta()
func ColorBrRed ¶ added in v0.0.31
func ColorBrRed()
func ColorBrWhite ¶ added in v0.0.31
func ColorBrWhite()
func ColorBrYellow ¶ added in v0.0.31
func ColorBrYellow()
func ColorGreen ¶
func ColorGreen()
func ColorMagenta ¶
func ColorMagenta()
func ColorWhite ¶
func ColorWhite()
func ColorYellow ¶ added in v0.0.31
func ColorYellow()
func DisplayDateInput ¶ added in v0.0.92
DisplayDateInput displays an interactive date input in format YYYY-MM-DD Allows arrow keys to navigate between fields and increment/decrement values Returns a string in format "YYYY-MM-DD"
func DisplayError ¶ added in v0.2.52
DisplayError renders an env.Error in a user-friendly, interactive view.
Layout (each "field" is a navigable row):
┌─ Error ──────────────────────────────┐ │ Type connection-error │ ← Kind (optional) │ Code 503 │ ← Status (optional, shown only if != 0) │ Message server unavailable │ ← Message (optional) │ ───────────────────────────────── │ ← separator before Values │ url https://... │ ← Values entries (optional) │ ─ caused by ───────────────────── │ ← separator before parent │ Type http-error │ ← parent fields, indented │ Code 0 │ │ Message connection refused │ └──────────────────────────────────────┘
Arrow keys navigate rows; Enter selects the value of the current row; Esc / Ctrl+C returns the original error unchanged.
func DisplayIntInput ¶ added in v0.2.12
DisplayIntInput displays an interactive date input in format YYYY-MM-DD Allows arrow keys to navigate between fields and increment/decrement values Returns a string in format "YYYY-MM-DD"
func DisplayMarkdown ¶ added in v0.2.11
DisplayMarkdown provides an interactive display for markdown content with proper terminal-aware rendering
func DisplayMarkdownItems ¶ added in v0.2.11
DisplayMarkdownItems displays markdown items with proper block selection and type+content return
func DisplaySelection ¶
func DisplayTableCustom ¶ added in v0.0.31
func DisplayTableCustom(bloc env.Table, myfn func(row env.Object, iscurr env.Integer), idx *env.Idxs) (env.Object, bool)
ideation: .display\custom fn { x } { -> 'subject .elipsis 20 .red .prn , spacer 2 , -> 'score .align-right 10 .print }
func DisplayTableRow ¶ added in v0.0.33
func DisplayTextArea ¶ added in v0.0.97
DisplayTextArea displays an interactive multiline text input width is max characters per line, height is number of lines text is optional initial text that will be split into lines Returns the text as a string with newlines between lines
func FindWordInfo ¶ added in v0.2.11
func FindWordInfo(ps *env.ProgramState, word string) string
FindWordInfo searches for documentation about a word in RYE_HOME/info/*.info.rye files
func GetChar ¶
GetChar reads a character from the Unix terminal and returns ASCII code, key code, and error
func GetCurrentColumn ¶ added in v0.2.11
GetCurrentColumn returns just the current column position
func GetCurrentRow ¶ added in v0.2.11
GetCurrentRow returns just the current row position
func GetTerminalColumns ¶ added in v0.0.26
func GetTerminalColumns() int
func GetTerminalHeight ¶ added in v0.2.11
func GetTerminalHeight() int
GetTerminalHeight returns just the terminal height in rows
func IsNearBottomOfTerminal ¶ added in v0.2.11
IsNearBottomOfTerminal checks if cursor is near the bottom of the terminal Returns true if within 'threshold' lines of the bottom
func RestoreCurPos ¶
func RestoreCurPos()
func RyeHighlight ¶ added in v0.0.26
func SaveCurPos ¶
func SaveCurPos()
func SetTerminalRestoreFunc ¶ added in v0.0.82
func SetTerminalRestoreFunc(restoreFunc func() error)
SetTerminalRestoreFunc allows external packages to register a function that will be called to restore terminal state after suspension
func StrCloseProps ¶ added in v0.0.31
func StrCloseProps() string
func StrColorBgBlue ¶ added in v0.0.90
func StrColorBgBlue() string
func StrColorBgCyan ¶ added in v0.0.90
func StrColorBgCyan() string
func StrColorBgGreen ¶ added in v0.0.90
func StrColorBgGreen() string
func StrColorBgMagenta ¶ added in v0.0.90
func StrColorBgMagenta() string
func StrColorBgRed ¶ added in v0.0.90
func StrColorBgRed() string
func StrColorBgWhite ¶ added in v0.0.90
func StrColorBgWhite() string
func StrColorBgYellow ¶ added in v0.0.90
func StrColorBgYellow() string
func StrColorBlue ¶ added in v0.0.31
func StrColorBlue() string
func StrColorBrBlack ¶ added in v0.0.31
func StrColorBrBlack() string
func StrColorBrBlue ¶ added in v0.0.90
func StrColorBrBlue() string
func StrColorBrCyan ¶ added in v0.0.90
func StrColorBrCyan() string
func StrColorBrGreen ¶ added in v0.0.90
func StrColorBrGreen() string
func StrColorBrMagenta ¶ added in v0.0.90
func StrColorBrMagenta() string
func StrColorBrRed ¶ added in v0.0.90
func StrColorBrRed() string
func StrColorBrWhite ¶ added in v0.0.90
func StrColorBrWhite() string
func StrColorBrYellow ¶ added in v0.0.90
func StrColorBrYellow() string
func StrColorCyan ¶ added in v0.0.31
func StrColorCyan() string
func StrColorGreen ¶ added in v0.0.31
func StrColorGreen() string
func StrColorMagenta ¶ added in v0.0.31
func StrColorMagenta() string
func StrColorRed ¶ added in v0.0.31
func StrColorRed() string
func StrColorWhite ¶ added in v0.0.31
func StrColorWhite() string
func StrColorYellow ¶ added in v0.0.31
func StrColorYellow() string
func StrResetBold ¶ added in v0.0.90
func StrResetBold() string
func StrUnderline ¶ added in v0.0.90
func StrUnderline() string
func SuspendProcess ¶ added in v0.0.82
func SuspendProcess() error
SuspendProcess implements Unix-style process suspension using SIGTSTP signal It properly handles terminal state restoration after resume to fix input issues
Types ¶
type BaseWidget ¶ added in v0.2.50
type BaseWidget struct {
Theme Theme
Idx *env.Idxs
Mode int // 0 = human (Print), 1 = dev (Inspect)
MoveUp int // Lines to move up before redraw
}
BaseWidget provides common functionality for all widgets
func NewBaseWidget ¶ added in v0.2.50
func NewBaseWidget(idx *env.Idxs) BaseWidget
NewBaseWidget creates a new BaseWidget with default theme
func (*BaseWidget) FormatValue ¶ added in v0.2.50
func (b *BaseWidget) FormatValue(obj env.Object) string
FormatValue formats an object based on the current mode
func (*BaseWidget) PrepareRedraw ¶ added in v0.2.50
func (b *BaseWidget) PrepareRedraw()
PrepareRedraw moves cursor up and saves position for redraw
func (*BaseWidget) ToggleMode ¶ added in v0.2.50
func (b *BaseWidget) ToggleMode()
ToggleMode switches between human and dev display modes
type Completer ¶ added in v0.0.26
Completer takes the currently edited line content at the left of the cursor to the completer which may return {"Hello, world", "Hello, Word"} to have "Hello, world!!!".
type CursorPosition ¶ added in v0.2.11
CursorPosition represents the current cursor position
func QueryCursorPosition ¶ added in v0.2.11
func QueryCursorPosition() (CursorPosition, error)
QueryCursorPosition queries the terminal for the current cursor position using ANSI escape sequences Returns the current row and column (1-based indexing as returned by terminal)
type DateWidget ¶ added in v0.2.50
type DateWidget struct {
BaseWidget
Year int
Month int
Day int
Field int // 0=year, 1=month, 2=day
}
DateWidget handles date input with field navigation
func NewDateWidget ¶ added in v0.2.50
func NewDateWidget(initialDate string, idx *env.Idxs) *DateWidget
NewDateWidget creates a new date widget with optional initial date
func (*DateWidget) GetHeight ¶ added in v0.2.50
func (w *DateWidget) GetHeight() int
func (*DateWidget) GetValue ¶ added in v0.2.50
func (w *DateWidget) GetValue() env.Object
func (*DateWidget) HandleKey ¶ added in v0.2.50
func (w *DateWidget) HandleKey(key WidgetKey) (done bool, canceled bool)
func (*DateWidget) Render ¶ added in v0.2.50
func (w *DateWidget) Render()
type HighlightedStringBuilder ¶ added in v0.0.26
type HighlightedStringBuilder struct {
// contains filtered or unexported fields
}
func (*HighlightedStringBuilder) ColoredString ¶ added in v0.0.26
func (h *HighlightedStringBuilder) ColoredString(inStr bool) string
func (*HighlightedStringBuilder) Reset ¶ added in v0.0.26
func (h *HighlightedStringBuilder) Reset()
func (*HighlightedStringBuilder) String ¶ added in v0.0.26
func (h *HighlightedStringBuilder) String() string
func (*HighlightedStringBuilder) WriteRune ¶ added in v0.0.26
func (h *HighlightedStringBuilder) WriteRune(c rune)
type HistoryItem ¶ added in v0.2.10
type HistoryItem struct {
Content string // The history line content
OriginalIdx int // Index in the original s.history slice
}
HistoryItem represents a history entry with its original index
type ImprovedMLState ¶ added in v0.2.50
type ImprovedMLState struct {
*MLState
// contains filtered or unexported fields
}
ImprovedMLState extends MLState with better terminal state management
func NewImprovedMicroLiner ¶ added in v0.2.50
func NewImprovedMicroLiner(ch chan KeyEvent, sb func(msg string), el func(line string) string) *ImprovedMLState
NewImprovedMicroLiner creates a new improved microliner with terminal state tracking
type InputWidget ¶ added in v0.2.50
type InputWidget struct {
BaseWidget
Text string
MaxLen int
Position int // cursor position within text
}
InputWidget handles single-line text input
func NewInputWidget ¶ added in v0.2.50
func NewInputWidget(maxLen int, idx *env.Idxs) *InputWidget
NewInputWidget creates a new input widget
func (*InputWidget) GetHeight ¶ added in v0.2.50
func (w *InputWidget) GetHeight() int
func (*InputWidget) GetValue ¶ added in v0.2.50
func (w *InputWidget) GetValue() env.Object
func (*InputWidget) HandleKey ¶ added in v0.2.50
func (w *InputWidget) HandleKey(key WidgetKey) (done bool, canceled bool)
func (*InputWidget) Render ¶ added in v0.2.50
func (w *InputWidget) Render()
type MLState ¶ added in v0.0.26
type MLState struct {
// contains filtered or unexported fields
}
MLState represents the state of a microliner terminal session
func NewMicroLiner ¶ added in v0.0.26
NewMicroLiner initializes a new *MLState with the provided event channel, output function, and line handler function.
func (*MLState) AppendHistory ¶ added in v0.0.26
AppendHistory appends an entry to the scrollback history. AppendHistory should be called iff Prompt returns a valid command.
func (*MLState) ClearHistory ¶ added in v0.0.26
func (s *MLState) ClearHistory()
ClearHistory clears the scrollback history.
func (*MLState) DeleteHistoryAt ¶ added in v0.2.3
DeleteHistoryAt removes the entry at the given index from the scrollback history. It is a no-op when idx is out of bounds.
func (*MLState) GetHistoryLast ¶ added in v0.0.97
Returns the last N history lines
func (*MLState) GetKeyChan ¶ added in v0.0.40
func (*MLState) MicroPrompt ¶ added in v0.0.26
func (s *MLState) MicroPrompt(prompt string, text string, pos int, ctx1 context.Context) (string, error)
MicroPrompt displays a prompt and handles user input with editing capabilities. It returns the final input string or an error if the operation was canceled or failed. The prompt is displayed with the given text and cursor position. The context can be used to cancel the operation.
func (*MLState) ReadHistory ¶ added in v0.0.31
ReadHistory reads history entries from an io.Reader and adds them to the history buffer. It returns the number of entries successfully read and any error encountered. If an error occurs, some entries may have been added to the history buffer.
func (*MLState) SetColumns ¶ added in v0.0.27
func (*MLState) SetCompleter ¶ added in v0.0.26
SetCompleter sets the completion function that Liner will call to fetch completion candidates when the user presses tab.
func (*MLState) SetDisplayValueFunc ¶ added in v0.0.82
func (s *MLState) SetDisplayValueFunc(fn func(*env.ProgramState, env.Object, bool) (env.Object, string))
SetDisplayValueFunc sets the callback function used to display values
func (*MLState) SetOnValueSelectedFunc ¶ added in v0.0.93
SetOnValueSelectedFunc sets the callback function called when user selects a value via Ctrl+x
func (*MLState) SetProgramState ¶ added in v0.0.82
func (s *MLState) SetProgramState(ps *env.ProgramState)
SetProgramState sets the program state for environment access during tab completion
func (*MLState) SetPromptFunc ¶ added in v0.2.3
SetPromptFunc sets an optional function that returns the prompt string. When set, it is called before each new input line so the prompt can reflect dynamic state (e.g. the current context kind).
func (*MLState) SetWasmMode ¶ added in v0.2.0
SetWasmMode enables WASM mode which avoids terminal operations that cause issues in xterm.js
func (*MLState) WriteHistory ¶ added in v0.0.31
WriteHistory writes scrollback history to w. Returns the number of lines successfully written, and any write error.
Unlike the rest of liner's API, WriteHistory is safe to call from another goroutine while Prompt is in progress. This exception is to facilitate the saving of the history buffer during an unexpected exit (for example, due to Ctrl-C being invoked)
type PaginatedSelectWidget ¶ added in v0.2.50
type PaginatedSelectWidget struct {
BaseWidget
Items []env.Object
Current int // Global index
PageSize int
CurrentPage int
}
PaginatedSelectWidget handles selection from large lists with pagination
func NewPaginatedSelectWidget ¶ added in v0.2.50
func NewPaginatedSelectWidget(items []env.Object, pageSize int, idx *env.Idxs) *PaginatedSelectWidget
NewPaginatedSelectWidget creates a new paginated selection widget
func (*PaginatedSelectWidget) GetHeight ¶ added in v0.2.50
func (w *PaginatedSelectWidget) GetHeight() int
func (*PaginatedSelectWidget) GetValue ¶ added in v0.2.50
func (w *PaginatedSelectWidget) GetValue() env.Object
func (*PaginatedSelectWidget) HandleKey ¶ added in v0.2.50
func (w *PaginatedSelectWidget) HandleKey(key WidgetKey) (done bool, canceled bool)
func (*PaginatedSelectWidget) Render ¶ added in v0.2.50
func (w *PaginatedSelectWidget) Render()
type SelectWidget ¶ added in v0.2.50
type SelectWidget struct {
BaseWidget
Items []env.Object
Current int
}
SelectWidget allows selecting an item from a block
func NewSelectWidget ¶ added in v0.2.50
func NewSelectWidget(items []env.Object, idx *env.Idxs) *SelectWidget
NewSelectWidget creates a new selection widget
func (*SelectWidget) GetHeight ¶ added in v0.2.50
func (w *SelectWidget) GetHeight() int
func (*SelectWidget) GetValue ¶ added in v0.2.50
func (w *SelectWidget) GetValue() env.Object
func (*SelectWidget) HandleKey ¶ added in v0.2.50
func (w *SelectWidget) HandleKey(key WidgetKey) (done bool, canceled bool)
func (*SelectWidget) Render ¶ added in v0.2.50
func (w *SelectWidget) Render()
type TerminalSize ¶ added in v0.2.11
TerminalSize represents the terminal dimensions
func GetTerminalSize ¶ added in v0.2.11
func GetTerminalSize() (TerminalSize, error)
GetTerminalSize returns the current terminal size (width and height in characters)
type TerminalState ¶ added in v0.2.50
type TerminalState struct {
// contains filtered or unexported fields
}
TerminalState tracks the current state of the terminal for robust cursor management
type TextAreaWidget ¶ added in v0.2.50
TextAreaWidget handles multiline text input
func NewTextAreaWidget ¶ added in v0.2.50
func NewTextAreaWidget(width, height int, initialText string, idx *env.Idxs) *TextAreaWidget
NewTextAreaWidget creates a new textarea widget
func (*TextAreaWidget) GetHeight ¶ added in v0.2.50
func (w *TextAreaWidget) GetHeight() int
func (*TextAreaWidget) GetValue ¶ added in v0.2.50
func (w *TextAreaWidget) GetValue() env.Object
func (*TextAreaWidget) HandleKey ¶ added in v0.2.50
func (w *TextAreaWidget) HandleKey(key WidgetKey) (done bool, canceled bool)
func (*TextAreaWidget) Render ¶ added in v0.2.50
func (w *TextAreaWidget) Render()
type Theme ¶ added in v0.2.50
type Theme struct {
Selected func() // Function to set selected item style
Normal func() // Function to reset to normal style
Header func() // Function to set header style
Cursor string // Cursor character for selected items
CursorNormal string // Space or empty for non-selected items
}
Theme defines colors and styles for widgets
type Widget ¶ added in v0.2.50
type Widget interface {
// Render draws the widget at the current cursor position
Render()
// HandleKey processes a key event, returns (done, canceled)
HandleKey(key WidgetKey) (done bool, canceled bool)
// GetValue returns the current value of the widget
GetValue() env.Object
// GetHeight returns the number of lines the widget occupies
GetHeight() int
}
Widget is the interface for all TUI components
type WidgetKey ¶ added in v0.2.50
WidgetKey represents a keyboard input event for widgets
type WordCompleter ¶ added in v0.0.26
type WordCompleter func(line string, pos int, mode int) (head string, completions []string, tail string)
WordCompleter takes the currently edited line with the cursor position and to the completer which may returns ("Hello, ", {"world", "Word"}, "!!!") to have "Hello, world!!!".