### Get Line Info Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns information about the current soft-wrapped line. ```go func (m Model) LineInfo() LineInfo ``` -------------------------------- ### Move Cursor to Start Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor to the beginning of the input field. ```go func (m *Model) CursorStart() ``` -------------------------------- ### Get Line Position Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current line index. ```go func (m Model) Line() int ``` -------------------------------- ### Model Height and Width Methods Source: https://pkg.go.dev/github.com/knz/bubbline/complete Methods to get or set the dimensions of the completion component. ```go func (m *Model) GetHeight() int func (m *Model) GetMaxHeight() int func (m *Model) SetHeight(height int) func (m *Model) SetWidth(width int) ``` -------------------------------- ### Get Length Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the total number of characters in the input. ```go func (m *Model) Length() int ``` -------------------------------- ### Example Output for History Operations Source: https://pkg.go.dev/github.com/knz/bubbline/history Displays the expected output format when interacting with history files. ```text Output: open /dev/null/notvalid: not a directory open /dev/null/notvalid: not a directory ``` -------------------------------- ### Get Current Line Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Retrieves the text content of the current line as a string. ```go func (m *Model) CurrentLine() string ``` -------------------------------- ### Get Debug Info Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns a string containing debug details about the model state. ```go func (m Model) Debug() string ``` -------------------------------- ### Get Line Info at Position Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Computes LineInfo for a specific row and column. ```go func (m Model) LineInfoAt(row, col int) LineInfo ``` -------------------------------- ### Get Line Count Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the total number of lines in the input. ```go func (m *Model) LineCount() int ``` -------------------------------- ### Get Logical Height Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the number of lines required to display the entire value. ```go func (m Model) LogicalHeight() int ``` -------------------------------- ### Get Height Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current height of the textarea. ```go func (m Model) Height() int ``` -------------------------------- ### Create simple word completions Source: https://pkg.go.dev/github.com/knz/bubbline/editline SimpleWordsCompletion converts a slice of strings into a Completions interface, requiring start and end positions for the word on the current line. ```go func SimpleWordsCompletion(words []string, category string, cursor, start, end int) Completions ``` -------------------------------- ### Get Number of Logical Lines Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the count of logical lines in the value. ```go func (m *Model) NumLinesInValue() int ``` -------------------------------- ### Get text area width Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current width of the textarea. ```go func (m Model) Width() int ``` -------------------------------- ### Get Cursor Position Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Retrieves the current integer position of the cursor. ```go func (m *Model) CursorPos() int ``` -------------------------------- ### Create a single word completion Source: https://pkg.go.dev/github.com/knz/bubbline/editline SingleWordCompletion converts a single string into a Completions interface, requiring start and end positions for the word on the current line. ```go func SingleWordCompletion(word string, cursor, start, end int) Completions ``` -------------------------------- ### FindWord Function Source: https://pkg.go.dev/github.com/knz/bubbline/computil Identifies the start and end of a word at a specific cursor position within a 2D rune grid. Useful for AutoComplete callbacks. ```go func FindWord(v [][]rune, line, col int) (word string, wordStart, wordEnd int) ``` -------------------------------- ### Model Help Methods Source: https://pkg.go.dev/github.com/knz/bubbline/complete Methods for the help.KeyMap interface. ```go func (m *Model) FullHelp() [][]key.Binding func (m *Model) ShortHelp() []key.Binding ``` -------------------------------- ### Model Initialization Source: https://pkg.go.dev/github.com/knz/bubbline/editline Creates a new instance of the Model. ```go func New(width, height int) *Model ``` -------------------------------- ### Initialize Model Source: https://pkg.go.dev/github.com/knz/bubbline/complete Creates a new instance of the completion model. ```go func New() Model ``` -------------------------------- ### ShortHelp Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Implements the help.KeyMap interface to provide short help bindings. ```go func (m Model) ShortHelp() []key.Binding ``` -------------------------------- ### Model Initialization and State Methods Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Methods for creating a new model and checking cursor position state. ```go func New() Model ``` ```go func (m *Model) AtBeginningOfEmptyLine() bool ``` ```go func (m *Model) AtFirstLineOfInputAndView() bool ``` ```go func (m *Model) AtLastLineOfInputAndView() bool ``` -------------------------------- ### Initialize and use Bubbline input widget Source: https://pkg.go.dev/github.com/knz/bubbline Demonstrates how to instantiate the Bubbline widget and process input lines, including handling EOF, interruptions, and termination errors. ```go package main import ( "errors" "fmt" "io" "log" tea "github.com/charmbracelet/bubbletea" "github.com/knz/bubbline" ) func main() { // Instantiate the widget. m := bubbline.New() for { // Read a line of input using the widget. val, err := m.GetLine() // Handle the end of input. if err != nil { if err == io.EOF { // No more input. break } if errors.Is(err, bubbline.ErrInterrupted) { // Entered Ctrl+C to cancel input. fmt.Println("^C") } else if errors.Is(err, bubbline.ErrTerminated) { fmt.Println("terminated") break } else { fmt.Println("error:", err) } continue } // Handle regular input. fmt.Printf("\nYou have entered: %q\n", val) m.AddHistory(val) } } ``` -------------------------------- ### Create String Entry Source: https://pkg.go.dev/github.com/knz/bubbline/complete Adds the Entry interface to a simple string. ```go func StringEntry(s string) Entry ``` -------------------------------- ### New(width, height int) *Model Source: https://pkg.go.dev/github.com/knz/bubbline/editline Creates a new instance of the Model with the specified initial width and height. ```APIDOC ### func New Creates a new Model instance. #### Signature `func New(width, height int) *Model` ``` -------------------------------- ### Model Lifecycle Methods Source: https://pkg.go.dev/github.com/knz/bubbline/complete Methods implementing the tea.Model interface. ```go func (m *Model) Init() tea.Cmd func (m *Model) Update(imsg tea.Msg) (tea.Model, tea.Cmd) func (m *Model) View() string ``` -------------------------------- ### Focus Model Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the focus state, allowing keyboard input. ```go func (m *Model) Focus() tea.Cmd ``` -------------------------------- ### (*Model) Focus() tea.Cmd Source: https://pkg.go.dev/github.com/knz/bubbline/editline Sets the focus state on the model, allowing it to receive keyboard input and displaying the cursor. ```APIDOC ### func (*Model) Focus Sets the focus state on the model. #### Signature `func (m *Model) Focus() tea.Cmd` ``` -------------------------------- ### Define KeyMap Structure Source: https://pkg.go.dev/github.com/knz/bubbline/complete Defines keybindings for navigating the completions. ```go type KeyMap struct { list.KeyMap NextCompletions key.Binding PrevCompletions key.Binding AcceptCompletion key.Binding Abort key.Binding } ``` -------------------------------- ### Editor Methods Source: https://pkg.go.dev/github.com/knz/bubbline Methods for managing the editor lifecycle, history, and input processing. ```go func New() *Editor ``` ```go func (m *Editor) AddHistory(line string) error ``` ```go func (m *Editor) Close() ``` ```go func (m *Editor) GetLine() (string, error) ``` ```go func (m *Editor) LoadHistory(file string) error ``` ```go func (m *Editor) SaveHistory() error ``` ```go func (m *Editor) SetAutoSaveHistory(file string, autoSave bool) ``` ```go func (m *Editor) Update(imsg tea.Msg) (tea.Model, tea.Cmd) ``` -------------------------------- ### Set Prompt Function Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Configures a custom prompt function for the textarea. ```go func (m *Model) SetPromptFunc(promptWidth int, fn func(lineIdx int) string) ``` -------------------------------- ### Model Focus and Blur Methods Source: https://pkg.go.dev/github.com/knz/bubbline/complete Methods to manage the focus state of the completion editor. ```go func (m *Model) Blur() func (m *Model) Focus() ``` -------------------------------- ### SetHistory Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Sets the entire history navigation list for the model. ```go func (m *Model) SetHistory(h []string) ``` -------------------------------- ### Style Struct Source: https://pkg.go.dev/github.com/knz/bubbline/editline Defines the styling configuration for the editor and search input components. ```go type Style struct { Editor textarea.Style SearchInput struct { PromptStyle lipgloss.Style TextStyle lipgloss.Style // BackgroundStyle is unused. // // Deprecated: kept for backward compatibility; the underlying // bubbles/textinput widget removed background styling and this field has no effect. BackgroundStyle lipgloss.Style PlaceholderStyle lipgloss.Style CursorStyle lipgloss.Style } } ``` -------------------------------- ### Function InputComplete Source: https://pkg.go.dev/github.com/knz/bubbline/editline Generates an InputCompleteMsg. ```go func InputComplete() tea.Msg ``` -------------------------------- ### Interface and Debugging Methods Source: https://pkg.go.dev/github.com/knz/bubbline/editline Methods for debugging and satisfying interface requirements. ```go func (m *Model) Debug() string ``` ```go func (m Model) FullHelp() [][]key.Binding ``` ```go func (m *Model) Init() tea.Cmd ``` -------------------------------- ### Focus and State Management Source: https://pkg.go.dev/github.com/knz/bubbline/editline Methods to control the focus state and reset the model. ```go func (m *Model) Blur() ``` ```go func (m *Model) Focus() tea.Cmd ``` ```go func (m *Model) Reset() ``` -------------------------------- ### Model Debug Method Source: https://pkg.go.dev/github.com/knz/bubbline/complete Returns debug information as a string. ```go func (m *Model) Debug() string ``` -------------------------------- ### View Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Renders the text area in its current state. ```APIDOC ## func (Model) View ### Description View renders the text area in its current state. ### Signature `func (m Model) View() string` ``` -------------------------------- ### Define Entry Interface Source: https://pkg.go.dev/github.com/knz/bubbline/complete Interface for a single completion candidate. ```go type Entry interface { // Title is the main displayed text. Title() string // Description is the explanation for the entry. Description() string } ``` -------------------------------- ### History Management Source: https://pkg.go.dev/github.com/knz/bubbline/editline Methods for interacting with the input history. ```go func (m *Model) AddHistoryEntry(s string) ``` ```go func (m *Model) GetHistory() []string ``` -------------------------------- ### LoadHistory Function Signature Source: https://pkg.go.dev/github.com/knz/bubbline/history Signature for loading history from a file path. ```go func LoadHistory(fileName string) ([]string, error) ``` -------------------------------- ### func New Source: https://pkg.go.dev/github.com/knz/bubbline/editline Creates a new Model instance for the editline component. ```APIDOC ## func New(width, height int) *Model ### Description Initializes a new Model with the specified dimensions. ### Parameters - **width** (int) - The width of the input area. - **height** (int) - The height of the input area. ### Returns - **Model** (*Model) - A pointer to the initialized Model. ``` -------------------------------- ### Define a completion candidate Source: https://pkg.go.dev/github.com/knz/bubbline/editline The Candidate interface defines how a completion string replaces existing text, including cursor movement and character deletion logic. ```go type Candidate interface { // Replacement is the string to replace. Replacement() string // MoveRight returns the number of times the cursor // should be moved to the right to arrive at the // end of the word being replaced by the completion. // // For example, if the input is this: // // alice // ^ // // where the cursor is on the 2nd character, and // the completion is able to replace the entire word, // MoveRight should return 4. MoveRight() int // DeleteLeft returns the total number of characters // being replaced by the completion, including the // characters to the right of the cursor (as returned by MoveRight). // // For example, if the input is this: // // alice // ^ // // where the cursor is on the 2nd character, and // the completion is able to replace the entire word, // DeleteLeft should return 5. DeleteLeft() int } ``` -------------------------------- ### Default KeyMap Bindings Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Partial definition of the default key bindings for text manipulation actions. ```go TransposeCharacterBackward: key.NewBinding(key.WithKeys("ctrl+t"), key.WithHelp("C-t", "transpose char")), CapitalizeWordForward: key.NewBinding(key.WithKeys("alt+c"), key.WithHelp("M-c", "capitalize word")), LowercaseWordForward: key.NewBinding(key.WithKeys("alt+l"), key.WithHelp("M-l", "lowercase word")), UppercaseWordForward: key.NewBinding(key.WithKeys("alt+u"), key.WithHelp("M-u", "uppercase word")), ToggleOverwriteMode: key.NewBinding(key.WithKeys("insert", "alt+o"), key.WithHelp("M-o/ins", "toggle overwrite")), } ``` -------------------------------- ### Textarea Utility Functions Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Functions for cursor control, styling, and clipboard operations. ```go func Blink() tea.Msg ``` ```go func DefaultStyles() (Style, Style) ``` ```go func Paste() tea.Msg ``` -------------------------------- ### Function DefaultStyles Source: https://pkg.go.dev/github.com/knz/bubbline/editline Returns default styles for focused and blurred states. ```go func DefaultStyles() (Style, Style) ``` -------------------------------- ### func (*Editor) GetLine() (string, error) Source: https://pkg.go.dev/github.com/knz/bubbline Runs the editor and retrieves the input line. ```APIDOC ## func (*Editor) GetLine() (string, error) ### Description Getline runs the editor and returns the line that was read. ``` -------------------------------- ### Clear Line Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Clears the content of the current line. ```go func (m *Model) ClearLine() ``` -------------------------------- ### Update Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea The Bubble Tea update loop for the textarea model. ```APIDOC ## func (Model) Update ### Description Update is the Bubble Tea update loop. ### Signature `func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)` ``` -------------------------------- ### func New() *Editor Source: https://pkg.go.dev/github.com/knz/bubbline Instantiates a new editor instance. ```APIDOC ## func New() ### Description Instantiates an editor. ### Signature `func New() *Editor` ``` -------------------------------- ### Function DefaultReflow Source: https://pkg.go.dev/github.com/knz/bubbline/editline Default implementation for reflowing text. ```go func DefaultReflow( allText bool, currentText string, targetWidth int, ) (changed bool, newText, info string) ``` -------------------------------- ### Model SetValues Method Source: https://pkg.go.dev/github.com/knz/bubbline/complete Resets the values and recomputes the height. ```go func (m *Model) SetValues(values Values) ``` -------------------------------- ### LineInfo Struct Definition Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Helper structure for tracking soft-wrapped line metrics. ```go type LineInfo struct { // Width is the number of columns in the line. Width int // CharWidth is the number of characters in the line to account for // double-width runes. CharWidth int // Height is the number of rows in the line. Height int // StartColumn is the index of the first column of the line. StartColumn int // ColumnOffset is the number of columns that the cursor is offset from the // start of the line. ColumnOffset int // RowOffset is the number of rows that the cursor is offset from the start // of the line. RowOffset int // CharOffset is the number of characters that the cursor is offset // from the start of the line. This will generally be equivalent to // ColumnOffset, but will be different there are double-width runes before // the cursor. CharOffset int } ``` -------------------------------- ### Define Styles Structure Source: https://pkg.go.dev/github.com/knz/bubbline/complete Style definitions for the completions component. ```go type Styles struct { FocusedTitleBar lipgloss.Style FocusedTitle lipgloss.Style BlurredTitleBar lipgloss.Style BlurredTitle lipgloss.Style Item lipgloss.Style SelectedItem lipgloss.Style Spinner lipgloss.Style FilterPrompt lipgloss.Style FilterCursor lipgloss.Style PaginationStyle lipgloss.Style DefaultFilterCharacterMatch lipgloss.Style ActivePaginationDot lipgloss.Style InactivePaginationDot lipgloss.Style ArabicPagination lipgloss.Style DividerDot lipgloss.Style PlaceholderDescription lipgloss.Style Description lipgloss.Style } ``` -------------------------------- ### Reset Model Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Resets the input to its default state with no content. ```go func (m *Model) Reset() ``` -------------------------------- ### Model Key Matching Source: https://pkg.go.dev/github.com/knz/bubbline/complete Checks if the completion editor can use the given key message. ```go func (m *Model) MatchesKey(msg tea.KeyMsg) bool ``` -------------------------------- ### Update Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Handles Bubble Tea events as part of the tea.Model interface. ```go func (m *Model) Update(imsg tea.Msg) (tea.Model, tea.Cmd) ``` -------------------------------- ### SetSize Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Updates the editor dimensions. Changes take effect on the next processed event, and zero values are ignored. ```go func (m *Model) SetSize(width, height int) ``` -------------------------------- ### Define Model Structure Source: https://pkg.go.dev/github.com/knz/bubbline/complete The model that implements the completion selector widget. ```go type Model struct { Err error // KeyMap is the key bindings for navigating the completions. KeyMap KeyMap // Styles is the styles to use for display. Styles Styles // AcceptedValue is the result of the selection. AcceptedValue Entry // contains filtered or unexported fields } ``` -------------------------------- ### Define completion management Source: https://pkg.go.dev/github.com/knz/bubbline/editline The Completions interface manages a set of completion values and provides a method to convert entries into candidates. ```go type Completions interface { // Values is the set of all completion values. complete.Values // Candidate converts a complete.Entry to a Candidate. Candidate(e complete.Entry) Candidate } ``` -------------------------------- ### Model Struct Definition Source: https://pkg.go.dev/github.com/knz/bubbline/editline The Model struct defines the configuration and state for the multi-line input widget. ```go type Model struct { // Err is the final state at the end of input. // Likely io.EOF or ErrInterrupted. Err error // KeyMap is the key bindings to use. KeyMap KeyMap // Styling. FocusedStyle and BlurredStyle are used to style the textarea in // focused and blurred states. // Only takes effect at Reset() or Focus(). FocusedStyle Style BlurredStyle Style // Placeholder is displayed when the editor is still empty. // Only takes effect at Reset() or Focus(). Placeholder string // CheckInputComplete is called when the Enter key is pressed. It // determines whether a newline character should be added to the // input (callback returns false) or whether the input should // terminate altogether (callback returns true). The callback is // provided the text of the input and the line number at which the // cursor is currently positioned as argument. // // The default behavior if CheckInputComplete is nil is to terminate // the input when enter is pressed. CheckInputComplete func(entireInput [][]rune, line, col int) bool // AutoComplete is the AutoCompleteFn to use. AutoComplete AutoCompleteFn // CharLimit is the maximum size of the input in characters. // Set to zero or less for no limit. CharLimit int // MaxHeight is the maximum height of the input in lines. // Set to zero or less for no limit. MaxHeight int // MaxWidth is the maximum width of the input in characters. // Set to zero or less for no limit. MaxWidth int // CursorMode determines how the cursor is displayed. CursorMode cursor.Mode // MaxHistorySize is the maximum number of entries in the history. // Set to zero for no limit. MaxHistorySize int // DedupHistory if true avoids adding a history entry // if it is equal to the last one added. DedupHistory bool // DeleteCharIfNotEOF, if true, causes the EndOfInput key binding // to be translated to delete-character-forward when it is not // entered at the beginning of a line. // Meant for use when the EndOfInput key binding is Ctrl+D, which // is the standard character deletion in textarea/libedit. // This can be set to false if the EndOfInput binding is fully // separate from DeleteCharacterForward. DeleteCharIfNotEOF bool // Prompt is the prompt displayed before entry lines. // Only takes effect at Reset(). Prompt string // NextPrompt, if defined is the prompt displayed before entry lines // after the first one. // Only takes effect at Reset(). NextPrompt string // Reflow, if defined, is used for the reflowing commands (M-q/M-Q). // The info returned value, if any, is displayed as an informational // message above the editor. Reflow func(all bool, currentText string, targetWidth int) (changed bool, newText, info string) // SearchPrompt is the prompt displayed before the history search pattern. SearchPrompt string // SearchPromptNotFound is the prompt displayed before the history search pattern, // when no match is found. SearchPromptNotFound string // SearchPromptInvalid is the prompt displayed before the history search pattern, // when the pattern is invalid. SearchPromptInvalid string // CaseSensitiveSearch, if enabled, makes history search case-sensitive. CaseSensitiveSearch bool // ShowLineNumbers if true shows line numbers at the beginning // of each input line. // Only takes effect at Reset() or Focus(). ShowLineNumbers bool // contains filtered or unexported fields } ``` -------------------------------- ### Type AutoCompleteFn Source: https://pkg.go.dev/github.com/knz/bubbline/editline Callback function signature for handling autocomplete requests. ```go type AutoCompleteFn func(entireInput [][]rune, line, col int) (msg string, comp Completions) ``` -------------------------------- ### String Values Implementation Source: https://pkg.go.dev/github.com/knz/bubbline/complete Adds the Values interface to a simple string slice. ```go func StringValues(title string, entries []string) Values ``` -------------------------------- ### Define editor key mappings Source: https://pkg.go.dev/github.com/knz/bubbline/editline KeyMap aggregates various key bindings for editor actions, extending the base textarea key map. ```go type KeyMap struct { textarea.KeyMap EndOfInput key.Binding Interrupt key.Binding AutoComplete key.Binding SignalQuit key.Binding SignalTTYStop key.Binding Refresh key.Binding AbortSearch key.Binding SearchBackward key.Binding HistoryPrevious key.Binding HistoryNext key.Binding Debug key.Binding HideShowPrompt key.Binding AlwaysNewline key.Binding AlwaysComplete key.Binding MoreHelp key.Binding ReflowLine key.Binding ReflowAll key.Binding ExternalEdit key.Binding } ``` -------------------------------- ### Insert String Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Inserts a string at the current cursor position. ```go func (m *Model) InsertString(s string) ``` -------------------------------- ### Define Default Key Bindings Source: https://pkg.go.dev/github.com/knz/bubbline/complete The DefaultKeyMap variable provides the standard set of key bindings for navigation, filtering, and completion selection. ```go var DefaultKeyMap = KeyMap{ KeyMap: list.KeyMap{ CursorUp: key.NewBinding(key.WithKeys("up", "ctrl+p"), key.WithHelp("C-p/↑", "prev entry")), CursorDown: key.NewBinding(key.WithKeys("down", "ctrl+n"), key.WithHelp("C-n/↓", "next entry")), NextPage: key.NewBinding(key.WithKeys("pgdown"), key.WithHelp("pgdown", "prev page/column")), PrevPage: key.NewBinding(key.WithKeys("pgup"), key.WithHelp("pgup", "next page/column")), GoToStart: key.NewBinding(key.WithKeys("ctrl+a", "home"), key.WithHelp("C-a/home", "start of column")), GoToEnd: key.NewBinding(key.WithKeys("ctrl+e", "end"), key.WithHelp("C-e/end", "end of column")), Filter: key.NewBinding(key.WithKeys("/", ""), key.WithHelp("/", "filter")), ClearFilter: key.NewBinding(key.WithKeys("ctrl+g"), key.WithHelp("C-g", "clear/cancel")), CancelWhileFiltering: key.NewBinding(key.WithKeys("ctrl+g"), key.WithHelp("C-g", "clear/cancel")), AcceptWhileFiltering: key.NewBinding(key.WithKeys("enter", "ctrl+j"), key.WithHelp("C-j/enter", "accept filter")), ShowFullHelp: key.NewBinding(key.WithKeys("alt+?"), key.WithHelp("M-?", "toggle key help")), CloseFullHelp: key.NewBinding(key.WithKeys("alt+?"), key.WithHelp("M-?", "toggle key help")), }, NextCompletions: key.NewBinding(key.WithKeys("right", "alt+n"), key.WithHelp("→/M-n", "next column")), PrevCompletions: key.NewBinding(key.WithKeys("left", "alt+p"), key.WithHelp("←/M-p", "prev column")), AcceptCompletion: key.NewBinding(key.WithKeys("enter", "tab", "ctrl+j"), key.WithHelp("C-j/enter/tab", "accept")), Abort: key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("C-c", "close/cancel")), } ``` -------------------------------- ### Configure text area width Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the width of the textarea to fit exactly within the given width, accounting for prompts and line numbers. Call this after setting the Prompt and ShowLineNumbers. ```go func (m *Model) SetWidth(w int) ``` -------------------------------- ### Value Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Retrieves the current string value of the text input. ```go func (m *Model) Value() string ``` -------------------------------- ### SaveHistory Function Signature Source: https://pkg.go.dev/github.com/knz/bubbline/history Signature for saving history to a file path. ```go func SaveHistory(h []string, fileName string) (retErr error) ``` -------------------------------- ### KeyMap Struct Definition Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea The structure defining all supported key bindings for the textarea. ```go type KeyMap struct { CharacterBackward key.Binding CharacterForward key.Binding DeleteAfterCursor key.Binding DeleteBeforeCursor key.Binding DeleteCharacterBackward key.Binding DeleteCharacterForward key.Binding DeleteWordBackward key.Binding DeleteWordForward key.Binding InsertNewline key.Binding LineEnd key.Binding LineNext key.Binding LinePrevious key.Binding LineStart key.Binding Paste key.Binding WordBackward key.Binding WordForward key.Binding InputBegin key.Binding InputEnd key.Binding ToggleOverwriteMode key.Binding TransposeCharacterBackward key.Binding UppercaseWordForward key.Binding LowercaseWordForward key.Binding CapitalizeWordForward key.Binding } ``` -------------------------------- ### func DefaultStyles Source: https://pkg.go.dev/github.com/knz/bubbline/editline Returns the default styles for focused and blurred states. ```APIDOC ## func DefaultStyles() (Style, Style) ### Description Returns the default styles for focused and blurred states for the textarea. ### Returns - **Style** (Style) - Style for the focused state. - **Style** (Style) - Style for the blurred state. ``` -------------------------------- ### Move Cursor Up Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor up one line. ```go func (m *Model) CursorUp() ``` -------------------------------- ### (*Model) AddHistoryEntry(s string) Source: https://pkg.go.dev/github.com/knz/bubbline/editline Adds a string entry to the history navigation list. ```APIDOC ### func (*Model) AddHistoryEntry Adds an entry to the history navigation list. #### Signature `func (m *Model) AddHistoryEntry(s string)` ``` -------------------------------- ### Define Type Aliases Source: https://pkg.go.dev/github.com/knz/bubbline Type aliases for autocomplete and completion handling. ```go type AutoCompleteFn = editline.AutoCompleteFn ``` ```go type Candidate = editline.Candidate ``` ```go type Completions = editline.Completions ``` ```go type Entry = complete.Entry ``` ```go type Values = complete.Values ``` -------------------------------- ### func (*Editor) LoadHistory(file string) error Source: https://pkg.go.dev/github.com/knz/bubbline Loads history from a file. ```APIDOC ## func (*Editor) LoadHistory(file string) error ### Description LoadHistory loads the entry history from file. ### Parameters - **file** (string) - Required - The path to the history file. ``` -------------------------------- ### Set Height Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the vertical height of the textarea. ```go func (m *Model) SetHeight(h int) ``` -------------------------------- ### Move Cursor to Position Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor to the specified row and column. ```go func (m *Model) MoveTo(row, col int) ``` -------------------------------- ### Define Default KeyMap Source: https://pkg.go.dev/github.com/knz/bubbline/editline The default set of key bindings for the editline model. ```go var DefaultKeyMap = KeyMap{ KeyMap: textarea.DefaultKeyMap, AlwaysNewline: key.NewBinding(key.WithKeys("ctrl+o"), key.WithHelp("C-o", "force newline")), AlwaysComplete: key.NewBinding(key.WithKeys("alt+enter", "alt+\r"), key.WithHelp("M-⤶/M-C-m", "force complete")), AutoComplete: key.NewBinding(key.WithKeys("tab"), key.WithHelp("tab", "try autocomplete")), Interrupt: key.NewBinding(key.WithKeys("ctrl+c"), key.WithHelp("C-c", "clear/cancel")), SignalQuit: key.NewBinding(key.WithKeys(`ctrl+\`)), SignalTTYStop: key.NewBinding(key.WithKeys("ctrl+z")), Refresh: key.NewBinding(key.WithKeys("ctrl+l"), key.WithHelp("C-l", "refresh display")), EndOfInput: key.NewBinding(key.WithKeys("ctrl+d"), key.WithHelp("C-d", "erase/stop")), AbortSearch: key.NewBinding(key.WithKeys("ctrl+g"), key.WithDisabled()), SearchBackward: key.NewBinding(key.WithKeys("ctrl+r"), key.WithHelp("C-r", "search hist"), key.WithDisabled()), HistoryPrevious: key.NewBinding(key.WithKeys("alt+p"), key.WithHelp("M-p", "prev history entry"), key.WithDisabled()), HistoryNext: key.NewBinding(key.WithKeys("alt+n"), key.WithHelp("M-n", "next history entry"), key.WithDisabled()), HideShowPrompt: key.NewBinding(key.WithKeys("alt+."), key.WithHelp("M-.", "hide/show prompt")), MoreHelp: key.NewBinding(key.WithKeys("alt+?"), key.WithHelp("M-?", "toggle key help")), ReflowLine: key.NewBinding(key.WithKeys("alt+q"), key.WithHelp("M-q", "reflow line")), ReflowAll: key.NewBinding(key.WithKeys("alt+Q", "alt+`"), key.WithHelp("M-S-q/M-`", "reflow all")), Debug: key.NewBinding(key.WithKeys("ctrl+_", "ctrl+@"), key.WithHelp("C-_/C-@", "debug mode"), key.WithDisabled()), ExternalEdit: key.NewBinding(key.WithKeys("alt+f2", "alt+2"), key.WithHelp("M-2/M-F2", "external edit")), } ``` -------------------------------- ### Render text area Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Renders the text area in its current state. ```go func (m Model) View() string ``` -------------------------------- ### func LoadHistory Source: https://pkg.go.dev/github.com/knz/bubbline/history Loads a history from a file at the specified path. The file must be in the same format as used by libedit. ```APIDOC ## func LoadHistory(fileName string) ([]string, error) ### Description Loads a history from a file loaded from the specified path. The file must be in the same format as used by libedit. ### Parameters - **fileName** (string) - Required - The path to the history file. ### Returns - **[]string** - A slice of history entries. - **error** - An error object if the operation fails. ``` -------------------------------- ### Define Values Interface Source: https://pkg.go.dev/github.com/knz/bubbline/complete Interface for the values displayed by the completion bubble. ```go type Values interface { // NumCategories returns the number of categories to display. NumCategories() int // CategoryTitle returns the title of a category. CategoryTitle(catIdx int) string // NumEntries returns the number of entries in a given category. NumEntries(catIdx int) int // Entry returns the entry in a category. Entry(catIdx, entryIdx int) Entry } ``` -------------------------------- ### Insert Rune Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Inserts a single rune at the current cursor position. ```go func (m *Model) InsertRune(r rune) ``` -------------------------------- ### Map Values Implementation Source: https://pkg.go.dev/github.com/knz/bubbline/complete Adds the Values interface to a map of entries. ```go func MapValues(values interface{}, categories []string) Values ``` ```go func MapValues[T Entry](values map[string][]T, categories []string) ``` -------------------------------- ### Define Default Styles Source: https://pkg.go.dev/github.com/knz/bubbline/complete The DefaultStyles variable provides a set of default lipgloss style definitions for the completions component. ```go var DefaultStyles = func() (c Styles) { ls := list.DefaultStyles() subtle := lipgloss.AdaptiveColor{Light: "#D9DCCF", Dark: "#383838"} c.Item = lipgloss.NewStyle().PaddingLeft(1) c.SelectedItem = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.Color("170")) c.FocusedTitleBar = lipgloss.NewStyle() c.BlurredTitleBar = lipgloss.NewStyle() c.FocusedTitle = lipgloss.NewStyle().Background(lipgloss.Color("62")).Foreground(lipgloss.Color("230")) c.BlurredTitle = c.FocusedTitle.Copy().Foreground(subtle) c.Spinner = ls.Spinner c.FilterPrompt = ls.FilterPrompt c.FilterCursor = ls.FilterCursor c.PaginationStyle = lipgloss.NewStyle() c.DefaultFilterCharacterMatch = ls.DefaultFilterCharacterMatch c.ActivePaginationDot = ls.ActivePaginationDot c.InactivePaginationDot = ls.InactivePaginationDot c.ArabicPagination = ls.ArabicPagination c.DividerDot = ls.DividerDot c.Description = lipgloss.NewStyle().Bold(true) c.PlaceholderDescription = lipgloss.NewStyle().Foreground(lipgloss.Color("240")) return c }() ``` -------------------------------- ### Check Empty Value Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns true if the input value is empty. ```go func (m *Model) EmptyValue() bool ``` -------------------------------- ### Model Struct Definition Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea The primary Bubble Tea model for the textarea component. ```go type Model struct { Err error // Prompt is printed at the beginning of each line. // // When changing the value of Prompt after the model has been // initialized, ensure that SetWidth() gets called afterwards. // // See also SetPromptFunc(). Prompt string // Placeholder is the text displayed when the user // hasn't entered anything yet. Placeholder string // ShowLineNumbers, if enabled, causes line numbers to be printed // after the prompt. ShowLineNumbers bool // EndOfBufferCharacter is displayed at the end of the input. EndOfBufferCharacter rune // KeyMap encodes the keybindings recognized by the widget. KeyMap KeyMap // Styling. FocusedStyle and BlurredStyle are used to style the textarea in // focused and blurred states. FocusedStyle Style BlurredStyle Style // Cursor is the text area cursor. Cursor cursor.Model // CharLimit is the maximum number of characters this input element will // accept. If 0 or less, there's no limit. CharLimit int // MaxHeight is the maximum height of the text area in rows. If 0 or less, // there's no limit. MaxHeight int // MaxWidth is the maximum width of the text area in columns. If 0 or less, // there's no limit. MaxWidth int // contains filtered or unexported fields } ``` -------------------------------- ### Define Editor Struct Source: https://pkg.go.dev/github.com/knz/bubbline The primary structure representing the input line editor. ```go type Editor struct { *editline.Model // contains filtered or unexported fields } ``` -------------------------------- ### (*Model) Reset() Source: https://pkg.go.dev/github.com/knz/bubbline/editline Resets the input to its default state while preserving the history. ```APIDOC ### func (*Model) Reset Sets the input to its default state with no input. #### Signature `func (m *Model) Reset()` ``` -------------------------------- ### Set text area value Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the current value of the text input. ```go func (m *Model) SetValue(s string) ``` -------------------------------- ### SetExternalEditorEnabled Method Source: https://pkg.go.dev/github.com/knz/bubbline/editline Configures the model to use an external editor via $EDITOR, with an optional file extension for syntax highlighting. ```go func (m *Model) SetExternalEditorEnabled(enable bool, extension string) ``` -------------------------------- ### func InputComplete Source: https://pkg.go.dev/github.com/knz/bubbline/editline Generates a message indicating input completion. ```APIDOC ## func InputComplete() tea.Msg ### Description Generates an InputCompleteMsg to signal that the user has finished input. ### Returns - **tea.Msg** (tea.Msg) - The completion message. ``` -------------------------------- ### Retrieve text area value Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current value of the text input as a string. ```go func (m Model) Value() string ``` -------------------------------- ### Width Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the width of the textarea. ```APIDOC ## func (Model) Width ### Description Width returns the width of the textarea. ### Signature `func (m Model) Width() int` ``` -------------------------------- ### Handle input completion message Source: https://pkg.go.dev/github.com/knz/bubbline/editline InputCompleteMsg is a signal type generated by the editor when input is finalized. ```go type InputCompleteMsg struct{} ``` -------------------------------- ### Flatten Function Source: https://pkg.go.dev/github.com/knz/bubbline/computil Converts a 2D rune representation and cursor position into a linear string and a 1D cursor index. ```go func Flatten(v [][]rune, line, col int) (string, int) ``` -------------------------------- ### Check Focused State Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current focus state of the model. ```go func (m Model) Focused() bool ``` -------------------------------- ### func (*Model) Value Source: https://pkg.go.dev/github.com/knz/bubbline/editline Retrieves the current text input value. ```APIDOC ## func (*Model) Value() string ### Description Value retrieves the value of the text input. ``` -------------------------------- ### SingleWordCompletion Source: https://pkg.go.dev/github.com/knz/bubbline/editline Turns a simple string into a Completions interface suitable to return from an AutoCompleteFn. ```APIDOC ## func SingleWordCompletion(word string, cursor, start, end int) Completions ### Description Turns a simple string into a Completions interface suitable to return from an AutoCompleteFn. The start/end positions refer to the word start and end positions on the current line. ### Parameters - **word** (string) - Required - The word to provide as a completion. - **cursor** (int) - Required - The current cursor position. - **start** (int) - Required - The start position of the word. - **end** (int) - Required - The end position of the word. ``` -------------------------------- ### FindLongestCommonPrefix Function Source: https://pkg.go.dev/github.com/knz/bubbline/computil Returns the longest common prefix between two strings, with an optional case-sensitivity toggle. ```go func FindLongestCommonPrefix(first, last string, caseSensitive bool) string ``` -------------------------------- ### SimpleWordsCompletion Source: https://pkg.go.dev/github.com/knz/bubbline/editline Turns an array of simple strings into a Completions interface suitable to return from an AutoCompleteFn. ```APIDOC ## func SimpleWordsCompletion(words []string, category string, cursor, start, end int) Completions ### Description Turns an array of simple strings into a Completions interface suitable to return from an AutoCompleteFn. The start/end positions refer to the word start and end positions on the current line. ### Parameters - **words** ([]string) - Required - The list of words to provide as completions. - **category** (string) - Required - The category for the completions. - **cursor** (int) - Required - The current cursor position. - **start** (int) - Required - The start position of the word. - **end** (int) - Required - The end position of the word. ``` -------------------------------- ### SetWidth Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the width of the textarea to fit exactly within the given width. ```APIDOC ## func (*Model) SetWidth ### Description Sets the width of the textarea to fit exactly within the given width. This accounts for the prompt width and line number visibility. Ensure this is called after setting the Prompt and ShowLineNumbers. ### Signature `func (m *Model) SetWidth(w int)` ``` -------------------------------- ### Value Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Returns the current value of the text input. ```APIDOC ## func (Model) Value ### Description Value returns the value of the text input. ### Signature `func (m Model) Value() string` ``` -------------------------------- ### Define text area styles Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Struct defining the styling applied to various components of the text area using Lip Gloss. ```go type Style struct { Base lipgloss.Style CursorLine lipgloss.Style CursorLineNumber lipgloss.Style EndOfBuffer lipgloss.Style LineNumber lipgloss.Style Placeholder lipgloss.Style Prompt lipgloss.Style Text lipgloss.Style } ``` -------------------------------- ### func (*Model) SetSize Source: https://pkg.go.dev/github.com/knz/bubbline/editline Updates the dimensions of the editor. ```APIDOC ## func (*Model) SetSize(width, height int) ### Description SetSize changes the size of the editor. NB: if one of the dimensions is zero, the call is a no-op. NB: it only takes effect at the first next event processed. ``` -------------------------------- ### Define DefaultKeyMap Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea The DefaultKeyMap variable defines the standard key bindings for navigation and text manipulation within the textarea model. ```go var DefaultKeyMap = KeyMap{ CharacterForward: key.NewBinding(key.WithKeys("right", "ctrl+f"), key.WithHelp("C-f/→", "next char")), CharacterBackward: key.NewBinding(key.WithKeys("left", "ctrl+b"), key.WithHelp("C-b/←", "prev char")), WordForward: key.NewBinding(key.WithKeys("alt+right", "ctrl+right", "alt+f"), key.WithHelp("M-f/C-→", "next word")), WordBackward: key.NewBinding(key.WithKeys("alt+left", "ctrl+left", "alt+b"), key.WithHelp("M-b/C-←", "prev word")), LineNext: key.NewBinding(key.WithKeys("down", "ctrl+n"), key.WithHelp("C-n/↓", "move down")), LinePrevious: key.NewBinding(key.WithKeys("up", "ctrl+p"), key.WithHelp("C-p/↑", "move up")), DeleteWordBackward: key.NewBinding(key.WithKeys("alt+backspace", "ctrl+w"), key.WithHelp("C-w/M-bksp", "del prev word")), DeleteWordForward: key.NewBinding(key.WithKeys("alt+delete", "alt+d"), key.WithHelp("M-d/M-del", "del next word")), DeleteAfterCursor: key.NewBinding(key.WithKeys("ctrl+k"), key.WithHelp("C-k", "del line end")), DeleteBeforeCursor: key.NewBinding(key.WithKeys("ctrl+u"), key.WithHelp("C-u", "del line start")), InsertNewline: key.NewBinding(key.WithKeys("enter", "ctrl+m", "ctrl+j"), key.WithHelp("C-m/⤶", "new line/enter")), DeleteCharacterBackward: key.NewBinding(key.WithKeys("backspace", "ctrl+h"), key.WithHelp("C-h/bksp", "del prev char")), DeleteCharacterForward: key.NewBinding(key.WithKeys("delete", "ctrl+d"), key.WithHelp("C-d/del", "del next char")), LineStart: key.NewBinding(key.WithKeys("home", "ctrl+a"), key.WithHelp("C-a/home", "start of line")), LineEnd: key.NewBinding(key.WithKeys("end", "ctrl+e"), key.WithHelp("C-e/end", "end of line")), Paste: key.NewBinding(key.WithKeys("ctrl+v"), key.WithHelp("C-v", "paste")), InputBegin: key.NewBinding(key.WithKeys("alt+<", "ctrl+home"), key.WithHelp("M-", "ctrl+end"), key.WithHelp("M->/C-end", "go to end")), ``` -------------------------------- ### Reset Viewport Cursor Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Scrolls the viewport to position the cursor on the bottom line. ```go func (m Model) ResetViewCursorDown() ``` -------------------------------- ### Move Cursor Right Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor to the right by the specified number of positions. ```go func (m *Model) CursorRight(n int) ``` -------------------------------- ### Retrieve text area value as runes Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Retrieves the current value decomposed as a slice of rune slices. ```go func (m *Model) ValueRunes() [][]rune ``` -------------------------------- ### Define Error Variables Source: https://pkg.go.dev/github.com/knz/bubbline Error constants used to signal interruption or termination of the input process. ```go var ErrInterrupted = editline.ErrInterrupted ``` ```go var ErrTerminated = errors.New("terminated") ``` -------------------------------- ### func (*Editor) SetAutoSaveHistory(file string, autoSave bool) Source: https://pkg.go.dev/github.com/knz/bubbline Configures auto-saving for history. ```APIDOC ## func (*Editor) SetAutoSaveHistory(file string, autoSave bool) ### Description SetAutoSaveHistory enables/disables auto-saving of entered lines to the history. ### Parameters - **file** (string) - Required - The file path for auto-saving. - **autoSave** (bool) - Required - Whether to enable auto-saving. ``` -------------------------------- ### SetValue Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Sets the value of the text input. ```APIDOC ## func (*Model) SetValue ### Description Sets the value of the text input. ### Signature `func (m *Model) SetValue(s string)` ``` -------------------------------- ### Move Cursor Down Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor down one line and returns whether the blink state should be reset. ```go func (m *Model) CursorDown() ``` -------------------------------- ### Move Cursor to End Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor to the end of the input field. ```go func (m *Model) CursorEnd() ``` -------------------------------- ### func (*Editor) SaveHistory() error Source: https://pkg.go.dev/github.com/knz/bubbline Saves the current history to a file. ```APIDOC ## func (*Editor) SaveHistory() error ### Description SaveHistory saves the current history to the file previously configured with SetAutoSaveHistory. ``` -------------------------------- ### Update text area state Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Standard Bubble Tea update loop for the model. ```go func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) ``` -------------------------------- ### Set Cursor Position Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Moves the cursor to a specific column, clamping to bounds if necessary. ```go func (m *Model) SetCursor(col int) ``` -------------------------------- ### ValueRunes Source: https://pkg.go.dev/github.com/knz/bubbline/editline/internal/textarea Retrieves the current value decomposed as runes. ```APIDOC ## func (*Model) ValueRunes ### Description ValueRunes retrieves the current value decomposed as runes. ### Signature `func (m *Model) ValueRunes() [][]rune` ```