Documentation
¶
Index ¶
- Constants
- func NewDisplayHandler(h HandlerDisplay, color string) *anyHandler
- func NewEditHandler(h HandlerEdit, timeout time.Duration, tracker MessageTracker, color string) *anyHandler
- func NewExecutionHandler(h HandlerExecution, timeout time.Duration, color string) *anyHandler
- func NewInteractiveHandler(h HandlerInteractive, timeout time.Duration, tracker MessageTracker, ...) *anyHandler
- func NewWriterHandler(h HandlerLogger, color string) *anyHandler
- func NewWriterTrackerHandler(h interface{ ... }, color string) *anyHandler
- type ColorPalette
- type DevTUI
- func (t *DevTUI) AddHandler(handler any, timeout time.Duration, color string, tabSection any)
- func (t *DevTUI) AddLogger(name string, enableTracking bool, color string, tabSection any) func(message ...any)
- func (h *DevTUI) ContentView() string
- func (h *DevTUI) Init() tea.Cmd
- func (t *DevTUI) NewTabSection(title, description string) any
- func (h *DevTUI) RefreshUI()
- func (t *DevTUI) ReturnFocus() error
- func (h *DevTUI) SetTestMode(enabled bool)
- func (h *DevTUI) Start(args ...any)
- func (h *DevTUI) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (h *DevTUI) View() string
- type HandlerDisplay
- type HandlerEdit
- type HandlerExecution
- type HandlerInteractive
- type HandlerLogger
- type MessageTracker
- type ShortcutEntry
- type ShortcutProvider
- type ShortcutRegistry
- type TuiConfig
Constants ¶
const HandlerNameWidth = 8
Variables ¶
This section is empty.
Functions ¶
func NewDisplayHandler ¶ added in v0.1.0
func NewDisplayHandler(h HandlerDisplay, color string) *anyHandler
func NewEditHandler ¶ added in v0.1.0
func NewEditHandler(h HandlerEdit, timeout time.Duration, tracker MessageTracker, color string) *anyHandler
func NewExecutionHandler ¶ added in v0.1.0
func NewExecutionHandler(h HandlerExecution, timeout time.Duration, color string) *anyHandler
func NewInteractiveHandler ¶ added in v0.1.0
func NewInteractiveHandler(h HandlerInteractive, timeout time.Duration, tracker MessageTracker, color string) *anyHandler
func NewWriterHandler ¶ added in v0.1.0
func NewWriterHandler(h HandlerLogger, color string) *anyHandler
Types ¶
type ColorPalette ¶ added in v0.0.168
type ColorPalette struct {
// Base (2 colores)
Foreground string // #F4F4F4
Background string // #000000
// Accent (2 colores)
Primary string // #FF6600 (tu actual Primary)
Secondary string // #666666 (tu actual Secondary)
// Semantic (4 colores)
Success string // #00FF00
Warning string // #FFFF00
Error string // #FF0000
Info string // #00FFFF
// UI (2-4 colores adicionales)
Border string // #444444
Muted string // #999999
Selected string // Derivado de Primary
Hover string // Derivado de Primary
}
func DefaultPalette ¶ added in v0.0.168
func DefaultPalette() *ColorPalette
type DevTUI ¶
type DevTUI struct {
*TuiConfig
TabSections []*tabSection // represent sections in the tui
// contains filtered or unexported fields
}
DevTUI mantiene el estado de la aplicación
func NewTUI ¶
NewTUI creates a new DevTUI instance and initializes it.
Usage Example:
config := &TuiConfig{
AppName: "MyApp",
ExitChan: make(chan bool),
Color: nil, // or your *ColorPalette
Logger: func(err any) { fmt.Println(err) },
}
tui := NewTUI(config)
func (*DevTUI) AddHandler ¶ added in v0.1.0
AddHandler is the ONLY method to register handlers of any type. It accepts any handler interface and internally detects the type. Does NOT return anything - enforces complete decoupling.
Supported handler interfaces (from interfaces.go):
- HandlerDisplay: Static/dynamic content display
- HandlerEdit: Interactive text input fields
- HandlerExecution: Action buttons
- HandlerInteractive: Combined display + interaction
- HandlerLogger: Basic line-by-line logging (via MessageTracker detection)
Optional interfaces (detected automatically):
- MessageTracker: Enables message update tracking
- ShortcutProvider: Registers global keyboard shortcuts
Parameters:
- handler: ANY handler implementing one of the supported interfaces
- timeout: Operation timeout (used for Edit/Execution/Interactive handlers, ignored for Display)
- color: Hex color for handler messages (e.g., "#1e40af", empty string for default)
- tabSection: The tab section returned by NewTabSection (as any for decoupling)
Example:
tab := tui.NewTabSection("BUILD", "Compiler")
tui.AddHandler(myEditHandler, 2*time.Second, "#3b82f6", tab)
tui.AddHandler(myDisplayHandler, 0, "", tab)
func (*DevTUI) AddLogger ¶ added in v0.1.0
func (t *DevTUI) AddLogger(name string, enableTracking bool, color string, tabSection any) func(message ...any)
AddLogger creates a logger function with the given name and tracking capability. enableTracking: true = can update existing lines, false = always creates new lines
Parameters:
- name: Logger identifier for message display
- enableTracking: Enable message update tracking (vs always new lines)
- color: Hex color for logger messages (e.g., "#1e40af", empty string for default)
- tabSection: The tab section returned by NewTabSection (as any for decoupling)
Returns:
- Variadic logging function: log("message", values...)
Example:
tab := tui.NewTabSection("BUILD", "Compiler")
log := tui.AddLogger("BuildProcess", true, "#1e40af", tab)
log("Starting build...")
log("Compiling", 42, "files")
func (*DevTUI) ContentView ¶
ContentView renderiza los mensajes para una sección de contenido
func (*DevTUI) NewTabSection ¶ added in v0.0.43
NewTabSection creates a new tab section and returns it as any for interface decoupling. The returned value must be passed to AddHandler/AddLogger methods.
Example:
tab := tui.NewTabSection("BUILD", "Compiler Section")
tui.AddHandler(myHandler, 2*time.Second, "#3b82f6", tab)
func (*DevTUI) RefreshUI ¶ added in v0.2.6
func (h *DevTUI) RefreshUI()
RefreshUI updates the TUI display for the currently active tab. This method is designed to be called from external tools/handlers to notify devtui that the UI needs to be refreshed without creating coupling.
Thread-safe and can be called from any goroutine. Only updates the view if the TUI is actively running.
Usage from external tools:
tui.RefreshUI() // Triggers a UI refresh for the active tab
func (*DevTUI) ReturnFocus ¶
func (*DevTUI) SetTestMode ¶ added in v0.0.125
SetTestMode enables or disables test mode for synchronous behavior in tests. This should only be used in test files to make tests deterministic.
func (*DevTUI) Start ¶ added in v0.0.93
Start initializes and runs the terminal UI application.
It accepts optional variadic arguments of any type. If a *sync.WaitGroup is provided among these arguments, Start will call its Done() method before returning.
The method runs the UI using the internal tea engine, and handles any errors that may occur during execution. If an error occurs, it will be displayed on the console and the application will wait for user input before exiting.
Parameters:
- args ...any: Optional arguments. Can include a *sync.WaitGroup for synchronization.
type HandlerDisplay ¶ added in v0.0.117
type HandlerDisplay interface {
Name() string // Full text to display in footer (handler responsible for content) eg. "System Status Information Display"
Content() string // Display content (e.g., "help\n1-..\n2-...", "executing deploy wait...")
}
HandlerDisplay defines the interface for read-only information display handlers. These handlers show static or dynamic content without user interaction.
type HandlerEdit ¶ added in v0.0.117
type HandlerEdit interface {
Name() string // Identifier for logging: "ServerPort", "DatabaseURL"
Label() string // Field label (e.g., "Server Port", "Host Configuration")
Value() string // Current/initial value (e.g., "8080", "localhost")
Change(newValue string, progress func(msgs ...any)) // New signature: no error, not variadic, string
}
HandlerEdit defines the interface for interactive fields that accept user input. These handlers allow users to modify values through text input.
type HandlerExecution ¶ added in v0.0.117
type HandlerExecution interface {
Name() string // Identifier for logging: "DeployProd", "BuildProject"
Label() string // Button label (e.g., "Deploy to Production", "Build Project")
Execute(progress func(msgs ...any)) // New signature: no error, not variadic
}
HandlerExecution defines the interface for action buttons that execute operations. These handlers trigger business logic when activated by the user.
type HandlerInteractive ¶ added in v0.0.149
type HandlerInteractive interface {
Name() string // Identifier for logging: "ChatBot", "ConfigWizard"
Label() string // Field label (updates dynamically)
Value() string // Current input value
Change(newValue string, progress func(msgs ...any)) // Handle user input + content display via progress
WaitingForUser() bool // Should edit mode be auto-activated?
}
HandlerInteractive defines the interface for interactive content handlers. These handlers combine content display with user interaction capabilities. All content display is handled through progress() for consistency.
type HandlerLogger ¶ added in v0.0.176
type HandlerLogger interface {
Name() string // Writer identifier (e.g., "webBuilder", "ApplicationLog")
}
HandlerLogger defines the interface for basic writers that create new lines for each write. These writers are suitable for simple logging or output display.
type MessageTracker ¶ added in v0.0.116
MessageTracker provides optional interface for message tracking control. Handlers can implement this to control message updates and operation tracking.
type ShortcutEntry ¶ added in v0.0.161
type ShortcutEntry struct {
Key string // The shortcut key (e.g., "c", "d", "p")
Description string // Human-readable description (e.g., "coding mode", "debug mode")
TabIndex int // Index of the tab containing the handler
FieldIndex int // Index of the field within the tab
HandlerName string // Handler name for identification
Value string // Value to pass to Change()
}
ShortcutEntry represents a registered shortcut
type ShortcutProvider ¶ added in v0.0.161
type ShortcutProvider interface {
Shortcuts() []map[string]string // Returns ordered list of single-entry maps with shortcut->description, preserving registration order
}
ShortcutProvider defines the optional interface for handlers that provide global shortcuts. HandlerEdit implementations can implement this interface to enable global shortcut keys.
type ShortcutRegistry ¶ added in v0.0.161
type ShortcutRegistry struct {
// contains filtered or unexported fields
}
ShortcutRegistry manages global shortcut keys
func (*ShortcutRegistry) Get ¶ added in v0.0.161
func (sr *ShortcutRegistry) Get(key string) (*ShortcutEntry, bool)
func (*ShortcutRegistry) GetAll ¶ added in v0.0.161
func (sr *ShortcutRegistry) GetAll() map[string]*ShortcutEntry
GetAll returns all registered shortcuts for UI display
func (*ShortcutRegistry) List ¶ added in v0.0.161
func (sr *ShortcutRegistry) List() []string
func (*ShortcutRegistry) Register ¶ added in v0.0.161
func (sr *ShortcutRegistry) Register(key string, entry *ShortcutEntry)
func (*ShortcutRegistry) Unregister ¶ added in v0.0.161
func (sr *ShortcutRegistry) Unregister(key string)
type TuiConfig ¶
type TuiConfig struct {
AppName string // app name eg: "MyApp"
ExitChan chan bool // global chan to close app eg: make(chan bool)
/*// *ColorPalette style for the TUI
// if nil it will use default style:
type ColorPalette struct {
Foreground string // eg: #F4F4F4
Background string // eg: #000000
Primary string // eg: #FF6600
Secondary string // eg: #666666
}*/
Color *ColorPalette
Logger func(messages ...any) // function to write log error
}
