Documentation
¶
Index ¶
- Variables
- func DefaultStyles() (Style, Style)
- func InputComplete() tea.Msg
- type AutoCompleteFn
- type Candidate
- type Completions
- func SimpleWordsCompletion(words []string, category string, cursor, start, end int) Completions
- func SimpleWordsCompletionWithDescriptions(words []string, descriptions []string, category string, cursor, start, end int) Completions
- func SingleWordCompletion(word string, cursor, start, end int) Completions
- type HistoryEntry
- type InputCompleteMsg
- type KeyMap
- type Model
- func (m *Model) AddHistoryEntry(s string)
- func (m *Model) Blur()
- func (m *Model) Debug() string
- func (m *Model) Focus() tea.Cmd
- func (m Model) FullHelp() [][]key.Binding
- func (m *Model) GetHistory() []HistoryEntry
- func (m *Model) GetNewHistory() []HistoryEntry
- func (m *Model) Init() tea.Cmd
- func (m *Model) MarkHistorySaved()
- func (m *Model) Reset()
- func (m *Model) SetDebugEnabled(enable bool)
- func (m *Model) SetExternalEditorEnabled(enable bool, extension string)
- func (m *Model) SetHelpDisabled(disabled bool)
- func (m *Model) SetHighlighter(highlighter func(string) string)
- func (m *Model) SetHistory(h []HistoryEntry)
- func (m *Model) SetSize(width, height int)
- func (m Model) ShortHelp() []key.Binding
- func (m *Model) Update(imsg tea.Msg) (*Model, tea.Cmd)
- func (m *Model) Value() string
- func (m Model) View() string
- func (m *Model) Write(text string) tea.Cmd
- func (m *Model) WriteRune(r rune) tea.Cmd
- type Style
Constants ¶
This section is empty.
Variables ¶
var DefaultKeyMap = KeyMap{ KeyMap: textarea.DefaultKeyMap, 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")), Clear: key.NewBinding(key.WithKeys("ctrl+k"), key.WithHelp("C-k", "clear screen")), 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()), MoreHelp: key.NewBinding(key.WithKeys("ctrl+h"), key.WithHelp("C-h", "toggle key help")), Debug: key.NewBinding(key.WithKeys("ctrl+_", "ctrl+@"), key.WithHelp("C-_/C-@", "debug mode"), key.WithDisabled()), ExternalEdit: key.NewBinding(key.WithKeys("ctrl+o"), key.WithHelp("C-.", "external edit")), }
DefaultKeyMap is the default set of key bindings.
var ErrInterrupted = errors.New("interrupted")
ErrInterrupted is returned when the input is terminated with Ctrl+C.
Functions ¶
func DefaultStyles ¶
DefaultStyles returns the default styles for focused and blurred states for the textarea.
Types ¶
type AutoCompleteFn ¶
type AutoCompleteFn func(entireInput [][]rune, line, col int) (msg string, comp Completions)
AutoCompleteFn is called upon the user pressing the autocomplete key. The callback is provided the text of the input and the position of the cursor in the input. The returned msg is printed above the input box.
type Candidate ¶
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
}
Candidate is the type of one completion candidate.
type Completions ¶
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
}
Completions is the return value of AutoCompleteFn.
func SimpleWordsCompletion ¶
func SimpleWordsCompletion(words []string, category string, cursor, start, end int) Completions
SimpleWordsCompletion 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.
func SimpleWordsCompletionWithDescriptions ¶
func SimpleWordsCompletionWithDescriptions(words []string, descriptions []string, category string, cursor, start, end int) Completions
SimpleWordsCompletionWithDescriptions turns arrays of strings and descriptions 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. Each word can have an optional description.
func SingleWordCompletion ¶
func SingleWordCompletion(word string, cursor, start, end int) Completions
SingleWordCompletion 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.
type HistoryEntry ¶
type InputCompleteMsg ¶
type InputCompleteMsg struct{}
InputCompleteMsg is generated by the editor when the input is complete.
type KeyMap ¶
type KeyMap struct {
textarea.KeyMap
EndOfInput key.Binding
Interrupt key.Binding
AutoComplete key.Binding
SignalQuit key.Binding
SignalTTYStop key.Binding
Refresh key.Binding
Clear key.Binding
AbortSearch key.Binding
SearchBackward key.Binding
HistoryPrevious key.Binding
HistoryNext key.Binding
Debug key.Binding
HideShowPrompt key.Binding
MoreHelp key.Binding
ExternalEdit key.Binding
}
KeyMap is the key bindings for actions within the editor.
type Model ¶
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
// Highlighter is an optional function that applies syntax highlighting
// to the input text. It receives the entire input string and returns
// a highlighted version with ANSI escape codes.
Highlighter func(string) string
// 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
// AutoComplete is the AutoCompleteFn to use.
AutoComplete AutoCompleteFn
// AddSpaceAfterCompletion, if true, adds a trailing space after
// accepting a completion. Default is true for backward compatibility.
AddSpaceAfterCompletion bool
// 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
// 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
}
Model represents a widget that supports multi-line entry with auto-growing of the text height.
func (*Model) AddHistoryEntry ¶
AddHistoryEntry adds an entry to the history navigation list.
func (*Model) Blur ¶
func (m *Model) Blur()
Blur removes the focus state on the model. When the model is blurred it can not receive keyboard input and the cursor will be hidden.
func (*Model) Focus ¶
Focus sets the focus state on the model. When the model is in focus it can receive keyboard input and the cursor is displayed.
func (*Model) GetHistory ¶
func (m *Model) GetHistory() []HistoryEntry
GetHistory retrieves all the entries in the history navigation list.
func (*Model) GetNewHistory ¶
func (m *Model) GetNewHistory() []HistoryEntry
GetNewHistory retrieves only the entries added since the last call to MarkHistorySaved (or since SetHistory was called).
func (*Model) MarkHistorySaved ¶
func (m *Model) MarkHistorySaved()
MarkHistorySaved marks all current history entries as saved, so they won't be returned by subsequent calls to GetNewHistory.
func (*Model) Reset ¶
func (m *Model) Reset()
Reset sets the input to its default state with no input. The history is preserved.
func (*Model) SetDebugEnabled ¶
SetDebugEnabled enables/disables the debug mode binding. When disabling it, it also proactively disables debugging if currently enabled.
func (*Model) SetExternalEditorEnabled ¶
SetExternalEditorEnabled enables using an external editor (via $EDITOR). The extension is added to the generated file name so that the editor can auto-select a language for syntax highlighting. If the extension is left empty, "txt" is assumed.
func (*Model) SetHelpDisabled ¶
SetHelpDisabled conditionally disables the help status bar at the bottom.
func (*Model) SetHighlighter ¶
SetHighlighter sets a function that will be used to apply syntax highlighting to the input text. The function should receive the entire input text and return a highlighted version. Pass nil to disable highlighting.
func (*Model) SetHistory ¶
func (m *Model) SetHistory(h []HistoryEntry)
SetHistory sets the history navigation list all at once.
func (*Model) SetSize ¶
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.
func (*Model) Update ¶
Update is the Bubble Tea event handler. This is part of the tea.Model interface.
func (Model) View ¶
View renders the text area in its current state. This is part of the tea.Model interface.