tui

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyEnter     = '\r'
	KeyNewline   = '\n'
	KeyEscape    = 27
	KeyBackspace = 127
	KeyCtrlC     = 3
	KeyCtrlD     = 4
)

Variables

This section is empty.

Functions

func Bold

func Bold(s string) string

func ChooseConfigFile

func ChooseConfigFile(explicitPath string) (string, error)

ChooseConfigFile scans ~/.carbide for config*.yaml files and shows an interactive selector if multiple configs exist. Returns the chosen path, or empty string if only one config exists (use default) or no terminal is available.

func ClearDown

func ClearDown()

func ClearLine

func ClearLine()

func Cyan

func Cyan(s string) string

func Dim

func Dim(s string) string

func Green

func Green(s string) string

func HideCursor

func HideCursor()

func LogCmd

func LogCmd(s *Session, parts ...string)

LogCmd prints the equivalent carbidecli one-liner for reference.

func MoveDown

func MoveDown(n int)

func MoveToColumn

func MoveToColumn(n int)

func MoveUp

func MoveUp(n int)

func PromptConfirm

func PromptConfirm(label string) (bool, error)

PromptConfirm displays a y/N confirmation prompt.

func PromptText

func PromptText(label string, required bool) (string, error)

PromptText displays a label and reads a line of text input.

func RawMode

func RawMode() (restore func(), err error)

func Red

func Red(s string) string

func Reverse

func Reverse(s string) string

func RunREPL

func RunREPL(s *Session) error

RunREPL starts the interactive REPL loop with inline autocomplete.

func RunTUI

func RunTUI(explicitConfig string) error

RunTUI is the entry point for carbidecli tui. It handles config selection, authentication, and starts the REPL.

func ShowCursor

func ShowCursor()

func Yellow

func Yellow(s string) string

Types

type Cache

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

Cache holds lazy-loaded resources for the interactive session with a TTL.

func NewCache

func NewCache() *Cache

func (*Cache) Get

func (c *Cache) Get(resourceType string) []NamedItem

func (*Cache) Invalidate

func (c *Cache) Invalidate(resourceType string)

func (*Cache) InvalidateAll

func (c *Cache) InvalidateAll()

func (*Cache) InvalidateFiltered

func (c *Cache) InvalidateFiltered()

func (*Cache) LookupByID

func (c *Cache) LookupByID(resourceType, id string) *NamedItem

func (*Cache) LookupByName

func (c *Cache) LookupByName(resourceType, name string) *NamedItem

func (*Cache) Set

func (c *Cache) Set(resourceType string, items []NamedItem)

type Command

type Command struct {
	Name        string
	Description string
	Run         func(s *Session, args []string) error
}

Command represents a registered interactive command.

func AllCommands

func AllCommands() []Command

AllCommands returns all available commands.

type FetchFunc

type FetchFunc func(ctx context.Context) ([]NamedItem, error)

FetchFunc fetches resources from the API and returns them as NamedItems.

type KeyEvent

type KeyEvent struct {
	Char    byte
	Special SpecialKey
}

func ReadKey

func ReadKey() (KeyEvent, error)

type LoginFunc

type LoginFunc func() (string, error)

LoginFunc is a callback to perform login and return a new token.

type NamedItem

type NamedItem struct {
	Name   string
	ID     string
	Status string
	Extra  map[string]string
	Raw    interface{}
}

NamedItem is a generic resource with a human-readable name and UUID.

type Resolver

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

Resolver resolves resource names to UUIDs using the cache and interactive select.

func NewResolver

func NewResolver(cache *Cache) *Resolver

func (*Resolver) Fetch

func (r *Resolver) Fetch(ctx context.Context, resourceType string) ([]NamedItem, error)

func (*Resolver) RegisterFetcher

func (r *Resolver) RegisterFetcher(resourceType string, fn FetchFunc)

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, resourceType, label string) (*NamedItem, error)

func (*Resolver) ResolveID

func (r *Resolver) ResolveID(resourceType, id string) string

func (*Resolver) ResolveWithArgs

func (r *Resolver) ResolveWithArgs(ctx context.Context, resourceType, label string, args []string) (*NamedItem, error)

func (*Resolver) SelectFromItems

func (r *Resolver) SelectFromItems(label string, items []NamedItem) (*NamedItem, error)

type Scope

type Scope struct {
	SiteID   string
	SiteName string
	VpcID    string
	VpcName  string
}

Scope holds the current filter context for the interactive session.

type SelectItem

type SelectItem struct {
	Label string
	ID    string
	Extra map[string]string
}

SelectItem represents one option in a select menu.

func Select

func Select(label string, items []SelectItem) (*SelectItem, error)

Select displays an interactive arrow-key menu and returns the selected item. For large lists it shows a scrolling window of selectWindowSize items.

type Session

type Session struct {
	Client     *carbidecli.Client
	ConfigPath string
	Org        string
	Token      string
	Scope      Scope
	Cache      *Cache
	Resolver   *Resolver
	LoginFn    LoginFunc
}

Session holds the shared state for an interactive TUI session.

func NewSession

func NewSession(client *carbidecli.Client, org, configPath string) *Session

NewSession creates a new interactive session.

func (*Session) PromptString

func (s *Session) PromptString() string

PromptString returns the prompt showing org and current scope.

func (*Session) RefreshClient

func (s *Session) RefreshClient(token string)

RefreshClient updates the session with a new token.

type SpecialKey

type SpecialKey int
const (
	KeyNone SpecialKey = iota
	KeyUp
	KeyDown
	KeyRight
	KeyLeft
)

Jump to

Keyboard shortcuts

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