shellinput

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

This file is forked from the textinput component from github.com/charmbracelet/bubbles

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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", "ctrl+right", "alt+f")),
	WordBackward:            key.NewBinding(key.WithKeys("alt+left", "ctrl+left", "alt+b")),
	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")),
	DeleteCharacterBackward: key.NewBinding(key.WithKeys("backspace", "ctrl+h")),
	Complete:                key.NewBinding(key.WithKeys("tab")),
	PrevSuggestion:          key.NewBinding(key.WithKeys("shift+tab")),
	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")),
	Yank:                    key.NewBinding(key.WithKeys("ctrl+y")),
	YankPop:                 key.NewBinding(key.WithKeys("alt+y")),
	NextValue:               key.NewBinding(key.WithKeys("down", "ctrl+n")),
	PrevValue:               key.NewBinding(key.WithKeys("up", "ctrl+p")),
	ClearScreen:             key.NewBinding(key.WithKeys("ctrl+l")),
	ReverseSearch:           key.NewBinding(key.WithKeys("ctrl+r")),
	HistorySort:             key.NewBinding(key.WithKeys("ctrl+o")),
	SwapCharacters:          key.NewBinding(key.WithKeys("ctrl+t")),
	SwapWords:               key.NewBinding(key.WithKeys("alt+t")),
	InsertLastArg:           key.NewBinding(key.WithKeys("alt+.")),
}

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

Functions

func Blink() tea.Msg

Blink is a command used to initialize cursor blinking.

func GetLastArgument added in v0.30.0

func GetLastArgument(line string) string

func Paste

func Paste() tea.Msg

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

Types

type CompletionCandidate

type CompletionCandidate struct {
	Value       string // The actual value to insert
	Display     string // What to show in the list (if different from Value)
	Description string // The description to show in the right column
	Suffix      string // Optional suffix to show as greyed-out inline suggestion (e.g., "/" for directories)
}

CompletionCandidate represents a single completion suggestion

type CompletionProvider

type CompletionProvider interface {
	// GetCompletions returns a list of completion suggestions for the current input
	// line and cursor position
	GetCompletions(line string, pos int) []CompletionCandidate

	// GetHelpInfo returns help information for special commands like #! and #/
	// Returns empty string if no help is available
	GetHelpInfo(line string, pos int) string
}

CompletionProvider is the interface that provides completion suggestions

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 HistoryFilterMode

type HistoryFilterMode int

HistoryFilterMode defines the scope of history search

const (
	HistoryFilterAll HistoryFilterMode = iota
	HistoryFilterDirectory
	HistoryFilterSession
)

func (HistoryFilterMode) String

func (m HistoryFilterMode) String() string

type HistoryItem

type HistoryItem struct {
	Command   string
	Directory string
	Timestamp time.Time
	SessionID string
}

HistoryItem represents a single command history entry with metadata

type HistorySortMode

type HistorySortMode int

HistorySortMode defines the sort order of history search results

const (
	HistorySortRecent HistorySortMode = iota
	HistorySortRelevance
	HistorySortAlphabetical
)

func (HistorySortMode) String

func (m HistorySortMode) String() string

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
	Yank                    key.Binding
	YankPop                 key.Binding
	NextValue               key.Binding
	PrevValue               key.Binding
	Complete                key.Binding
	PrevSuggestion          key.Binding
	ClearScreen             key.Binding
	ReverseSearch           key.Binding
	HistorySort             key.Binding
	SwapCharacters          key.Binding
	SwapWords               key.Binding
	InsertLastArg           key.Binding
}

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

type Model

type Model struct {
	Err error

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

	// Completion settings
	CompletionProvider CompletionProvider

	// 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
	CompletionStyle          lipgloss.Style
	ReverseSearchPromptStyle lipgloss.Style

	// Deprecated: use Cursor.Style instead.
	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 marks the horizontal boundary for this component to render within.
	// Content that exceeds this width will be wrapped.
	// 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

	// Should the input suggest to complete
	ShowSuggestions bool
	// 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) AvailableSuggestions

func (m *Model) AvailableSuggestions() []string

AvailableSuggestions returns the list of available suggestions.

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

func (m Model) CompletionBoxView(height int, width int) string

CompletionBoxView renders the completion info box with all available completions CompletionBoxView renders the completion info box with all available completions

func (*Model) CurrentSuggestion

func (m *Model) CurrentSuggestion() string

CurrentSuggestion returns the currently selected suggestion.

func (*Model) CurrentSuggestionIndex

func (m *Model) CurrentSuggestionIndex() int

CurrentSuggestion returns the currently selected suggestion index.

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

func (m Model) HelpBoxView() string

func (Model) HistorySearchBoxView

func (m Model) HistorySearchBoxView(height, width int) string

HistorySearchBoxView renders the history search box

func (Model) InReverseSearch

func (m Model) InReverseSearch() bool

InReverseSearch returns true if the input is currently in reverse search mode.

func (*Model) MatchedSuggestions

func (m *Model) MatchedSuggestions() []string

MatchedSuggestions returns the list of matched suggestions.

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

func (m *Model) SetCurrentDirectory(dir string)

SetCurrentDirectory sets the current directory for filtering history

func (*Model) SetCurrentSessionID added in v0.30.0

func (m *Model) SetCurrentSessionID(id string)

SetCurrentSessionID sets the current session ID for filtering history

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

func (m *Model) SetHistoryValues(historyValues []string)

SetHistoryValues sets the suggestions for the input.

func (*Model) SetRichHistory

func (m *Model) SetRichHistory(items []HistoryItem)

SetRichHistory sets the history items for the rich search

func (*Model) SetSuggestions

func (m *Model) SetSuggestions(suggestions []string)

SetSuggestions sets the suggestions for the input.

func (*Model) SetValue

func (m *Model) SetValue(s string)

SetValue sets the value of the text input.

func (Model) SuggestionsSuppressedUntilInput

func (m Model) SuggestionsSuppressedUntilInput() bool

SuggestionsSuppressedUntilInput reports whether autocomplete hints are temporarily disabled until the user provides additional input (for example after a kill command like Ctrl+K).

func (Model) Update

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

Update is the Bubble Tea update loop.

func (*Model) UpdateHelpInfo

func (m *Model) UpdateHelpInfo()

UpdateHelpInfo is the exported wrapper for refreshes triggered outside the shellinput package.

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