gline

package
v0.34.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Active appState = iota
	Terminated
)
View Source
const (
	ESC                  = "\033"
	BACKSPACE            = "\b \b"
	RESET_CURSOR         = ESC + "[H"
	RESET_CURSOR_COLUMN  = ESC + "[G"
	CLEAR_REMAINING_LINE = ESC + "[K"
	CLEAR_LINE           = RESET_CURSOR_COLUMN + ESC + "[2K"
	CLEAR_AFTER_CURSOR   = ESC + "[J"
	SAVE_CURSOR          = ESC + "[s"
	RESTORE_CURSOR       = ESC + "[u"
	GET_CURSOR_POS       = ESC + "[6n"
	MOVE_CURSOR          = ESC + "[%d;%dH"
)

Variables

View Source
var ErrInterrupted = errors.New("interrupted by user")

ErrInterrupted is returned when the user presses Ctrl+C

Functions

func GetLightningBoltWidth

func GetLightningBoltWidth() int

GetLightningBoltWidth returns the width of the lightning bolt character. Uses the generic emoji width cache with terminal probing.

func GetRobotWidth

func GetRobotWidth() int

GetRobotWidth returns the width of the robot emoji character. Uses the generic emoji width cache with terminal probing.

func GetRuneWidth

func GetRuneWidth(r rune) int

GetRuneWidth returns the display width of a rune, using terminal probing for emoji. For emoji characters, the width is detected once and cached. For other characters, it returns 1 for ASCII or 2 for wide characters.

func Gline

func Gline(
	prompt string,
	historyValues []string,
	explanation string,
	predictor Predictor,
	explainer Explainer,
	analytics PredictionAnalytics,
	logger *zap.Logger,
	options Options,
) (string, error)

func WordwrapWithRuneWidth

func WordwrapWithRuneWidth(s string, width int) string

WordwrapWithRuneWidth wraps text to the given width using GetRuneWidth for accurate Unicode character width calculation. This is needed because the standard ansi.Wordwrap uses its own width calculation that may not match terminal-specific emoji rendering. It preserves ANSI escape codes in the output.

Types

type BorderStatusModel

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

BorderStatusModel manages the state and rendering of border status elements

func NewBorderStatusModel

func NewBorderStatusModel() BorderStatusModel

func (BorderStatusModel) RenderBottomCenter

func (m BorderStatusModel) RenderBottomCenter() string

func (BorderStatusModel) RenderBottomLeft

func (m BorderStatusModel) RenderBottomLeft() string

func (BorderStatusModel) RenderTopContext

func (m BorderStatusModel) RenderTopContext(maxWidth int) string

func (BorderStatusModel) RenderTopLeft

func (m BorderStatusModel) RenderTopLeft() string

func (*BorderStatusModel) SetWidth

func (m *BorderStatusModel) SetWidth(w int)

func (BorderStatusModel) TopLeftWidth

func (m BorderStatusModel) TopLeftWidth() int

TopLeftWidth returns the actual display width of the top-left section. This accounts for terminal-specific rendering of emoji characters like 🤖.

func (*BorderStatusModel) UpdateContext

func (m *BorderStatusModel) UpdateContext(user, host, cwd string)

func (*BorderStatusModel) UpdateGit

func (m *BorderStatusModel) UpdateGit(status *git.RepoStatus)

func (*BorderStatusModel) UpdateInput

func (m *BorderStatusModel) UpdateInput(input string)

func (*BorderStatusModel) UpdateResources

func (m *BorderStatusModel) UpdateResources(res *system.Resources)

type BorderStyles

type BorderStyles struct {
	BadgeRaw     lipgloss.Style
	BadgeAgent   lipgloss.Style
	BadgeControl lipgloss.Style
	BadgeSub     lipgloss.Style

	RiskCalm    lipgloss.Style
	RiskWarning lipgloss.Style
	RiskAlert   lipgloss.Style

	ContextUser lipgloss.Style
	ContextDir  lipgloss.Style
	ContextGit  lipgloss.Style
	Divider     lipgloss.Style

	ResCool  lipgloss.Style
	ResWarm  lipgloss.Style
	ResHot   lipgloss.Style
	ResLabel lipgloss.Style
}

type CommandKind

type CommandKind int

Command Classification

const (
	KindRawShell CommandKind = iota
	KindAgentChat
	KindAgentControl
	KindSubagent
	KindUnknown
)

type Explainer

type Explainer interface {
	Explain(ctx context.Context, input string) (string, error)
}

type IdleSummaryGenerator

type IdleSummaryGenerator func(ctx context.Context) (string, error)

IdleSummaryGenerator is a function that generates an idle summary

type LLMIndicator

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

LLMIndicator holds the state for an LLM status indicator

func NewLLMIndicator

func NewLLMIndicator() LLMIndicator

NewLLMIndicator creates a new LLM indicator

func (LLMIndicator) GetStatus

func (i LLMIndicator) GetStatus() LLMStatus

GetStatus returns the current status

func (*LLMIndicator) SetStatus

func (i *LLMIndicator) SetStatus(status LLMStatus)

SetStatus updates the indicator status

func (LLMIndicator) Tick

func (i LLMIndicator) Tick() tea.Cmd

Tick returns a command that sends LLMTickMsg after the animation interval

func (*LLMIndicator) Update

func (i *LLMIndicator) Update()

Update advances the animation frame

func (LLMIndicator) View

func (i LLMIndicator) View() string

View renders the indicator

func (LLMIndicator) Width

func (i LLMIndicator) Width() int

Width returns the display width of the indicator. Note: ⚡ (U+26A1) has ambiguous East Asian width; runewidth returns 2 but many western terminals render it as 1 cell. We detect the actual terminal behavior at runtime using cursor position probing.

type LLMStatus

type LLMStatus int

LLMStatus represents the current status of an LLM request

const (
	// LLMStatusIdle means no request has been made yet
	LLMStatusIdle LLMStatus = iota
	// LLMStatusInFlight means a request is currently in progress
	LLMStatusInFlight
	// LLMStatusSuccess means the last request was successful
	LLMStatusSuccess
	// LLMStatusError means the last request encountered an error
	LLMStatusError
)

type LLMTickMsg

type LLMTickMsg struct{}

LLMTickMsg is sent to advance the color animation

type MultilineState

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

MultilineState tracks the state of multiline input

func NewMultilineState

func NewMultilineState() *MultilineState

NewMultilineState creates a new multiline state

func (*MultilineState) AddLine

func (m *MultilineState) AddLine(line string) (complete bool, prompt string)

AddLine adds a line to the multiline buffer and checks if more input is needed

IMPORTANT: This method expects individual lines without embedded newlines. In real shell usage, users type one line at a time, and the shell determines whether more input is needed based on syntax analysis.

For here-documents, the usage pattern is: 1. User types: cat <<EOF 2. Shell shows: > (continuation prompt) 3. User types: content line 4. Shell shows: > (continuation prompt) 5. User types: EOF 6. Command completes

func (*MultilineState) GetAccumulatedLines

func (m *MultilineState) GetAccumulatedLines() string

GetAccumulatedLines returns the accumulated lines for display purposes

func (*MultilineState) GetCompleteCommand

func (m *MultilineState) GetCompleteCommand() string

GetCompleteCommand returns the complete command and resets the state

func (*MultilineState) GetLines

func (m *MultilineState) GetLines() []string

GetLines returns the individual lines that have been entered

func (*MultilineState) IsActive

func (m *MultilineState) IsActive() bool

IsActive returns true if we're in the middle of a multiline input

func (*MultilineState) Reset

func (m *MultilineState) Reset()

Reset clears the multiline state

type NoopExplainer

type NoopExplainer struct{}

func (*NoopExplainer) Explain

func (e *NoopExplainer) Explain(ctx context.Context, input string) (string, error)

type NoopPredictionAnalytics

type NoopPredictionAnalytics struct{}

func (*NoopPredictionAnalytics) NewEntry

func (p *NoopPredictionAnalytics) NewEntry(input string, prediction string, actual string) error

type NoopPredictor

type NoopPredictor struct{}

func (*NoopPredictor) Predict

func (p *NoopPredictor) Predict(ctx context.Context, input string) (string, string, error)

type Options

type Options struct {
	// Deprecated: use AssistantHeight instead
	MinHeight          int
	AssistantHeight    int
	CompletionProvider shellinput.CompletionProvider
	RichHistory        []shellinput.HistoryItem
	CurrentDirectory   string
	CurrentSessionID   string
	User               string
	Host               string

	// InitialValue is the initial text to populate in the input field.
	// Used for features like editing a suggested fix before execution.
	InitialValue string

	// IdleSummaryTimeout is the number of seconds of idle time before generating a summary.
	// Set to 0 to disable idle summaries.
	IdleSummaryTimeout int
	// IdleSummaryGenerator is called when the user is idle to generate a summary
	IdleSummaryGenerator IdleSummaryGenerator

	// ResourceUpdateInterval is the interval in seconds between resource (CPU/RAM) updates.
	// Higher values reduce energy consumption. Default is 5 seconds.
	// Set to 0 to disable resource monitoring.
	ResourceUpdateInterval int
}

func NewOptions

func NewOptions() Options

type PredictionAnalytics

type PredictionAnalytics interface {
	NewEntry(input string, prediction string, actual string) error
}

type Predictor

type Predictor interface {
	Predict(ctx context.Context, input string) (string, string, error)
}

type RiskLevel

type RiskLevel int

Execution Risk States

const (
	RiskCalm RiskLevel = iota
	RiskWarning
	RiskAlert
)

type ShellCompletionProvider

type ShellCompletionProvider struct {
	CompletionManager *completion.CompletionManager
	Runner            *interp.Runner
}

ShellCompletionProvider implements shellinput.CompletionProvider using the shell's CompletionManager

func (*ShellCompletionProvider) GetCompletions

func (p *ShellCompletionProvider) GetCompletions(line string, pos int) []shellinput.CompletionCandidate

GetCompletions returns completion suggestions for the current input line

func (*ShellCompletionProvider) GetHelpInfo

func (p *ShellCompletionProvider) GetHelpInfo(line string, pos int) string

GetHelpInfo returns help information for special commands like #! and #/ Returns empty string if no help is available

Jump to

Keyboard shortcuts

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