routing_matrix
routing_matrix
¶
A patchbay-style grid for wiring keys to scopes.
Rows are keys, columns are scopes, and every intersection is a connection the operator can toggle — the same mental model as a MIDI routing matrix or a studio patchbay. A moving crosshair (the cursor's whole row and column light up) keeps "which key, which scope" legible even when the grid is sparse.
The widget is a pure view: it renders the routing it is handed and emits
an intent when the operator toggles a cell or asks to mint a key — it
never touches a vault or a backend itself. That keeps it reusable by any
Textual app willing to supply
MatrixKey rows and persist
the CellToggled
intents it posts.
MatrixKey(key_id, label)
dataclass
¶
RoutingMatrix(**kwargs)
¶
Bases: Static
An interactive keys×scopes grid that emits wiring intents.
Start empty; the screen feeds routing through set_routing.
Source code in src/terok/tui/widgets/routing_matrix.py
can_focus = True
class-attribute
instance-attribute
¶
DEFAULT_CSS = '\n RoutingMatrix {\n height: auto;\n padding: 1 2;\n }\n RoutingMatrix:focus {\n background: $surface;\n }\n '
class-attribute
instance-attribute
¶
BINDINGS = [Binding('up,k', 'move(-1, 0)', 'Up', show=False), Binding('down,j', 'move(1, 0)', 'Down', show=False), Binding('left,h', 'move(0, -1)', 'Left', show=False), Binding('right,l', 'move(0, 1)', 'Right', show=False), Binding('space,enter', 'toggle_cell', 'Toggle link'), Binding('n', 'mint', 'Mint key for column')]
class-attribute
instance-attribute
¶
cursor_key
property
¶
The key under the cursor, or None when there are no rows.
cursor_scope
property
¶
The scope under the cursor, or None when there are no columns.
CellToggled(scope, key_id, linked)
¶
Bases: Message
Posted when the operator toggles the cursor cell.
linked is the cell's state before the toggle, so a handler
knows whether it is wiring a new link or cutting an existing one.
Source code in src/terok/tui/widgets/routing_matrix.py
MintRequested(scope)
¶
set_routing(keys, scopes, links, defaults=None)
¶
Replace the rendered routing and clamp the cursor into the new grid.
Source code in src/terok/tui/widgets/routing_matrix.py
action_move(drow, dcol)
¶
Step the cursor, clamped to the grid edges.
Source code in src/terok/tui/widgets/routing_matrix.py
action_toggle_cell()
¶
Emit a toggle intent for the cursor cell.
Source code in src/terok/tui/widgets/routing_matrix.py
action_mint()
¶
render()
¶
Assemble the legend, the numbered header, the key rows, and a status line.