Documentation
¶
Index ¶
- func MatchesKeyBinding(event *tcell.EventKey, binding config.KeyBinding) bool
- func ParseAlignment(align string) int
- type BoundView
- type ColorHelper
- type Context
- func (c *Context) GetState(key string) (interface{}, bool)
- func (c *Context) HasDirtyKeys() bool
- func (c *Context) OnStateChange(key string, fn func(interface{}))
- func (c *Context) RefreshDirtyBoundViews()
- func (c *Context) RegisterBoundView(key string, bv BoundView)
- func (c *Context) RegisterFormCancel(name string, callback func())
- func (c *Context) RegisterFormSubmit(name string, callback func())
- func (c *Context) RunCallback(templateStr string)
- func (c *Context) RunFormCancel(name string)
- func (c *Context) RunFormSubmit(name string)
- func (c *Context) SetExecutor(e *Executor)
- func (c *Context) SetState(key string, value interface{})
- func (c *Context) SetStateDirect(key string, value interface{})
- type Executor
- type FunctionRegistry
- func (r *FunctionRegistry) Get(name string) (*TemplateFunction, bool)
- func (r *FunctionRegistry) GetEvaluator(name string) (*TemplateEvaluator, bool)
- func (r *FunctionRegistry) Register(name string, minArgs int, maxArgs *int, ...) error
- func (r *FunctionRegistry) RegisterEvaluator(name string, minArgs, maxArgs int, handler func(*Context, []string) string) error
- type TemplateEvaluator
- type TemplateFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchesKeyBinding ¶
func MatchesKeyBinding(event *tcell.EventKey, binding config.KeyBinding) bool
MatchesKeyBinding returns true if the given key event matches the binding. The binding.Key string supports formats like "Escape", "Enter", "Ctrl+Q", "Ctrl+C", "F1", "Alt+a".
func ParseAlignment ¶
ParseAlignment converts alignment strings to tview alignment constants
Types ¶
type BoundView ¶
type BoundView struct {
Refresh func() string // returns evaluated template string
SetText func(string) // applies the string to the view
}
BoundView refreshes a view when its state key changes; used for deferred refresh from SetInputCapture.
type Context ¶
type Context struct {
App *tview.Application
Pages *tview.Pages
Colors *ColorHelper
// contains filtered or unexported fields
}
Context provides the execution context for templates
func NewContext ¶
func NewContext(app *tview.Application, pages *tview.Pages) *Context
NewContext creates a new template context
func (*Context) HasDirtyKeys ¶
HasDirtyKeys returns true if any state key has been marked dirty (e.g. by SetStateDirect).
func (*Context) OnStateChange ¶
OnStateChange subscribes to state changes for the given key. The callback runs on the main goroutine when SetState is called for that key.
func (*Context) RefreshDirtyBoundViews ¶
func (c *Context) RefreshDirtyBoundViews()
RefreshDirtyBoundViews evaluates and updates all bound views for dirty keys, then runs OnStateChange callbacks for those keys. Must be run on the main goroutine (e.g. via QueueUpdateDraw from a background refresh goroutine).
func (*Context) RegisterBoundView ¶
RegisterBoundView registers a view that displays state for key. It will be refreshed when RefreshDirtyBoundViews runs (on next key event), not from inside handlers.
func (*Context) RegisterFormCancel ¶
RegisterFormCancel registers a form's cancel callback by name so runFormCancel(formName) can invoke it (e.g. from a button).
func (*Context) RegisterFormSubmit ¶
RegisterFormSubmit registers a form's submit callback by name so runFormSubmit(formName) can invoke it (e.g. from a button).
func (*Context) RunCallback ¶
RunCallback executes a template expression (e.g. "switchToPage \"main\"") and runs the resulting callback. No-op if executor is not set or execution fails.
func (*Context) RunFormCancel ¶
RunFormCancel runs the cancel callback registered for the given form name. No-op if name is unknown.
func (*Context) RunFormSubmit ¶
RunFormSubmit runs the submit callback registered for the given form name. No-op if name is unknown.
func (*Context) SetExecutor ¶
SetExecutor sets the template executor so RunCallback can execute template expressions (e.g. from modal onDone). Called by the app builder after creating the executor.
func (*Context) SetState ¶
SetState updates the view model state and notifies subscribers. Safe to call from goroutines; notifications run on main via App.QueueUpdateDraw.
func (*Context) SetStateDirect ¶
SetStateDirect updates state and marks the key dirty. Bound views are refreshed later from RefreshDirtyBoundViews (e.g. in SetInputCapture) to avoid deadlock.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles template execution
func NewExecutor ¶
func NewExecutor(ctx *Context, registry *FunctionRegistry) *Executor
NewExecutor creates a new template executor
func (*Executor) EvaluateToString ¶
EvaluateToString evaluates a template string containing {{ bindState key }} (and other evaluators) and returns the rendered string. Example: "Notification: {{ bindState notification }}" -> "Notification: Hello" when state "notification" is "Hello"
func (*Executor) ExecuteCallback ¶
ExecuteCallback parses and executes a template expression to create a callback function
func (*Executor) ExtractBindStateKeys ¶
ExtractBindStateKeys returns all state keys referenced by bindState in the template string. Used to subscribe to state changes for re-evaluation.
type FunctionRegistry ¶
type FunctionRegistry struct {
// contains filtered or unexported fields
}
FunctionRegistry manages registered template functions
func NewFunctionRegistry ¶
func NewFunctionRegistry() *FunctionRegistry
NewFunctionRegistry creates a new function registry with built-in functions
func (*FunctionRegistry) Get ¶
func (r *FunctionRegistry) Get(name string) (*TemplateFunction, bool)
Get retrieves a template function by name
func (*FunctionRegistry) GetEvaluator ¶
func (r *FunctionRegistry) GetEvaluator(name string) (*TemplateEvaluator, bool)
GetEvaluator retrieves an evaluator by name
func (*FunctionRegistry) Register ¶
func (r *FunctionRegistry) Register(name string, minArgs int, maxArgs *int, validator func(*Context, []string) error, handler interface{}) error
Register adds a new template function to the registry
func (*FunctionRegistry) RegisterEvaluator ¶
func (r *FunctionRegistry) RegisterEvaluator(name string, minArgs, maxArgs int, handler func(*Context, []string) string) error
RegisterEvaluator adds a value-returning template function (e.g. bindState)