textarea

package
v0.0.0-...-5ccc2a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultKeyMap = KeyMap{
	CharacterForward:        key.NewBinding(key.WithKeys("right", "ctrl+f")),
	CharacterBackward:       key.NewBinding(key.WithKeys("left", "ctrl+b")),
	WordForward:             key.NewBinding(key.WithKeys("alt+right", "alt+f")),
	WordBackward:            key.NewBinding(key.WithKeys("alt+left", "alt+b")),
	LineNext:                key.NewBinding(key.WithKeys("down", "ctrl+n")),
	LinePrevious:            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")),
	InputBegin:              key.NewBinding(key.WithKeys("alt+<", "ctrl+home")),
	InputEnd:                key.NewBinding(key.WithKeys("alt+>", "ctrl+end")),

	CapitalizeWordForward: key.NewBinding(key.WithKeys("alt+c")),
	LowercaseWordForward:  key.NewBinding(key.WithKeys("alt+l")),
	UppercaseWordForward:  key.NewBinding(key.WithKeys("alt+u")),

	TransposeCharacterBackward: key.NewBinding(key.WithKeys("ctrl+t")),
}

DefaultKeyMap is the default set of key bindings for navigating and acting upon the textarea.

Functions

func Blink() tea.Msg

Blink returns the blink command for the cursor.

func DefaultStyles

func DefaultStyles() (Style, Style)

DefaultStyles returns the default styles for focused and blurred states for the textarea.

func Paste

func Paste() tea.Msg

Paste is a command for pasting from the clipboard into the text input.

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

	UppercaseWordForward  key.Binding
	LowercaseWordForward  key.Binding
	CapitalizeWordForward key.Binding

	TransposeCharacterBackward 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
	// contains filtered or unexported fields
}

Model is the Bubble Tea model for this text area element.

func New

func New() Model

New creates a new model with default settings.

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) 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) CursorStart

func (m *Model) CursorStart()

CursorStart moves the cursor to the start of the input field.

func (*Model) CursorUp

func (m *Model) CursorUp()

CursorUp moves the cursor up by one line.

func (*Model) Focus

func (m *Model) Focus() tea.Cmd

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) Focused

func (m Model) Focused() bool

Focused returns the focus state on the model.

func (Model) Height

func (m Model) Height() int

Height returns the current height of the textarea.

func (*Model) InsertRune

func (m *Model) InsertRune(r rune)

InsertRune inserts a rune at the cursor position.

func (*Model) InsertString

func (m *Model) InsertString(s string)

InsertString inserts a string at the cursor position.

func (*Model) Length

func (m *Model) Length() int

Length returns the number of characters currently in the text input.

func (Model) Line

func (m Model) Line() int

Line returns the line position.

func (*Model) LineCount

func (m *Model) LineCount() int

LineCount returns the number of lines that are currently in the text input.

func (Model) LineInfo

func (m Model) LineInfo() LineInfo

LineInfo returns the number of characters from the start of the (soft-wrapped) line and the (soft-wrapped) line width.

func (*Model) Reset

func (m *Model) Reset()

Reset sets the input to its default state with no input.

func (*Model) SetCursor

func (m *Model) SetCursor(col int)

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) SetHeight

func (m *Model) SetHeight(h int)

SetHeight sets the height of the textarea.

func (*Model) SetPromptFunc

func (m *Model) SetPromptFunc(promptWidth int, fn func(lineIdx int) string)

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) SetValue

func (m *Model) SetValue(s string)

SetValue sets the value of the text input.

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

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) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

Update is the Bubble Tea update loop.

func (Model) Value

func (m Model) Value() string

Value returns the value of the text input.

func (Model) View

func (m Model) View() string

View renders the text area in its current state.

func (Model) Width

func (m Model) Width() int

Width returns the width of the textarea.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL