class TUI::ArrayDetailSource(T)

Overview

Generic DetailDataSource over an in-memory Array(T), id-keyed by a single string-valued property — the direct Detail-side analog of ArrayTableSource(T) for TableDataSource. Simpler than ArrayTableSource since DetailDataSource has no filter/sort/size/reload contract to replicate — just "given an id and the current toggle state, produce label/value rows."

Defined in:

tui/data_sources/array_detail_source.cr
tui/data_sources/array_detail_source_define.cr

Constructors

Macro Summary

Instance Method Summary

Instance methods inherited from class TUI::DetailDataSource

lines(id : String, expansions : Set(Symbol)) : Array(DetailLine) lines, title(id : String) : String title, toggle_label(sym : Symbol) : String toggle_label, toggles : Array(Symbol) toggles

Constructor Detail

def self.new(all : Array(T), id_key : T -> String, lines : T -> Array(DetailLine), toggle_lines : Hash(Symbol, T -> Array(DetailLine)) = {} of Symbol => (T -> Array(DetailLine)), toggle_labels : Hash(Symbol, String) = {} of Symbol => String) #

[View source]

Macro Detail

macro define(name, model_type, all, &block) #

Block-DSL sugar over ArrayDetailSource(T) construction — the Detail-side analog of TUI::Form.define (same "auto-assign the built value straight to a caller-named constant" shape), not of ArrayTableSource.define. Unlike ArrayTableSource, a single ArrayDetailSource instance has no independent per-page state (no filter, no sort, no swapped-in data) — one shared instance covers every consumer, so there's no need for ArrayTableSource.define's named-builder-class indirection (that indirection exists there solely because Crystal disallows declaring a class inside a def body, and Table view/Split window each need their own independent ArrayTableSource instance — neither constraint applies here).

TUI::ArrayDetailSource.define(PACKAGE_DETAIL_SOURCE, Package, FAKE_PACKAGES) do id_key :name line :name, "Name" line :size_mb, "Size", suffix: " MB" toggle :description, "description" do line :description, "Description" end end

all is an ordinary (non-block) macro argument — the data array must already exist as a top-level constant by the time this call executes textually.


[View source]

Instance Method Detail

def lines(id : String, expansions : Set(Symbol)) : Array(DetailLine) #

[View source]
def title(id : String) : String #

[View source]
def toggle_label(sym : Symbol) : String #
Description copied from class TUI::DetailDataSource

Human label for the toggle key bound to sym (e.g. "dependents" for :rdeps) — drives DetailView's status hint, so the letters shown to the user and the letters that actually work can never drift.


[View source]
def toggles : Array(Symbol) #

[View source]