Documentation ¶
Index ¶
- Variables
- func Blink() tea.Msg
- func DefaultStyles() (Style, Style)
- func Paste() tea.Msg
- type KeyMap
- type Keymap
- type LineInfo
- type Style
- type Textarea
- func (m *Textarea) Blur()
- func (m *Textarea) CursorEnd()
- func (m *Textarea) CursorStart()
- func (m *Textarea) Focus() tea.Cmd
- func (m *Textarea) Focused() bool
- func (m *Textarea) Height() int
- func (m *Textarea) LineInfo() LineInfo
- func (m *Textarea) MoveDown()
- func (m *Textarea) MoveUp()
- func (m *Textarea) Reset()
- func (m *Textarea) SetCursor(col int)
- func (m *Textarea) SetDocument(document *views.Document)
- func (m *Textarea) SetHeight(h int)
- func (m *Textarea) SetWidth(w int)
- func (m *Textarea) Update(msg tea.Msg) (*Textarea, tea.Cmd)
- func (m *Textarea) View() string
- func (m *Textarea) Width() int
- type Ui
Constants ¶
This section is empty.
Variables ¶
var DefaultKeyMap = KeyMap{ MoveRight: key.NewBinding(key.WithKeys("right", "ctrl+f")), MoveLeft: key.NewBinding(key.WithKeys("left", "ctrl+b")), WordRight: key.NewBinding(key.WithKeys("alt+right", "alt+f")), WordLeft: key.NewBinding(key.WithKeys("alt+left", "alt+b")), MoveDown: key.NewBinding(key.WithKeys("down", "ctrl+n")), MoveUp: key.NewBinding(key.WithKeys("up", "ctrl+p")), DeleteWordBackward: key.NewBinding(key.WithKeys("alt+backspace", "ctrl+w")), DeleteWordForward: key.NewBinding(key.WithKeys("alt+delete", "alt+d")), DeleteAfterCursor: key.NewBinding(key.WithKeys("ctrl+k")), DeleteBeforeCursor: key.NewBinding(key.WithKeys("ctrl+u")), InsertNewline: key.NewBinding(key.WithKeys("enter", "ctrl+m")), DeleteCharacterBackward: key.NewBinding(key.WithKeys("backspace", "ctrl+h")), DeleteCharacterForward: key.NewBinding(key.WithKeys("delete", "ctrl+d")), LineStart: key.NewBinding(key.WithKeys("home", "ctrl+a")), LineEnd: key.NewBinding(key.WithKeys("end", "ctrl+e")), Paste: key.NewBinding(key.WithKeys("ctrl+v")), }
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 { MoveLeft key.Binding MoveRight 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 MoveDown key.Binding MoveUp key.Binding LineStart key.Binding Paste key.Binding WordLeft key.Binding WordRight 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 Style ¶
type Style struct { Base lipgloss.Style CursorLineNumber lipgloss.Style EndOfBuffer lipgloss.Style LineNumber 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
type Textarea ¶
type Textarea struct { Err error // General settings. ShowLineNumbers bool EndOfBufferCharacter rune 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 // contains filtered or unexported fields }
Textarea is the Bubble Tea model for this text area element.
func NewTextArea ¶
func NewTextArea() *Textarea
NewTextArea creates a new model with default settings.
func (*Textarea) Blur ¶
func (m *Textarea) 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 (*Textarea) CursorEnd ¶
func (m *Textarea) CursorEnd()
CursorEnd moves the cursor to the end of the input field.
func (*Textarea) CursorStart ¶
func (m *Textarea) CursorStart()
CursorStart moves the cursor to the start of the input field.
func (*Textarea) 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 (*Textarea) LineInfo ¶
LineInfo returns the number of characters from the start of the (soft-wrapped) line and the (soft-wrapped) line width.
func (*Textarea) Reset ¶
func (m *Textarea) Reset()
Reset sets the input to its default state with no input.
func (*Textarea) 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 (*Textarea) SetDocument ¶
func (*Textarea) 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, If it important that the width of the textarea be exactly the given width and no more.