interactive

package
v7.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package interactive houses interactive UI types and helpers shared across the application.

Index

Constants

View Source
const (
	// InteractiveQuitCommand instructs the interactive UI to exit.
	InteractiveQuitCommand = "quit"
	// InteractiveWorkflowCommand signals that an interactive workflow has been executed.
	InteractiveWorkflowCommand = "workflow-executed"
)
View Source
const (
	// ProfileDefault exposes the default key binding profile identifier.
	ProfileDefault = kb.ProfileDefault
	// ProfileEmacs exposes the emacs key binding profile identifier.
	ProfileEmacs = kb.ProfileEmacs
	// ProfileVi exposes the vi key binding profile identifier.
	ProfileVi = kb.ProfileVi
	// ProfileReadline exposes the readline key binding profile identifier.
	ProfileReadline = kb.ProfileReadline

	// ContextGlobal exposes the global key binding context identifier.
	ContextGlobal = kb.ContextGlobal
	// ContextInput exposes the input key binding context identifier.
	ContextInput = kb.ContextInput
	// ContextResults exposes the results key binding context identifier.
	ContextResults = kb.ContextResults
	// ContextSearch exposes the search key binding context identifier.
	ContextSearch = kb.ContextSearch
)

Variables

View Source
var (
	// NewKeyBindingResolver constructs a key binding resolver using the keybindings package implementation.
	NewKeyBindingResolver = kb.NewKeyBindingResolver
	// RegisterBuiltinProfiles registers builtin profiles in the underlying keybindings package.
	RegisterBuiltinProfiles = kb.RegisterBuiltinProfiles
	// DefaultKeyBindingMap provides the default key binding map from the keybindings package.
	DefaultKeyBindingMap = kb.DefaultKeyBindingMap
	// DetectPlatform returns the inferred platform from the keybindings package.
	DetectPlatform = kb.DetectPlatform
	// DetectTerminal returns the inferred terminal from the keybindings package.
	DetectTerminal = kb.DetectTerminal
	// NewContextManager constructs a context manager using the keybindings package.
	NewContextManager = kb.NewContextManager
	// NewCtrlKeyStroke creates a control key stroke using the keybindings package implementation.
	NewCtrlKeyStroke = kb.NewCtrlKeyStroke
	// NewCharKeyStroke creates a character key stroke using the keybindings package implementation.
	NewCharKeyStroke = kb.NewCharKeyStroke
	// NewRawKeyStroke creates a raw key stroke using the keybindings package implementation.
	NewRawKeyStroke = kb.NewRawKeyStroke
	// NewEscapeKeyStroke creates an escape key stroke using the keybindings package implementation.
	NewEscapeKeyStroke = kb.NewEscapeKeyStroke
	// NewAltKeyStroke creates an alt key stroke using the keybindings package implementation.
	NewAltKeyStroke = kb.NewAltKeyStroke
	// NewContextualKeyBindingMap builds a contextual key binding map using the keybindings package implementation.
	NewContextualKeyBindingMap = kb.NewContextualKeyBindingMap
	// FormatKeyStrokesForDisplay formats key strokes for human-readable display.
	FormatKeyStrokesForDisplay = kb.FormatKeyStrokesForDisplay
)
View Source
var ErrWorkflowCanceled = errors.New("workflow canceled")

ErrWorkflowCanceled indicates the workflow was aborted by the user via soft cancel.

Functions

func Run

func Run(gitClient git.StatusInfoReader) []string

Run executes the incremental search interactive UI with the provided custom git client, and returns the selected command as []string (or nil if nothing is selected).

Types

type ANSIColors

type ANSIColors = uiutil.ANSIColors

ANSIColors is an alias to the shared UI palette definition.

func NewANSIColors

func NewANSIColors() *ANSIColors

NewANSIColors exposes the shared ANSI color palette helper.

type CommandInfo

type CommandInfo struct {
	Command     string
	Description string
}

CommandInfo contains the name and description of the command

type CommandRouter

type CommandRouter interface {
	Route(args []string)
}

CommandRouter represents an interface for routing commands

type Context

type Context = kb.Context

Context exposes the kb.Context type to interactive consumers.

type ContextManager

type ContextManager = kb.ContextManager

ContextManager exposes the kb.ContextManager type to interactive consumers.

type ContextualKeyBindingMap

type ContextualKeyBindingMap = kb.ContextualKeyBindingMap

ContextualKeyBindingMap exposes the kb.ContextualKeyBindingMap type to interactive consumers.

type GitStatus

type GitStatus struct {
	Branch     string
	Modified   int
	Staged     int
	Ahead      int
	Behind     int
	HasChanges bool
}

GitStatus represents the current Git repository status

type KeyBindingMap

type KeyBindingMap = kb.KeyBindingMap

KeyBindingMap exposes the kb.KeyBindingMap type to interactive consumers.

type KeyBindingResolver

type KeyBindingResolver = kb.KeyBindingResolver

KeyBindingResolver exposes the kb.KeyBindingResolver type to interactive consumers.

type KeyHandler

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

KeyHandler manages keyboard input processing

func (*KeyHandler) GetCurrentKeyMap

func (h *KeyHandler) GetCurrentKeyMap() *KeyBindingMap

GetCurrentKeyMap returns the appropriate keybinding map for the current context

func (*KeyHandler) HandleKey

func (h *KeyHandler) HandleKey(r rune, _ bool, oldState *term.State, reader *bufio.Reader) (bool, []string)

HandleKey processes UTF-8 rune input and returns true if should continue This method handles both single-byte (ASCII/control) and multibyte characters

type KeyStroke

type KeyStroke = kb.KeyStroke

KeyStroke exposes the kb.KeyStroke type to interactive consumers.

type Profile

type Profile = kb.Profile

Profile exposes the kb.Profile type to interactive consumers.

type Renderer

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

Renderer handles all terminal rendering operations

func (*Renderer) Render

func (r *Renderer) Render(ui *UI, state *UIState)

Render displays the command list with proper terminal handling

type UI

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

UI represents the interface for terminal UI operations

func NewUI

func NewUI(gitClient git.StatusInfoReader, router ...CommandRouter) *UI

NewUI creates a new UI with the provided git client and loads keybindings from config

func (*UI) AddToWorkflow

func (ui *UI) AddToWorkflow(command string, args []string, description string) int

AddToWorkflow adds a command to the workflow

func (*UI) ApplyContextualKeybindings

func (ui *UI) ApplyContextualKeybindings(contextual *ContextualKeyBindingMap)

ApplyContextualKeybindings updates the active keybinding map, satisfying keybindings.ContextualMapApplier.

func (*UI) ClearWorkflow

func (ui *UI) ClearWorkflow()

ClearWorkflow removes all steps from the workflow

func (*UI) ExecuteWorkflow

func (ui *UI) ExecuteWorkflow() error

ExecuteWorkflow executes the current workflow

func (*UI) ResetToSearchMode

func (ui *UI) ResetToSearchMode() bool

ResetToSearchMode clears the interactive search UI back to its default state.

func (*UI) Run

func (ui *UI) Run() []string

Run executes the interactive UI

func (*UI) ToggleWorkflowView

func (ui *UI) ToggleWorkflowView()

ToggleWorkflowView toggles between normal command view and workflow view

type UIState

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

UIState holds the current state of the interactive UI

func (*UIState) AddRune

func (s *UIState) AddRune(r rune)

AddRune adds a UTF-8 rune to the input at cursor position

func (*UIState) ClearInput

func (s *UIState) ClearInput()

ClearInput clears all input

func (*UIState) DeleteToEnd

func (s *UIState) DeleteToEnd()

DeleteToEnd deletes from cursor to end of line (Ctrl+K)

func (*UIState) DeleteWord

func (s *UIState) DeleteWord()

DeleteWord deletes word before cursor (Ctrl+W)

func (*UIState) EnterContext

func (s *UIState) EnterContext(newContext Context)

EnterContext pushes the current context onto the stack and switches to the new context

func (*UIState) ExitContext

func (s *UIState) ExitContext()

ExitContext pops the previous context from the stack

func (*UIState) GetCurrentContext

func (s *UIState) GetCurrentContext() Context

GetCurrentContext returns the current UI context

func (*UIState) GetSelectedCommand

func (s *UIState) GetSelectedCommand() *CommandInfo

GetSelectedCommand returns the currently selected command

func (*UIState) HasInput

func (s *UIState) HasInput() bool

HasInput returns true if there is input

func (*UIState) HasMatches

func (s *UIState) HasMatches() bool

HasMatches returns true if there are filtered matches

func (*UIState) IsInInputMode

func (s *UIState) IsInInputMode() bool

IsInInputMode returns true if currently in input context

func (*UIState) IsInResultsMode

func (s *UIState) IsInResultsMode() bool

IsInResultsMode returns true if currently in results context

func (*UIState) IsInSearchMode

func (s *UIState) IsInSearchMode() bool

IsInSearchMode returns true if currently in search context

func (*UIState) MoveDown

func (s *UIState) MoveDown()

MoveDown moves selection down

func (*UIState) MoveLeft

func (s *UIState) MoveLeft()

MoveLeft moves cursor one rune left

func (*UIState) MoveRight

func (s *UIState) MoveRight()

MoveRight moves cursor one rune right

func (*UIState) MoveToBeginning

func (s *UIState) MoveToBeginning()

MoveToBeginning moves cursor to beginning of line (Ctrl+A)

func (*UIState) MoveToEnd

func (s *UIState) MoveToEnd()

MoveToEnd moves cursor to end of line (Ctrl+E)

func (*UIState) MoveUp

func (s *UIState) MoveUp()

MoveUp moves selection up

func (*UIState) MoveWordLeft

func (s *UIState) MoveWordLeft()

MoveWordLeft moves cursor to the beginning of the previous word

func (*UIState) MoveWordRight

func (s *UIState) MoveWordRight()

MoveWordRight moves cursor to the start of the next word

func (*UIState) RemoveChar

func (s *UIState) RemoveChar()

RemoveChar removes character before cursor (backspace)

func (*UIState) SetContext

func (s *UIState) SetContext(ctx Context)

SetContext directly sets the context (use with caution)

func (*UIState) UpdateFiltered

func (s *UIState) UpdateFiltered()

UpdateFiltered updates the filtered commands based on current input using fuzzy matching

type Workflow

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

Workflow manages a sequence of commands to be executed

func NewWorkflow

func NewWorkflow() *Workflow

NewWorkflow creates a new workflow

func (*Workflow) AddStep

func (w *Workflow) AddStep(command string, args []string, description string) int

AddStep adds a step to the workflow

func (*Workflow) Clear

func (w *Workflow) Clear()

Clear removes all steps from the workflow

func (*Workflow) GetSteps

func (w *Workflow) GetSteps() []WorkflowStep

GetSteps returns a copy of all workflow steps

func (*Workflow) IsEmpty

func (w *Workflow) IsEmpty() bool

IsEmpty returns true if the workflow has no steps

func (*Workflow) Size

func (w *Workflow) Size() int

Size returns the number of steps in the workflow

type WorkflowExecutor

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

WorkflowExecutor executes workflow steps sequentially using existing Route mechanism

func NewWorkflowExecutor

func NewWorkflowExecutor(router CommandRouter, ui *UI) *WorkflowExecutor

NewWorkflowExecutor creates a new workflow executor

func (*WorkflowExecutor) Execute

func (we *WorkflowExecutor) Execute(workflow *Workflow) error

Execute runs all steps in the workflow sequentially

type WorkflowStep

type WorkflowStep struct {
	ID          int      `json:"id"`
	Command     string   `json:"command"`
	Args        []string `json:"args"`
	Description string   `json:"description"`
}

WorkflowStep represents a single step in a workflow

func (*WorkflowStep) String

func (ws *WorkflowStep) String() string

String returns a string representation of the workflow step

Jump to

Keyboard shortcuts

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