core

package
v1.88.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyScrollMap = map[string]ScrollDirection{
	"up":     ScrollUp,
	"k":      ScrollUp,
	"down":   ScrollDown,
	"j":      ScrollDown,
	"pgup":   ScrollPageUp,
	"pgdown": ScrollPageDown,
	"home":   ScrollToTop,
	"end":    ScrollToBottom,
}

KeyScrollMap maps common scroll keys to directions

View Source
var NavigationKeys = []string{"up", "down", "left", "right", "enter", "esc"}

NavigationKeys are common keys used for navigation that components might want to handle. Note: vim-style keys (h, j, k, l) are intentionally excluded to avoid conflicts with typing in completion popups where users need to type those letters.

Functions

func CmdHandler

func CmdHandler(msg tea.Msg) tea.Cmd

CmdHandler creates a command that returns the given message

func IsNavigationKey

func IsNavigationKey(msg tea.KeyPressMsg) bool

IsNavigationKey returns true if the key is a common navigation key

func NewSimpleHelp

func NewSimpleHelp(list []key.Binding) help.KeyMap

NewSimpleHelp creates a new simple help system

func ResetKeys added in v1.88.0

func ResetKeys()

ResetKeys clears the cached keybindings so the next GetKeys call rebuilds them. Used by tests and available for a future hot-reload.

func Resolve added in v1.44.0

func Resolve[T any](m tea.Model) T

Resolve retrieves a dependency of type T from the given tea.Model.

This function provides a type-safe way to access dependencies (such as *app.App, *service.SessionState, chat.Page, or editor.Editor) from a model that implements the Resolve(any) any method. The model acts as a dependency provider, allowing command handlers and other components to access shared state without tight coupling.

Usage:

app := core.Resolve[*app.App](model)
sessionState := core.Resolve[*service.SessionState](model)
chatPage := core.Resolve[chat.Page](model)

Panics if the model does not implement Resolve or cannot provide the requested type.

Experimental

Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.

func ValidActions added in v1.88.0

func ValidActions() []string

ValidActions returns the sorted list of action names that can be remapped. Useful for documentation and a future "show active bindings" command.

Types

type KeyMap added in v1.88.0

type KeyMap struct {
	Quit                  key.Binding
	SwitchFocus           key.Binding
	Commands              key.Binding
	Help                  key.Binding
	ToggleYolo            key.Binding
	ToggleHideToolResults key.Binding
	CycleAgent            key.Binding
	ModelPicker           key.Binding
	ClearQueue            key.Binding
	Suspend               key.Binding
	ToggleSidebar         key.Binding
	EditExternal          key.Binding
	HistorySearch         key.Binding

	// EditorSend submits the editor content. EditorNewline inserts a line
	// break. These are the input bindings referenced by issue #1626. The
	// editor additionally offers shift+enter for newline on terminals that
	// can report it; that is detected at runtime and is not part of the
	// configurable default.
	EditorSend    key.Binding
	EditorNewline key.Binding
}

KeyMap contains the keybindings used across the TUI. Bindings are resolved once from DefaultKeyMap() merged with the user's overrides (see GetKeys).

func DefaultKeyMap added in v1.88.0

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the built-in keybindings used when the user has not overridden them. Newline defaults to ctrl+j only; shift+enter is layered on at runtime by the editor when the terminal supports it.

func GetKeys added in v1.88.0

func GetKeys() KeyMap

GetKeys returns the resolved keybindings, merging the user config over the defaults. The result is read from disk once and cached; subsequent calls are lock-cheap so hot paths (key handling, help rendering) stay allocation-free.

type KeyMapHelp

type KeyMapHelp interface {
	Help() help.KeyMap
}

KeyMapHelp interface for components that provide help

type ScrollDirection

type ScrollDirection int

ScrollDirection represents the direction of scrolling

const (
	ScrollUp ScrollDirection = iota
	ScrollDown
	ScrollPageUp
	ScrollPageDown
	ScrollToTop
	ScrollToBottom
)

func GetScrollDirection

func GetScrollDirection(msg tea.KeyPressMsg) (ScrollDirection, bool)

GetScrollDirection returns the scroll direction for a key press, or -1 if not a scroll key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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