Skip to content

Commit ed63860

Browse files
committed
feat(powershell): interactive db-query sample + docs
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f6f21cf commit ed63860

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ derived from git tags via [MinVer](https://github.com/adamralph/minver) (tag pre
3030
- **Templates** — reusable layouts are PowerShell functions returning parameterized subtrees;
3131
`samples/Strata.Demo.PowerShell` ships a `HostCard` template reused across `ping-monitor.ps1`
3232
and `uptime-monitor.ps1`.
33+
- **Interactive Terminal.Gui apps** (`Strata.Dsl.TerminalGui` + `Show-StrataApp`) — full-screen
34+
apps with focusable `Button` (`-OnSelect`), two-way-bound `TextField` (`-Bind`/`-OnChange`), and
35+
scrollable/selectable `List` (`-Bind`/`-OnEnter`), driven by the reactive store. `StrataElement`
36+
implements `IPseudoStateMutable` so the existing `FocusController`/`SelectionController` toggle
37+
`:focused`/`:selected` on DSL elements. CSS `command:` keymaps register via
38+
`Register-StrataCommand`. Sample: `samples/Strata.Demo.PowerShell/db-query.ps1`.
3339
- **Native widgets & overlay layout** — kind-aware projection of interactive controls and
3440
floating surfaces, in both renderers:
3541
- **Button** — a node of kind `Button` projects to a native control: a Terminal.Gui `Button`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env pwsh
2+
# Interactive DB-query demo: type a query, press Run, scroll the results. Full-screen Terminal.Gui,
3+
# authored in PowerShell on the reactive store.
4+
#
5+
# dotnet build src/Strata.Dsl.TerminalGui/Strata.Dsl.TerminalGui.csproj
6+
# pwsh -File samples/Strata.Demo.PowerShell/db-query.ps1
7+
#
8+
# Tab/arrows move focus, Enter activates the focused control, Esc quits.
9+
10+
$binDir = Resolve-Path "$PSScriptRoot/../../src/Strata.Dsl.TerminalGui/bin/Debug/net10.0"
11+
[System.Runtime.Loader.AssemblyLoadContext]::Default.add_Resolving({
12+
param($context, $assemblyName)
13+
$candidate = Join-Path $binDir "$($assemblyName.Name).dll"
14+
if (Test-Path $candidate) { return $context.LoadFromAssemblyPath($candidate) }
15+
return $null
16+
})
17+
Add-Type -Path (Join-Path $binDir 'Strata.Dsl.TerminalGui.dll')
18+
Import-Module "$PSScriptRoot/../../src/Strata.PowerShell/Strata.PowerShell.psd1" -Force
19+
20+
# Stand-in data source so the demo runs with no database.
21+
function Invoke-DemoQuery([string]$q) {
22+
1..8 | ForEach-Object { "row $_ :: $q" }
23+
}
24+
25+
$store = New-StrataStore @{ query = 'SELECT * FROM users'; rows = @() }
26+
27+
$layout = Stack -Class 'app' {
28+
Text 'DB Query' -Class 'h1'
29+
TextField -Bind '$.query'
30+
Button 'Run' -OnSelect {
31+
param($ctx)
32+
$q = $ctx.Store.State['query'].ToString()
33+
Update-StrataStore $ctx.Store -Set '$.rows' -Value (Invoke-DemoQuery $q)
34+
}
35+
List -Bind '$.rows'
36+
}
37+
38+
Show-StrataApp -Layout $layout -Store $store -Stylesheet "$PSScriptRoot/query.css"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* Strata interactive demo — DB query tool. */
2+
Text.h1 { color: brightcyan; font-weight: bold; }
3+
TextField { color: brightwhite; }
4+
TextField:focused { color: black; background: brightcyan; }
5+
Button { color: brightgreen; }
6+
Button:focused { color: black; background: brightgreen; }
7+
List { color: white; }
8+
List:focused { color: brightyellow; }

src/Strata.PowerShell/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ while ($true) {
4848
}
4949
```
5050

51+
### Interactive apps (full-screen Terminal.Gui)
52+
- `Button 'Run' -OnSelect { param($ctx) ... }` — focusable button; handler gets `$ctx.Store/.Element/.Value`.
53+
- `TextField -Bind '$.query' -OnChange { ... }` — text input, two-way bound to store state.
54+
- `List -Bind '$.rows' -OnEnter { param($ctx) ... }` — scrollable, selectable list bound to an array.
55+
- `Register-StrataCommand -Name '<name>' -Action { param($ctx) ... }` — handler for a CSS
56+
`command: "<name>" when "key.…"` keymap.
57+
- `Show-StrataApp -Layout $layout -Store $store -Stylesheet ./app.css` — blocks on the full-screen
58+
Terminal.Gui loop (Tab/arrows move focus, Enter activates, Esc quits). Headless-safe.
59+
60+
See `samples/Strata.Demo.PowerShell/db-query.ps1`.
61+
5162
### Templates
5263
A reusable layout is a function returning a parameterized subtree — see
5364
`samples/Strata.Demo.PowerShell/StrataTemplates.psm1` (`HostCard`), reused across the ping and

0 commit comments

Comments
 (0)