textinput

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Deprecated: use cursor.CursorBlink.
	CursorBlink = CursorMode(cursor.CursorBlink)
	// Deprecated: use cursor.CursorStatic.
	CursorStatic = CursorMode(cursor.CursorStatic)
	// Deprecated: use cursor.CursorHide.
	CursorHide = CursorMode(cursor.CursorHide)
)

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")),
	DeleteWordBackward:      key.NewBinding(key.WithKeys("alt+backspace", "ctrl+w")),
	DeleteWordForward:       key.NewBinding(key.WithKeys("alte+delete", "alt+d")),
	DeleteAfterCursor:       key.NewBinding(key.WithKeys("ctrl+k")),
	DeleteBeforeCursor:      key.NewBinding(key.WithKeys("ctrl+u")),
	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 textinput.

View Source
var NewModel = New

NewModel creates a new model with default settings.

Deprecated: Use New instead.

Functions

func Blink() tea.Msg

Blink is a command used to initialize cursor blinking.

func Paste

func Paste() tea.Msg

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

Types

type CursorMode deprecated

type CursorMode int

Deprecated: use cursor.Mode.

func (CursorMode) String

func (c CursorMode) String() string

type EchoMode

type EchoMode int

EchoMode sets the input behavior of the text input field.

const (
	// EchoNormal displays text as is. This is the default behavior.
	EchoNormal EchoMode = iota

	// EchoPassword displays the EchoCharacter mask instead of actual
	// characters. This is commonly used for password fields.
	EchoPassword

	// EchoNone displays nothing as characters are entered. This is commonly
	// seen for password fields on the command line.
	EchoNone
)

type KeyMap

type KeyMap struct {
	CharacterForward        key.Binding
	CharacterBackward       key.Binding
	WordForward             key.Binding
	WordBackward            key.Binding
	DeleteWordBackward      key.Binding
	DeleteWordForward       key.Binding
	DeleteAfterCursor       key.Binding
	DeleteBeforeCursor      key.Binding
	DeleteCharacterBackward key.Binding
	DeleteCharacterForward  key.Binding
	LineStart               key.Binding
	LineEnd                 key.Binding
	Paste                   key.Binding
}

KeyMap is the key bindings for different actions within the textinput.

type Model

type Model struct {
	Err error

	// General settings.
	Prompt        string
	Placeholder   string
	EchoMode      EchoMode
	EchoCharacter rune
	Cursor        cursor.Model

	// Deprecated: use [cursor.BlinkSpeed] instead.
	BlinkSpeed time.Duration

	// Styles. These will be applied as inline styles.
	//
	// For an introduction to styling with Lip Gloss see:
	// https://github.com/charmbracelet/lipgloss
	PromptStyle      lipgloss.Style
	TextStyle        lipgloss.Style
	PlaceholderStyle lipgloss.Style
	CursorStyle      lipgloss.Style

	// CharLimit is the maximum amount of characters this input element will
	// accept. If 0 or less, there's no limit.
	CharLimit int

	// Width is the maximum number of characters that can be displayed at once.
	// It essentially treats the text field like a horizontally scrolling
	// viewport. If 0 or less this setting is ignored.
	Width int

	// KeyMap encodes the keybindings recognized by the widget.
	KeyMap KeyMap

	// Validate is a function that checks whether or not the text within the
	// input is valid. If it is not valid, the `Err` field will be set to the
	// error returned by the function. If the function is not defined, all
	// input is considered valid.
	Validate ValidateFunc
	// contains filtered or unexported fields
}

Model is the Bubble Tea model for this text input 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) CursorEnd

func (m *Model) CursorEnd()

CursorEnd moves the cursor to the end of the input field.

func (Model) CursorMode deprecated

func (m Model) CursorMode() CursorMode

Deprecated: use cursor.Mode().

func (*Model) CursorStart

func (m *Model) CursorStart()

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

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 shown.

func (Model) Focused

func (m Model) Focused() bool

Focused returns the focus state on the model.

func (Model) Position

func (m Model) Position() int

Position returns the cursor position.

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(pos 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) SetCursorMode deprecated

func (m *Model) SetCursorMode(mode CursorMode) tea.Cmd

Deprecated: use cursor.SetMode().

func (*Model) SetValue

func (m *Model) SetValue(s string)

SetValue sets the value of the text input.

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 textinput in its current state.

type ValidateFunc

type ValidateFunc func(string) error

ValidateFunc is a function that returns an error if the input is invalid.

Jump to

Keyboard shortcuts

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