Documentation ¶
Index ¶
- Variables
- func Blink() tea.Msg
- func DefaultStyles() (Style, Style)
- func Paste() tea.Msg
- type KeyMap
- type LineInfo
- type Model
- func (m *Model) AtBeginningOfEmptyLine() bool
- func (m *Model) AtFirstLineOfInputAndView() bool
- func (m *Model) AtLastLineOfInputAndView() bool
- func (m *Model) Blur()
- func (m *Model) ClearLine()
- func (m *Model) CurrentLine() string
- func (m *Model) CursorDown()
- func (m *Model) CursorEnd()
- func (m *Model) CursorPos() int
- func (m *Model) CursorRight(n int)
- func (m *Model) CursorStart()
- func (m *Model) CursorUp()
- func (m Model) Debug() string
- func (m *Model) DeleteCharacterForward()
- func (m *Model) DeleteCharactersBackward(n int)
- func (m *Model) EmptyValue() bool
- func (m *Model) Focus() tea.Cmd
- func (m Model) Focused() bool
- func (m Model) Height() int
- func (m *Model) InsertNewline()
- func (m *Model) InsertRune(r rune)
- func (m *Model) InsertString(s string)
- func (m *Model) Length() int
- func (m Model) Line() int
- func (m *Model) LineCount() int
- func (m Model) LineInfo() LineInfo
- func (m Model) LineInfoAt(row, col int) LineInfo
- func (m Model) LogicalHeight() int
- func (m *Model) MoveTo(row, col int)
- func (m *Model) NumLinesInValue() int
- func (m *Model) Reset()
- func (m Model) ResetViewCursorDown()
- func (m *Model) SetCursor(col int)
- func (m *Model) SetHeight(h int)
- func (m *Model) SetPromptFunc(promptWidth int, fn func(lineIdx int) string)
- func (m *Model) SetValue(s string)
- func (m *Model) SetWidth(w int)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) Value() string
- func (m *Model) ValueRunes() [][]rune
- func (m Model) View() string
- func (m Model) Width() int
- type Style
Constants ¶
This section is empty.
Variables ¶
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-</C-home", "go to begin")), InputEnd: key.NewBinding(key.WithKeys("alt+>", "ctrl+end"), key.WithHelp("M->/C-end", "go to end")), 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")), }
DefaultKeyMap is the default set of key bindings for navigating and acting upon the textarea.
Functions ¶
func DefaultStyles ¶
DefaultStyles returns the default styles for focused and blurred states for the textarea.
Types ¶
type KeyMap ¶
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 }
KeyMap is the key bindings for different actions within the textarea.
type LineInfo ¶
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 }
LineInfo is a helper for keeping track of line information regarding soft-wrapped lines.
type Model ¶
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 }
Model is the Bubble Tea model for this text area element.
func (*Model) AtBeginningOfEmptyLine ¶
AtBeginningOfLine returns true if the cursor is at the beginning of an empty line line.
func (*Model) AtFirstLineOfInputAndView ¶
AtFirstLineOfInputAndView returns true if the cursor is on the first line of the input and viewport.
func (*Model) AtLastLineOfInputAndView ¶
AtEndOfInput returns true if the cursor is on the last line of the input and viewport.
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) CurrentLine ¶
CurrentLine retrieves the current line as a string.
func (*Model) CursorDown ¶
func (m *Model) CursorDown()
CursorDown moves the cursor down by one line. Returns whether or not the cursor blink should be reset.
func (*Model) CursorEnd ¶
func (m *Model) CursorEnd()
CursorEnd moves the cursor to the end of the input field.
func (*Model) CursorRight ¶
CursorRight moves the cursor to the right by the specified amount.
func (*Model) CursorStart ¶
func (m *Model) CursorStart()
CursorStart moves the cursor to the start of the input field.
func (*Model) DeleteCharacterForward ¶
func (m *Model) DeleteCharacterForward()
DeleteCharacterForward deletes the character at the cursor.
func (*Model) DeleteCharactersBackward ¶
DeleteCharactersBackward deletes n characters before the cursor.
func (*Model) EmptyValue ¶
EmptyValue returns true iff the value is empty.
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 will be hidden.
func (*Model) InsertNewline ¶
func (m *Model) InsertNewline()
InsertNewline inserts a newline character at the cursor.
func (*Model) InsertRune ¶
InsertRune inserts a rune at the cursor position.
func (*Model) InsertString ¶
InsertString inserts a string at the cursor position.
func (*Model) LineCount ¶
LineCount returns the number of lines that are currently in the text input.
func (Model) LineInfo ¶
LineInfo returns the number of characters from the start of the (soft-wrapped) line and the (soft-wrapped) line width.
func (Model) LineInfoAt ¶
LineInfoAt computes the LineInfo at the specified row/column. The caller is responsible for keeping row/col within bounds.
func (Model) LogicalHeight ¶
LogicalHeight returns the number of lines needed in a viewport to show the entire value.
func (*Model) NumLinesInValue ¶
NumLinesInValue returns the number of logical lines in the value.
func (*Model) Reset ¶
func (m *Model) Reset()
Reset sets the input to its default state with no input.
func (Model) ResetViewCursorDown ¶
func (m Model) ResetViewCursorDown()
ResetViewCursorDown scrolls the viewport so that the cursor is position on the bottom line.
func (*Model) SetCursor ¶
SetCursor moves the cursor to the given position. If the position is out of bounds the cursor will be moved to the start or end accordingly.
func (*Model) SetPromptFunc ¶
SetPromptFunc supersedes the Prompt field and sets a dynamic prompt instead. If the function returns a prompt that is shorter than the specified promptWidth, it will be padded to the left. If it returns a prompt that is longer, display artifacts may occur; the caller is responsible for computing an adequate promptWidth.
func (*Model) SetWidth ¶
SetWidth sets the width of the textarea to fit exactly within the given width. This means that the textarea will account for the width of the prompt and whether or not line numbers are being shown.
Ensure that SetWidth is called after setting the Prompt and ShowLineNumbers, It is important that the width of the textarea be exactly the given width and no more.
func (*Model) ValueRunes ¶
ValueRunes retrieves the current value decomposed as runes.
type Style ¶
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 }
Style that will be applied to the text area.
Style can be applied to focused and unfocused states to change the styles depending on the focus state.
For an introduction to styling with Lip Gloss see: https://github.com/charmbracelet/lipgloss