console

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearLineSeq added in v0.7.0

func ClearLineSeq() string

ClearLineSeq returns the escape sequence to clear the entire current line.

func ClearToEndOfLineSeq added in v0.7.0

func ClearToEndOfLineSeq() string

ClearToEndOfLineSeq returns the escape sequence to clear from cursor to end of line.

func DebugEnabled added in v0.7.0

func DebugEnabled() bool

DebugEnabled returns true if debug output is enabled

func DebugPrintf added in v0.7.0

func DebugPrintf(format string, args ...interface{})

DebugPrintf prints debug output to stderr if debugging is enabled

func MoveCursorSeq added in v0.7.0

func MoveCursorSeq(x, y int) string

MoveCursorSeq returns the escape sequence to move the cursor to (x,y) Note: ANSI uses row (y) first, then column (x).

func RegisterCleanup added in v0.7.0

func RegisterCleanup(fn func() error)

RegisterCleanup registers a global cleanup function

func RegisterComponent added in v0.7.0

func RegisterComponent(componentType string, factory ComponentFactory) error

RegisterComponent registers a component factory globally

func ResetScrollRegionSeq added in v0.7.0

func ResetScrollRegionSeq() string

ResetScrollRegionSeq resets the scrolling region to the full screen.

func RunCleanup added in v0.7.0

func RunCleanup()

RunCleanup runs all registered cleanup functions

func SetScrollRegionSeq added in v0.7.0

func SetScrollRegionSeq(top, bottom int) string

SetScrollRegionSeq returns the escape sequence to set the scrolling region (1-based, inclusive).

Types

type AutoLayoutManager added in v0.7.0

type AutoLayoutManager struct {
	LayoutManager // Embed the existing interface
	// contains filtered or unexported fields
}

AutoLayoutManager automatically manages component positioning

func NewAutoLayoutManager added in v0.7.0

func NewAutoLayoutManager() *AutoLayoutManager

NewAutoLayoutManager creates an enhanced layout manager

func (*AutoLayoutManager) AddResizeCallback added in v0.7.0

func (alm *AutoLayoutManager) AddResizeCallback(callback func(width, height int))

AddResizeCallback adds a callback for resize events

func (*AutoLayoutManager) GetContentRegion added in v0.7.0

func (alm *AutoLayoutManager) GetContentRegion() (Region, error)

GetContentRegion returns the region allocated for scrollable content

func (*AutoLayoutManager) GetScrollRegion added in v0.7.0

func (alm *AutoLayoutManager) GetScrollRegion() (top, bottom int)

GetScrollRegion returns the scroll region boundaries for terminal setup (1-based)

func (*AutoLayoutManager) GetTerminalSize added in v0.7.0

func (alm *AutoLayoutManager) GetTerminalSize() (int, int)

GetTerminalSize returns current terminal dimensions

func (*AutoLayoutManager) Initialize added in v0.7.0

func (alm *AutoLayoutManager) Initialize() error

Initialize sets up the auto layout manager

func (*AutoLayoutManager) InitializeForTest added in v0.7.0

func (alm *AutoLayoutManager) InitializeForTest(width, height int)

InitializeForTest sets up the auto layout manager without requiring a terminal

func (*AutoLayoutManager) OnTerminalResize added in v0.7.0

func (alm *AutoLayoutManager) OnTerminalResize(width, height int)

OnTerminalResize handles terminal resize events

func (*AutoLayoutManager) PrintDebugLayout added in v0.7.0

func (alm *AutoLayoutManager) PrintDebugLayout()

PrintDebugLayout prints current layout for debugging

func (*AutoLayoutManager) RegisterComponent added in v0.7.0

func (alm *AutoLayoutManager) RegisterComponent(name string, info *ComponentInfo)

RegisterComponent registers a component for automatic layout

func (*AutoLayoutManager) SetComponentHeight added in v0.7.0

func (alm *AutoLayoutManager) SetComponentHeight(name string, height int)

SetComponentHeight sets the height for a component

func (*AutoLayoutManager) SetComponentVisible added in v0.7.0

func (alm *AutoLayoutManager) SetComponentVisible(name string, visible bool)

SetComponentVisible sets visibility for a component

func (*AutoLayoutManager) TestLayout added in v0.7.0

func (alm *AutoLayoutManager) TestLayout(width, height int)

TestLayout manually sets up layout for testing without requiring terminal

func (*AutoLayoutManager) UpdateComponentInfo added in v0.7.0

func (alm *AutoLayoutManager) UpdateComponentInfo(name string, updater func(*ComponentInfo))

UpdateComponentInfo updates component layout information

type BaseComponent

type BaseComponent struct {

	// Protected fields - accessible by embedding components
	Deps Dependencies
	// contains filtered or unexported fields
}

BaseComponent provides common functionality for components

func NewBaseComponent

func NewBaseComponent(id, componentType string) *BaseComponent

NewBaseComponent creates a new base component

func (*BaseComponent) CanHandleInput

func (bc *BaseComponent) CanHandleInput() bool

CanHandleInput returns if component can handle input

func (*BaseComponent) Cleanup

func (bc *BaseComponent) Cleanup() error

Cleanup cleans up component resources

func (*BaseComponent) Controller added in v0.8.3

func (bc *BaseComponent) Controller() *TerminalController

Controller returns the terminal controller

func (*BaseComponent) Events

func (bc *BaseComponent) Events() EventBus

Events returns the event bus

func (*BaseComponent) GetRegion

func (bc *BaseComponent) GetRegion() string

GetRegion returns the component's region

func (*BaseComponent) HandleInput

func (bc *BaseComponent) HandleInput(input []byte) (bool, error)

HandleInput handles input

func (*BaseComponent) ID

func (bc *BaseComponent) ID() string

ID returns the component ID

func (*BaseComponent) Init

func (bc *BaseComponent) Init(ctx context.Context, deps Dependencies) error

Init initializes the component with dependencies

func (*BaseComponent) Layout

func (bc *BaseComponent) Layout() LayoutManager

Layout returns the layout manager

func (*BaseComponent) NeedsRedraw

func (bc *BaseComponent) NeedsRedraw() bool

NeedsRedraw returns if component needs redrawing

func (*BaseComponent) PublishEvent

func (bc *BaseComponent) PublishEvent(eventType string, data interface{})

PublishEvent publishes an event from this component

func (*BaseComponent) Render

func (bc *BaseComponent) Render() error

Render renders the component

func (*BaseComponent) SetNeedsRedraw

func (bc *BaseComponent) SetNeedsRedraw(needs bool)

SetNeedsRedraw marks component for redraw

func (*BaseComponent) SetRegion

func (bc *BaseComponent) SetRegion(region string)

SetRegion sets the component's region

func (*BaseComponent) Start

func (bc *BaseComponent) Start() error

Start starts the component

func (*BaseComponent) State

func (bc *BaseComponent) State() StateManager

State returns the state manager

func (*BaseComponent) Stop

func (bc *BaseComponent) Stop() error

Stop stops the component

func (*BaseComponent) Terminal

func (bc *BaseComponent) Terminal() TerminalManager

Terminal returns the terminal manager

func (*BaseComponent) Type

func (bc *BaseComponent) Type() string

Type returns the component type

type BufferStats added in v0.6.0

type BufferStats struct {
	TotalLines     int
	WrappedLines   int
	ScrollPosition int
	TerminalWidth  int
}

BufferStats contains buffer statistics

type CIOutputHandler added in v0.7.0

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

CIOutputHandler manages output formatting for CI/non-interactive environments

func NewCIOutputHandler added in v0.7.0

func NewCIOutputHandler(writer io.Writer) *CIOutputHandler

NewCIOutputHandler creates a new CI output handler

func (*CIOutputHandler) IsCI added in v0.7.0

func (h *CIOutputHandler) IsCI() bool

IsCI returns true if running in CI environment

func (*CIOutputHandler) IsInteractive added in v0.7.0

func (h *CIOutputHandler) IsInteractive() bool

IsInteractive returns true if running in an interactive terminal

func (*CIOutputHandler) PrintProgress added in v0.7.0

func (h *CIOutputHandler) PrintProgress()

PrintProgress prints a progress update in CI-friendly format

func (*CIOutputHandler) PrintSummary added in v0.7.0

func (h *CIOutputHandler) PrintSummary()

PrintSummary prints a final summary

func (*CIOutputHandler) Printf added in v0.7.0

func (h *CIOutputHandler) Printf(format string, args ...interface{})

Printf writes formatted output

func (*CIOutputHandler) ShouldShowProgress added in v0.7.0

func (h *CIOutputHandler) ShouldShowProgress() bool

ShouldShowProgress returns true if progress should be shown

func (*CIOutputHandler) UpdateMetrics added in v0.7.0

func (h *CIOutputHandler) UpdateMetrics(totalTokens, contextTokens, maxContextTokens, iteration int, totalCost float64)

UpdateMetrics updates the tracked metrics

func (*CIOutputHandler) Write added in v0.7.0

func (h *CIOutputHandler) Write(p []byte) (n int, err error)

Write implements io.Writer interface

func (*CIOutputHandler) WriteString added in v0.7.0

func (h *CIOutputHandler) WriteString(s string) error

WriteString writes a string with appropriate formatting

type CLIOutputHandler added in v0.8.3

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

CLIOutputHandler handles simple CLI mode output (direct to stdout)

func NewCLIOutputHandler added in v0.8.3

func NewCLIOutputHandler() *CLIOutputHandler

NewCLIOutputHandler creates a new CLI output handler

func (*CLIOutputHandler) Close added in v0.8.3

func (h *CLIOutputHandler) Close() error

Close cleans up resources (no-op for CLI)

func (*CLIOutputHandler) Flush added in v0.8.3

func (h *CLIOutputHandler) Flush() error

Flush ensures output is written (no-op for CLI)

func (*CLIOutputHandler) Mode added in v0.8.3

func (h *CLIOutputHandler) Mode() OutputMode

Mode returns the output mode

func (*CLIOutputHandler) Print added in v0.8.3

func (h *CLIOutputHandler) Print(format string, args ...interface{})

Print writes formatted output

func (*CLIOutputHandler) Printf added in v0.8.3

func (h *CLIOutputHandler) Printf(format string, args ...interface{})

Printf writes formatted output

func (*CLIOutputHandler) Println added in v0.8.3

func (h *CLIOutputHandler) Println(args ...interface{})

Println writes output with newline

func (*CLIOutputHandler) Write added in v0.8.3

func (h *CLIOutputHandler) Write(p []byte) (int, error)

Write writes raw bytes

type Component

type Component interface {
	// Lifecycle methods
	Init(ctx context.Context, deps Dependencies) error
	Start() error
	Stop() error
	Cleanup() error

	// Component identity
	ID() string
	Type() string

	// Rendering
	Render() error
	NeedsRedraw() bool

	// Input handling
	HandleInput(input []byte) (handled bool, err error)
	CanHandleInput() bool

	// Region management
	GetRegion() string
	SetRegion(region string)
}

Component is the base interface for all UI components

func CreateComponent added in v0.7.0

func CreateComponent(componentType string) (Component, error)

CreateComponent creates a component from the global registry

type ComponentConfig

type ComponentConfig struct {
	ID      string
	Type    string
	Region  string
	Config  map[string]interface{}
	Enabled bool
}

ComponentConfig configures a component

type ComponentFactory added in v0.7.0

type ComponentFactory func() Component

ComponentFactory creates component instances

type ComponentInfo added in v0.7.0

type ComponentInfo struct {
	Name     string
	Position string // "top", "bottom", "content"
	Height   int    // Fixed height, 0 = flexible
	Priority int    // Higher priority gets preference
	Visible  bool
	ZOrder   int
}

ComponentInfo holds layout information for a component

type ComponentRegistry added in v0.7.0

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

ComponentRegistry manages component factories

func NewComponentRegistry added in v0.7.0

func NewComponentRegistry() *ComponentRegistry

NewComponentRegistry creates a new component registry

func (*ComponentRegistry) Create added in v0.7.0

func (r *ComponentRegistry) Create(componentType string) (Component, error)

Create creates a new component instance

func (*ComponentRegistry) ListTypes added in v0.7.0

func (r *ComponentRegistry) ListTypes() []string

ListTypes returns all registered component types

func (*ComponentRegistry) Register added in v0.7.0

func (r *ComponentRegistry) Register(componentType string, factory ComponentFactory) error

Register registers a component factory

type Config

type Config struct {
	// Terminal settings
	RawMode      bool
	MouseEnabled bool
	AltScreen    bool

	// Layout settings
	MinWidth  int
	MinHeight int

	// Component settings
	Components []ComponentConfig

	// Event settings
	EventQueueSize int

	// Debug settings
	Debug   bool
	LogFile string
}

Config holds application configuration

func ConfigForMode added in v0.8.3

func ConfigForMode(mode OutputMode) *Config

ConfigForMode returns a configuration appropriate for the given output mode

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration (compatible with existing code)

type ConsoleApp

type ConsoleApp interface {
	// Lifecycle
	Init(config *Config) error
	Start() error
	Stop() error
	Run() error
	Cleanup() error

	// Component management
	AddComponent(component Component) error
	RemoveComponent(componentID string) error
	GetComponent(componentID string) (Component, bool)
	ListComponents() []string

	// Service access
	Terminal() TerminalManager
	Layout() LayoutManager
	State() StateManager
	Events() EventBus
	Controller() *TerminalController

	// Configuration
	GetConfig() *Config
	UpdateConfig(config *Config) error
}

ConsoleApp is the main application controller

func NewConsoleApp

func NewConsoleApp() ConsoleApp

NewConsoleApp creates a new console application

func NewConsoleAppWithMode added in v0.8.3

func NewConsoleAppWithMode(mode OutputMode) ConsoleApp

NewConsoleAppWithMode creates a new console application with mode-aware configuration

type ConsoleBuffer added in v0.6.0

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

ConsoleBuffer represents a scrollable buffer with line wrapping

func NewConsoleBuffer added in v0.6.0

func NewConsoleBuffer(maxLines int) *ConsoleBuffer

NewConsoleBuffer creates a new console buffer

func (*ConsoleBuffer) AddContent added in v0.6.0

func (cb *ConsoleBuffer) AddContent(content string)

AddContent adds content that may span multiple lines

func (*ConsoleBuffer) AddLine added in v0.6.0

func (cb *ConsoleBuffer) AddLine(line string)

AddLine adds a new line to the buffer

func (*ConsoleBuffer) Clear added in v0.6.0

func (cb *ConsoleBuffer) Clear()

Clear clears the buffer

func (*ConsoleBuffer) Debug added in v0.6.0

func (cb *ConsoleBuffer) Debug() string

Debug method for troubleshooting

func (*ConsoleBuffer) GetStats added in v0.6.0

func (cb *ConsoleBuffer) GetStats() BufferStats

GetStats returns buffer statistics

func (*ConsoleBuffer) GetVisibleLines added in v0.6.0

func (cb *ConsoleBuffer) GetVisibleLines(viewportHeight int) []string

GetVisibleLines returns the lines that should be visible in the given viewport

func (*ConsoleBuffer) RedrawBuffer added in v0.6.0

func (cb *ConsoleBuffer) RedrawBuffer(terminal TerminalManager, viewportHeight int) error

RedrawBuffer redraws the entire buffer content to the terminal

func (*ConsoleBuffer) ScrollDown added in v0.6.0

func (cb *ConsoleBuffer) ScrollDown(lines int)

ScrollDown scrolls the buffer down by the given number of lines

func (*ConsoleBuffer) ScrollToBottom added in v0.6.0

func (cb *ConsoleBuffer) ScrollToBottom()

ScrollToBottom scrolls to the bottom of the buffer

func (*ConsoleBuffer) ScrollUp added in v0.6.0

func (cb *ConsoleBuffer) ScrollUp(lines int)

ScrollUp scrolls the buffer up by the given number of lines

func (*ConsoleBuffer) SetTerminalWidth added in v0.6.0

func (cb *ConsoleBuffer) SetTerminalWidth(width int)

SetTerminalWidth updates the terminal width and marks for rewrapping

type ContentUpdate added in v0.7.0

type ContentUpdate struct {
	Text string
}

ContentUpdate represents streaming content to append

type Dependencies

type Dependencies struct {
	Terminal   TerminalManager
	Controller *TerminalController
	Layout     LayoutManager
	State      StateManager
	Events     EventBus
}

Dependencies provides access to core services

type DualOutputHandler added in v0.8.3

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

DualOutputHandler implements OutputHandler with dual-mode support

func NewDualOutputHandler added in v0.8.3

func NewDualOutputHandler(cliOutput io.Writer, buffer *ConsoleBuffer) *DualOutputHandler

NewDualOutputHandler creates a new dual-mode output handler

func (*DualOutputHandler) Buffer added in v0.8.3

func (doh *DualOutputHandler) Buffer() *ConsoleBuffer

Buffer returns the console buffer

func (*DualOutputHandler) Mode added in v0.8.3

func (doh *DualOutputHandler) Mode() OutputMode

Mode returns the current output mode

func (*DualOutputHandler) Print added in v0.8.3

func (doh *DualOutputHandler) Print(format string, args ...interface{})

Print writes formatted output

func (*DualOutputHandler) Printf added in v0.8.3

func (doh *DualOutputHandler) Printf(format string, args ...interface{})

Printf writes formatted output

func (*DualOutputHandler) Println added in v0.8.3

func (doh *DualOutputHandler) Println(args ...interface{})

Println writes output with newline

func (*DualOutputHandler) Redraw added in v0.8.3

func (doh *DualOutputHandler) Redraw()

Redraw forces a redraw of the content

func (*DualOutputHandler) SetAutoRedraw added in v0.8.3

func (doh *DualOutputHandler) SetAutoRedraw(auto bool)

SetAutoRedraw controls whether to auto-redraw in interactive mode

func (*DualOutputHandler) SetMode added in v0.8.3

func (doh *DualOutputHandler) SetMode(mode OutputMode)

SetMode changes the output mode

func (*DualOutputHandler) Write added in v0.8.3

func (doh *DualOutputHandler) Write(p []byte) (n int, err error)

Write writes raw bytes

type Event

type Event struct {
	ID        string
	Type      string
	Source    string
	Target    string // Optional specific target
	Data      interface{}
	Timestamp int64
}

Event represents a system event

type EventBus

type EventBus interface {
	// Publishing
	Publish(event Event) error
	PublishAsync(event Event)

	// Subscriptions
	Subscribe(eventType string, handler EventHandler) string
	SubscribeToSource(source string, handler EventHandler) string
	Unsubscribe(subscriptionID string)

	// Event filtering
	SetFilter(filter EventFilter)

	// Control
	Start() error
	Stop() error
}

EventBus provides component communication

func NewEventBus

func NewEventBus(queueSize int) EventBus

NewEventBus creates a new event bus

type EventFilter

type EventFilter func(event Event) bool

EventFilter determines if an event should be processed

type EventHandler

type EventHandler func(event Event) error

EventHandler processes events

type FooterUpdate added in v0.7.0

type FooterUpdate struct {
	Model         string
	Provider      string
	Tokens        int
	Cost          float64
	Iteration     int
	ContextTokens int
	MaxTokens     int
}

FooterUpdate represents footer state change

type InputEvent added in v0.7.0

type InputEvent struct {
	Type InputEventType
	Data interface{}
}

InputEvent represents a keyboard input event

type InputEventType added in v0.7.0

type InputEventType int

InputEventType represents the type of input event

const (
	KeystrokeEvent InputEventType = iota
	InterruptEvent
	ResizeEvent
)

type InputHandler added in v0.7.0

type InputHandler interface {
	HandleInput(event InputEvent) bool // Returns true if event was handled
	GetHandlerID() string
}

InputHandler interface that components can implement to receive input events

type InputRouter added in v0.7.0

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

InputRouter manages routing input events to the currently active handler

func NewInputRouter added in v0.7.0

func NewInputRouter() *InputRouter

NewInputRouter creates a new input router

func (*InputRouter) PublishEvent added in v0.7.0

func (ir *InputRouter) PublishEvent(event InputEvent) bool

PublishEvent sends an input event to the active handler

func (*InputRouter) RegisterHandler added in v0.7.0

func (ir *InputRouter) RegisterHandler(handler InputHandler)

RegisterHandler registers a new input handler

func (*InputRouter) RestoreDefaultHandler added in v0.7.0

func (ir *InputRouter) RestoreDefaultHandler()

RestoreDefaultHandler switches back to the default handler

func (*InputRouter) SendInterrupt added in v0.7.0

func (ir *InputRouter) SendInterrupt() bool

SendInterrupt sends an interrupt event to the active handler

func (*InputRouter) SendKeystroke added in v0.7.0

func (ir *InputRouter) SendKeystroke(data []byte) bool

SendKeystroke sends a keystroke event to the active handler

func (*InputRouter) SetActiveHandler added in v0.7.0

func (ir *InputRouter) SetActiveHandler(handlerID string) bool

SetActiveHandler switches the active input handler

func (*InputRouter) SetDefaultHandler added in v0.7.0

func (ir *InputRouter) SetDefaultHandler(handler InputHandler)

SetDefaultHandler sets the default handler (usually the main console)

func (*InputRouter) Start added in v0.7.0

func (ir *InputRouter) Start()

Start begins processing input events

func (*InputRouter) UnregisterHandler added in v0.7.0

func (ir *InputRouter) UnregisterHandler(handlerID string)

UnregisterHandler removes an input handler

type InteractiveOutputHandler added in v0.8.3

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

InteractiveOutputHandler handles interactive buffer mode output (Vim-like)

func NewInteractiveOutputHandler added in v0.8.3

func NewInteractiveOutputHandler(buffer *ConsoleBuffer, terminal TerminalManager) *InteractiveOutputHandler

NewInteractiveOutputHandler creates a new interactive output handler

func (*InteractiveOutputHandler) Close added in v0.8.3

func (h *InteractiveOutputHandler) Close() error

Close cleans up resources

func (*InteractiveOutputHandler) Flush added in v0.8.3

func (h *InteractiveOutputHandler) Flush() error

Flush ensures output is written to terminal

func (*InteractiveOutputHandler) Mode added in v0.8.3

Mode returns the output mode

func (*InteractiveOutputHandler) Print added in v0.8.3

func (h *InteractiveOutputHandler) Print(format string, args ...interface{})

Print writes formatted output

func (*InteractiveOutputHandler) Printf added in v0.8.3

func (h *InteractiveOutputHandler) Printf(format string, args ...interface{})

Printf writes formatted output

func (*InteractiveOutputHandler) Println added in v0.8.3

func (h *InteractiveOutputHandler) Println(args ...interface{})

Println writes output with newline

func (*InteractiveOutputHandler) Write added in v0.8.3

func (h *InteractiveOutputHandler) Write(p []byte) (int, error)

Write writes raw bytes

type KeystrokeData added in v0.7.0

type KeystrokeData struct {
	Bytes []byte
	Raw   []byte
}

KeystrokeData contains keystroke information

type LayoutManager

type LayoutManager interface {
	// Region management
	DefineRegion(name string, region Region) error
	UpdateRegion(name string, region Region) error
	GetRegion(name string) (Region, error)
	RemoveRegion(name string) error
	ListRegions() []string

	// Layout calculations
	CalculateLayout(termWidth, termHeight int) error
	GetAvailableSpace() Region

	// Rendering control
	BeginBatch()
	EndBatch() error
	RequestRedraw(regionName string)
	ForceRedraw()

	// Z-order management
	SetZOrder(regionName string, zOrder int) error
	GetRenderOrder() []string
}

LayoutManager manages screen regions and rendering order

func NewLayoutManager

func NewLayoutManager(termWidth, termHeight int) LayoutManager

NewLayoutManager creates a new layout manager

type LogInputHandler added in v0.7.0

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

LogInputHandler handles input for the interactive log command

func NewLogInputHandler added in v0.7.0

func NewLogInputHandler() *LogInputHandler

NewLogInputHandler creates a new log input handler

func (*LogInputHandler) Activate added in v0.7.0

func (lih *LogInputHandler) Activate()

Activate enables this handler to receive input

func (*LogInputHandler) CreateReader added in v0.7.0

func (lih *LogInputHandler) CreateReader() *bufio.Reader

CreateReader creates a bufio.Reader-compatible interface for the log handler

func (*LogInputHandler) Deactivate added in v0.7.0

func (lih *LogInputHandler) Deactivate()

Deactivate disables this handler from receiving input

func (*LogInputHandler) GetHandlerID added in v0.7.0

func (lih *LogInputHandler) GetHandlerID() string

GetHandlerID returns the handler identifier

func (*LogInputHandler) HandleInput added in v0.7.0

func (lih *LogInputHandler) HandleInput(event InputEvent) bool

HandleInput processes input events for log navigation

func (*LogInputHandler) ReadString added in v0.7.0

func (lih *LogInputHandler) ReadString(delim byte) (string, error)

ReadString mimics bufio.Reader.ReadString for compatibility with existing log code

type OutputHandler added in v0.8.3

type OutputHandler interface {
	// Mode returns the current output mode
	Mode() OutputMode

	// Print writes formatted output
	Print(format string, args ...interface{})

	// Println writes output with newline
	Println(args ...interface{})

	// Printf writes formatted output
	Printf(format string, args ...interface{})

	// Write writes raw bytes
	Write(p []byte) (n int, err error)

	// Buffer returns the console buffer (nil in CLI mode)
	Buffer() *ConsoleBuffer

	// Redraw forces a redraw of the content (only in interactive mode)
	Redraw()

	// SetMode changes the output mode
	SetMode(mode OutputMode)
}

OutputHandler defines the interface for dual-mode output handling

type OutputMode added in v0.8.3

type OutputMode int

OutputMode represents the different output modes

const (
	// OutputModeCLI is simple CLI output (direct to stdout, cooked terminal)
	OutputModeCLI OutputMode = iota
	// OutputModeInteractive is interactive buffer mode (Vim-like, raw terminal)
	OutputModeInteractive
)

type Region

type Region struct {
	X, Y          int // Top-left corner (0-based)
	Width, Height int
	ZOrder        int // Higher values are on top
	Visible       bool
}

Region represents a rectangular area on the terminal

type RenderMessage added in v0.7.0

type RenderMessage struct {
	Type      string      // "content", "footer", "input", "cursor"
	Component string      // Component name
	Data      interface{} // Type-specific data
	Priority  int         // Higher priority processes first
	Callback  chan error  // Optional callback for completion
}

RenderMessage represents a UI update request

type RenderOp added in v0.7.0

type RenderOp struct {
	Type     string
	Callback func() error
	Priority int // Higher priority ops execute first
}

RenderOp represents a terminal rendering operation

type ResizableComponent

type ResizableComponent interface {
	OnResize(width, height int)
}

ResizableComponent is an interface for components that can handle resize events

type StateCallback

type StateCallback func(key string, oldValue, newValue interface{})

StateCallback is called when state changes

type StateManager

type StateManager interface {
	// State operations
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
	Delete(key string)
	Clear()

	// Transactions
	BeginTransaction()
	Commit()
	Rollback()

	// Subscriptions
	Subscribe(pattern string, callback StateCallback) string
	Unsubscribe(subscriptionID string)

	// Persistence
	Save(path string) error
	Load(path string) error
}

StateManager provides centralized state management

func NewStateManager

func NewStateManager() StateManager

NewStateManager creates a new state manager

type TerminalCleanupHandler added in v0.7.0

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

TerminalCleanupHandler ensures terminal is properly restored on exit

func NewTerminalCleanupHandler added in v0.7.0

func NewTerminalCleanupHandler() *TerminalCleanupHandler

NewTerminalCleanupHandler creates a new cleanup handler

func (*TerminalCleanupHandler) Cleanup added in v0.7.0

func (h *TerminalCleanupHandler) Cleanup()

Cleanup runs all registered cleanup functions

func (*TerminalCleanupHandler) EnsureCleanup added in v0.7.0

func (h *TerminalCleanupHandler) EnsureCleanup()

EnsureCleanup should be deferred in main to ensure cleanup on panic

func (*TerminalCleanupHandler) Register added in v0.7.0

func (h *TerminalCleanupHandler) Register(fn func() error)

Register adds a cleanup function to be called on exit

type TerminalController added in v0.7.0

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

TerminalController centralizes all terminal operations and state management

func NewTerminalController added in v0.7.0

func NewTerminalController(tm TerminalManager, eventBus EventBus) *TerminalController

NewTerminalController creates a new centralized terminal controller

func (*TerminalController) AcquireRawMode added in v0.8.3

func (tc *TerminalController) AcquireRawMode(reason string) (func(), error)

AcquireRawMode increments the raw mode reference count and ensures raw mode is enabled. The returned release function should be called to decrement the reference count when done.

func (*TerminalController) Cleanup added in v0.7.0

func (tc *TerminalController) Cleanup() error

Cleanup shuts down the controller and restores terminal state

func (*TerminalController) ClearLine added in v0.7.0

func (tc *TerminalController) ClearLine() error

ClearLine clears current line immediately

func (*TerminalController) ClearScreen added in v0.7.0

func (tc *TerminalController) ClearScreen() error

ClearScreen clears the entire screen

func (*TerminalController) ClearScrollback added in v0.8.3

func (tc *TerminalController) ClearScrollback() error

ClearScrollback clears the scrollback buffer

func (*TerminalController) ClearToEndOfLine added in v0.7.0

func (tc *TerminalController) ClearToEndOfLine() error

ClearToEndOfLine clears from cursor to end of line (immediate)

func (*TerminalController) ClearToEndOfScreen added in v0.7.0

func (tc *TerminalController) ClearToEndOfScreen() error

ClearToEndOfScreen clears from cursor to end of screen

func (*TerminalController) DisableMouseTracking added in v0.8.3

func (tc *TerminalController) DisableMouseTracking() error

DisableMouseTracking disables terminal mouse reporting and clears the desired state.

func (*TerminalController) EnableMouseTracking added in v0.8.3

func (tc *TerminalController) EnableMouseTracking() error

EnableMouseTracking enables terminal mouse reporting and records the desired state.

func (*TerminalController) EnterAltScreen added in v0.8.3

func (tc *TerminalController) EnterAltScreen() error

EnterAltScreen enters the alternate screen buffer

func (*TerminalController) ExitAltScreen added in v0.8.3

func (tc *TerminalController) ExitAltScreen() error

ExitAltScreen exits the alternate screen buffer

func (*TerminalController) Flush added in v0.7.0

func (tc *TerminalController) Flush() error

Flush ensures all pending operations are rendered

func (*TerminalController) GetSize added in v0.7.0

func (tc *TerminalController) GetSize() (width, height int, err error)

GetSize returns current terminal dimensions

func (*TerminalController) HideCursor added in v0.7.0

func (tc *TerminalController) HideCursor() error

HideCursor hides the cursor (immediate)

func (*TerminalController) Init added in v0.7.0

func (tc *TerminalController) Init() error

Init initializes the terminal controller

func (*TerminalController) IsAltScreen added in v0.8.3

func (tc *TerminalController) IsAltScreen() bool

IsAltScreen returns true when the controller believes the alternate screen is active.

func (*TerminalController) IsRawMode added in v0.7.0

func (tc *TerminalController) IsRawMode() bool

IsRawMode returns current raw mode state

func (*TerminalController) MoveCursor added in v0.7.0

func (tc *TerminalController) MoveCursor(x, y int) error

MoveCursor moves cursor immediately (required for proper rendering)

func (*TerminalController) OnResize added in v0.7.0

func (tc *TerminalController) OnResize(callback func(width, height int))

OnResize registers a callback for terminal resize events

func (*TerminalController) QueueRender added in v0.7.0

func (tc *TerminalController) QueueRender(op RenderOp)

QueueRender adds a rendering operation to the queue

func (*TerminalController) RegisterComponent added in v0.7.0

func (tc *TerminalController) RegisterComponent(name string, component Component, order int)

RegisterComponent adds a component to the controller

func (*TerminalController) ReleaseRawMode added in v0.8.3

func (tc *TerminalController) ReleaseRawMode(reason string)

ReleaseRawMode decrements the raw mode reference count and applies the resulting mode.

func (*TerminalController) ResetScrollRegion added in v0.7.0

func (tc *TerminalController) ResetScrollRegion() error

ResetScrollRegion resets the scrolling region to the entire screen

func (*TerminalController) RestoreCursor added in v0.7.0

func (tc *TerminalController) RestoreCursor() error

RestoreCursor restores the saved cursor position (immediate)

func (*TerminalController) SaveCursor added in v0.7.0

func (tc *TerminalController) SaveCursor() error

SaveCursor saves the current cursor position (immediate)

func (*TerminalController) ScrollDown added in v0.7.0

func (tc *TerminalController) ScrollDown(lines int) error

ScrollDown scrolls the current region down by n lines

func (*TerminalController) ScrollUp added in v0.7.0

func (tc *TerminalController) ScrollUp(lines int) error

ScrollUp scrolls the current region up by n lines

func (*TerminalController) SetInterruptHandler added in v0.7.0

func (tc *TerminalController) SetInterruptHandler(handler func())

SetInterruptHandler sets the interrupt callback

func (*TerminalController) SetRawMode added in v0.7.0

func (tc *TerminalController) SetRawMode(enabled bool) error

SetRawMode enables or disables raw mode atomically

func (*TerminalController) SetScrollRegion added in v0.7.0

func (tc *TerminalController) SetScrollRegion(top, bottom int) error

SetScrollRegion sets scroll region immediately (critical for layout)

func (*TerminalController) ShowCursor added in v0.7.0

func (tc *TerminalController) ShowCursor() error

ShowCursor shows the cursor (immediate)

func (*TerminalController) WithPrimaryScreen added in v0.8.3

func (tc *TerminalController) WithPrimaryScreen(fn func() error) error

WithPrimaryScreen ensures operations run on the primary screen, temporarily leaving the alternate buffer when needed and restoring it afterward.

func (*TerminalController) WithRawMode added in v0.8.3

func (tc *TerminalController) WithRawMode(reason string, fn func() error) error

WithRawMode acquires raw mode, runs the callback, and releases raw mode afterward.

func (*TerminalController) Write added in v0.7.0

func (tc *TerminalController) Write(p []byte) (n int, err error)

Write implements io.Writer with raw mode handling

func (*TerminalController) WriteAt added in v0.7.0

func (tc *TerminalController) WriteAt(x, y int, data []byte) error

WriteAt writes data at a specific position

func (*TerminalController) WriteString added in v0.7.0

func (tc *TerminalController) WriteString(s string) error

WriteString writes a string with proper line ending handling

func (*TerminalController) WriteText added in v0.7.0

func (tc *TerminalController) WriteText(text string) (int, error)

WriteText writes text with automatic raw mode line ending handling

type TerminalManager

type TerminalManager interface {
	// Initialization
	Init() error
	Cleanup() error

	// Size detection
	GetSize() (width, height int, err error)
	OnResize(callback func(width, height int))

	// Terminal modes
	SetRawMode(enabled bool) error
	IsRawMode() bool

	// Cursor control
	MoveCursor(x, y int) error
	SaveCursor() error
	RestoreCursor() error
	HideCursor() error
	ShowCursor() error

	// Screen operations
	ClearScreen() error
	ClearScrollback() error
	ClearLine() error
	ClearToEndOfLine() error
	ClearToEndOfScreen() error
	EnterAltScreen() error
	ExitAltScreen() error
	EnableMouseReporting() error
	DisableMouseReporting() error

	// Scroll region support
	SetScrollRegion(top, bottom int) error
	ResetScrollRegion() error
	ScrollUp(lines int) error
	ScrollDown(lines int) error

	// Output
	Write(data []byte) (int, error)
	WriteText(text string) (int, error) // Automatically handles line endings for raw mode
	WriteAt(x, y int, data []byte) error
	Flush() error
}

TerminalManager handles all terminal operations

func NewTerminalManager

func NewTerminalManager() TerminalManager

NewTerminalManager creates a new terminal manager

type UIHandler

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

UIHandler manages UI events and coordinates component updates

func NewUIHandler

func NewUIHandler(terminal TerminalManager) *UIHandler

NewUIHandler creates a new UI handler

func (*UIHandler) ForceRedraw

func (h *UIHandler) ForceRedraw()

ForceRedraw forces all components to redraw

func (*UIHandler) Initialize

func (h *UIHandler) Initialize() error

Initialize sets up the UI handler and starts listening for events

func (*UIHandler) RegisterComponent

func (h *UIHandler) RegisterComponent(id string, component ResizableComponent)

RegisterComponent registers a component for resize notifications

func (*UIHandler) UnregisterComponent

func (h *UIHandler) UnregisterComponent(id string)

UnregisterComponent removes a component from resize notifications

type UIRenderer added in v0.7.0

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

UIRenderer manages serialized UI updates through a message queue

func NewUIRenderer added in v0.7.0

func NewUIRenderer(tm TerminalManager) *UIRenderer

NewUIRenderer creates a new UI renderer

func (*UIRenderer) AppendContent added in v0.7.0

func (ur *UIRenderer) AppendContent(text string) error

AppendContent is a convenience method for streaming content

func (*UIRenderer) EnableBatching added in v0.7.0

func (ur *UIRenderer) EnableBatching(enabled bool)

EnableBatching enables update batching for efficiency

func (*UIRenderer) RegisterComponent added in v0.7.0

func (ur *UIRenderer) RegisterComponent(name string, component Component)

RegisterComponent registers a component for rendering

func (*UIRenderer) SendMessage added in v0.7.0

func (ur *UIRenderer) SendMessage(msg RenderMessage) error

SendMessage queues a render message

func (*UIRenderer) SendMessageSync added in v0.7.0

func (ur *UIRenderer) SendMessageSync(msg RenderMessage) error

SendMessageSync sends a message and waits for completion

func (*UIRenderer) SetBatchInterval added in v0.7.0

func (ur *UIRenderer) SetBatchInterval(interval time.Duration)

SetBatchInterval sets the batch flush interval

func (*UIRenderer) Start added in v0.7.0

func (ur *UIRenderer) Start()

Start begins the render loop

func (*UIRenderer) Stop added in v0.7.0

func (ur *UIRenderer) Stop()

Stop shuts down the renderer

func (*UIRenderer) UpdateFooter added in v0.7.0

func (ur *UIRenderer) UpdateFooter(update FooterUpdate) error

UpdateFooter is a convenience method for footer updates

type WrappedLine added in v0.6.0

type WrappedLine struct {
	Content    string // The wrapped line content
	OriginalID int    // Index of the original line this came from
	WrapIndex  int    // Which wrap of the original line this is (0 = first)
}

WrappedLine represents a line that has been wrapped for display

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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