@@ -20,12 +20,18 @@ public sealed class StrataInteractiveHost
2020 private readonly StrataElement _root ;
2121 private readonly StrataStore _store ;
2222 private readonly Action < string , StrataUiEvent > _invokeHandler ;
23+ private readonly string [ ] _commandNames ;
2324
24- private StrataInteractiveHost ( StrataElement root , StrataStore store , Action < string , StrataUiEvent > invokeHandler )
25+ private StrataInteractiveHost (
26+ StrataElement root ,
27+ StrataStore store ,
28+ Action < string , StrataUiEvent > invokeHandler ,
29+ IEnumerable < string > ? commandNames )
2530 {
2631 _root = root ;
2732 _store = store ;
2833 _invokeHandler = invokeHandler ;
34+ _commandNames = commandNames ? . ToArray ( ) ?? Array . Empty < string > ( ) ;
2935 }
3036
3137 /// <summary>Copy each bound list's resolved array into its <c>items</c> attribute for the projection.</summary>
@@ -62,6 +68,21 @@ public static void WriteFieldValue(StrataElement field, StrataStore store, strin
6268 }
6369 }
6470
71+ /// <summary>
72+ /// Build the <see cref="CommandHandler"/> that bridges a CSS <c>command:</c> keymap named
73+ /// <paramref name="name"/> to the author's dispatcher: when the command fires, invoke the
74+ /// PowerShell handler registered under <c>cmd:<name></c> with the focused element.
75+ /// </summary>
76+ public static CommandHandler MakeCommandHandler (
77+ string name , StrataStore store , StrataElement fallback , Action < string , StrataUiEvent > invoke )
78+ {
79+ ArgumentNullException . ThrowIfNull ( name ) ;
80+ ArgumentNullException . ThrowIfNull ( store ) ;
81+ ArgumentNullException . ThrowIfNull ( fallback ) ;
82+ ArgumentNullException . ThrowIfNull ( invoke ) ;
83+ return ctx => invoke ( $ "cmd:{ name } ", new StrataUiEvent ( store , ctx . Node as StrataElement ?? fallback , null ) ) ;
84+ }
85+
6586 private static JsonNode ? ResolveFirst ( string jsonPath , JsonObject state )
6687 {
6788 var result = JsonPath . Parse ( jsonPath ) . Evaluate ( state ) ;
@@ -81,14 +102,15 @@ public static string Run(
81102 StrataElement root ,
82103 string cssPath ,
83104 StrataStore store ,
84- Action < string , StrataUiEvent > invokeHandler )
105+ Action < string , StrataUiEvent > invokeHandler ,
106+ IEnumerable < string > ? commandNames = null )
85107 {
86108 ArgumentNullException . ThrowIfNull ( root ) ;
87109 ArgumentNullException . ThrowIfNull ( cssPath ) ;
88110 ArgumentNullException . ThrowIfNull ( store ) ;
89111 ArgumentNullException . ThrowIfNull ( invokeHandler ) ;
90112
91- var host = new StrataInteractiveHost ( root , store , invokeHandler ) ;
113+ var host = new StrataInteractiveHost ( root , store , invokeHandler , commandNames ) ;
92114
93115 var registry = StylingProperties . CreateRegistry ( ) ;
94116 InteractionProperties . RegisterAll ( registry ) ;
@@ -130,6 +152,10 @@ private string RunLoop(
130152
131153 using var input = new TerminalGuiInputSource ( ) ;
132154 var commands = new CommandRegistry ( ) ;
155+ foreach ( var name in _commandNames )
156+ {
157+ commands . Register ( name , MakeCommandHandler ( name , _store , _root , _invokeHandler ) ) ;
158+ }
133159 using var interaction = new InteractionHost ( input , commands ) ;
134160
135161 void Render ( )
0 commit comments