Add page-based TUI DSL
Each screen is now a self-contained `page` block with its own `enter`, `render`, and `key` handlers. Shared logic lives in a `helpers` block mixed into the render context. A `chrome` block renders persistent UI (header, sidebar, footer) before every frame. New context primitives: `go(page)` for transitions, `reload` to re-run the current page's `enter` block, `printable` key binding for text input. `FlowRunner#run_tui` now passes the flow context to TUIRunner so username and other session data are available without reaching into internals. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,28 +2,45 @@
|
||||
|
||||
module BBS
|
||||
class TUI
|
||||
attr_reader :init_block, :render_block, :key_bindings
|
||||
attr_reader :init_block, :chrome_block, :pages, :start_page, :helper_module
|
||||
|
||||
def self.define(&block)
|
||||
tui = new
|
||||
tui.instance_eval(&block)
|
||||
tui.freeze
|
||||
tui
|
||||
end
|
||||
|
||||
def initialize
|
||||
@key_bindings = {}
|
||||
@pages = {}
|
||||
@start_page = :idle
|
||||
end
|
||||
|
||||
def init(&block)
|
||||
@init_block = block
|
||||
def init(&block) = @init_block = block
|
||||
def chrome(&block) = @chrome_block = block
|
||||
def start(name) = @start_page = name
|
||||
|
||||
def helpers(&block)
|
||||
@helper_module = Module.new(&block)
|
||||
end
|
||||
|
||||
def render(&block)
|
||||
@render_block = block
|
||||
def page(name, &block)
|
||||
p = Page.new(name)
|
||||
p.instance_eval(&block)
|
||||
@pages[name] = p
|
||||
end
|
||||
|
||||
def key(k, action = nil, &block)
|
||||
@key_bindings[k] = action || block
|
||||
class Page
|
||||
attr_reader :name, :enter_block, :render_block, :key_bindings
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@key_bindings = {}
|
||||
end
|
||||
|
||||
def enter(&block) = @enter_block = block
|
||||
def render(&block) = @render_block = block
|
||||
def key(k, &block) = (@key_bindings[k] = block)
|
||||
def printable(&block) = (@key_bindings[:printable] = block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user