context

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder builds a context collection from various sources.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new context builder.

func (*Builder) AutoDetect

func (b *Builder) AutoDetect() *Builder

AutoDetect adds auto-detected context items (cwd, git branch, k8s context).

func (*Builder) Build

func (b *Builder) Build() *Collection

Build returns the built collection.

func (*Builder) WithCustom

func (b *Builder) WithCustom(key, value string) *Builder

WithCustom adds a custom context item.

func (*Builder) WithEnvVars

func (b *Builder) WithEnvVars(names []string) *Builder

WithEnvVars adds environment variables.

func (*Builder) WithHistory

func (b *Builder) WithHistory(commands []string) *Builder

WithHistory adds command history items.

func (*Builder) WithHistoryLimit

func (b *Builder) WithHistoryLimit(commands []string, limit int) *Builder

WithHistoryLimit adds command history items with a limit.

func (*Builder) WithLastError

func (b *Builder) WithLastError(stderr string) *Builder

WithLastError adds the last command error.

func (*Builder) WithLastOutput

func (b *Builder) WithLastOutput(output string) *Builder

WithLastOutput adds the last command output.

type Category

type Category int

Category defines context item types.

const (
	CategoryHistory    Category = iota // Recent commands
	CategoryEnv                        // Environment variables
	CategoryAutoDetect                 // Auto-detected context (cwd, git, k8s)
	CategoryCustom                     // User-added context
)

func (Category) String

func (c Category) String() string

type Collection

type Collection struct {
	Items        []Item
	MaxSizeBytes int // Recommended max size (default 8KB)
}

Collection holds all available context items.

func NewCollection

func NewCollection() *Collection

NewCollection creates a new context collection.

func (*Collection) Add

func (c *Collection) Add(item Item)

Add adds an item to the collection.

func (*Collection) Clear

func (c *Collection) Clear()

Clear removes all items from the collection.

func (*Collection) DeselectAll

func (c *Collection) DeselectAll()

DeselectAll deselects all items.

func (*Collection) SelectAll

func (c *Collection) SelectAll()

SelectAll selects all items.

func (*Collection) SelectedItems

func (c *Collection) SelectedItems() []Item

SelectedItems returns only selected items.

func (*Collection) SelectedSize

func (c *Collection) SelectedSize() int

SelectedSize returns the total size of selected items.

func (*Collection) Serialize

func (c *Collection) Serialize() string

Serialize returns the selected context as a string.

func (*Collection) SizeStatus

func (c *Collection) SizeStatus() string

SizeStatus returns a status indicator for the current size. Returns "green", "yellow", or "red".

func (*Collection) Toggle

func (c *Collection) Toggle(index int)

Toggle toggles selection of an item by index.

type Item

type Item struct {
	Category  Category
	Key       string // Display key (e.g., "kubectl get pods" or "HOME")
	Value     string // Full value to include in context
	Selected  bool   // Whether to include in context
	SizeBytes int    // Size in bytes when serialized
}

Item represents a single context item.

type Picker

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

Picker provides an interactive context picker.

func NewPicker

func NewPicker(collection *Collection) *Picker

NewPicker creates a new context picker.

func (*Picker) Collection

func (p *Picker) Collection() *Collection

Collection returns the underlying collection.

func (*Picker) CurrentItem

func (p *Picker) CurrentItem() *Item

CurrentItem returns the currently selected item, or nil if empty.

func (*Picker) Cursor

func (p *Picker) Cursor() int

Cursor returns the current cursor position.

func (*Picker) DeselectAll

func (p *Picker) DeselectAll()

DeselectAll deselects all items.

func (*Picker) ItemCount

func (p *Picker) ItemCount() int

ItemCount returns the number of items in the collection.

func (*Picker) MoveDown

func (p *Picker) MoveDown()

MoveDown moves the cursor down.

func (*Picker) MoveUp

func (p *Picker) MoveUp()

MoveUp moves the cursor up.

func (*Picker) Reset

func (p *Picker) Reset()

Reset resets the cursor to the beginning.

func (*Picker) SelectAll

func (p *Picker) SelectAll()

SelectAll selects all items.

func (*Picker) SelectedSize

func (p *Picker) SelectedSize() int

SelectedSize returns the size of selected items.

func (*Picker) Serialize

func (p *Picker) Serialize() string

Serialize returns the serialized context.

func (*Picker) SizeStatus

func (p *Picker) SizeStatus() string

SizeStatus returns the size status indicator.

func (*Picker) ToggleCurrent

func (p *Picker) ToggleCurrent()

ToggleCurrent toggles selection of the current item.

type PickerUI

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

PickerUI provides an interactive context picker TUI.

func NewPickerUI

func NewPickerUI(collection *Collection) *PickerUI

NewPickerUI creates a new picker UI.

func (*PickerUI) Init

func (ui *PickerUI) Init() tea.Cmd

Init implements tea.Model.

func (*PickerUI) Run

func (ui *PickerUI) Run() (string, error)

Run starts the interactive picker and returns the serialized context. Returns empty string if canceled.

func (*PickerUI) Update

func (ui *PickerUI) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (*PickerUI) View

func (ui *PickerUI) View() string

View implements tea.Model.

Jump to

Keyboard shortcuts

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