ui

package
v0.0.0-...-74c0925 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 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 {
	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 Keymap

type Keymap struct {
	// contains filtered or unexported fields
}

func NewKeymap

func NewKeymap() *Keymap

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

func (m *Textarea) 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 (*Textarea) Focused

func (m *Textarea) Focused() bool

Focused returns the focus state on the model.

func (*Textarea) Height

func (m *Textarea) Height() int

Height returns the current height of the textarea.

func (*Textarea) LineInfo

func (m *Textarea) LineInfo() LineInfo

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

func (*Textarea) MoveDown

func (m *Textarea) MoveDown()

func (*Textarea) MoveUp

func (m *Textarea) MoveUp()

func (*Textarea) Reset

func (m *Textarea) Reset()

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

func (*Textarea) SetCursor

func (m *Textarea) 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 (*Textarea) SetDocument

func (m *Textarea) SetDocument(document *views.Document)

func (*Textarea) SetHeight

func (m *Textarea) SetHeight(h int)

SetHeight sets the height of the textarea.

func (*Textarea) SetWidth

func (m *Textarea) 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, If it important that the width of the textarea be exactly the given width and no more.

func (*Textarea) Update

func (m *Textarea) Update(msg tea.Msg) (*Textarea, tea.Cmd)

Update is the Bubble Tea update loop.

func (*Textarea) View

func (m *Textarea) View() string

View renders the text area in its current state.

func (*Textarea) Width

func (m *Textarea) Width() int

Width returns the width of the textarea.

type Ui

type Ui struct {
	Program *tea.Program
	Keymap  *Keymap
	// contains filtered or unexported fields
}

func New

func New(cfg *config.Config) *Ui

func (*Ui) Init

func (u *Ui) Init() tea.Cmd

func (*Ui) Update

func (u *Ui) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Ui) View

func (u *Ui) View() string

Jump to

Keyboard shortcuts

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