A live session keeps a dashboard on screen while your work runs. Any thread can update a widget by its WidgetId, the screen redraws about 15 times a second with only the cells that changed, and the terminal is restored when the work ends. In PowerShell the session is Invoke-ConsoleDashboard; in C# it is LiveSession.
A dashboard updated from three threads
Each server is deployed in parallel and updates its own lane by key. The session applies the updates on its render thread about 15 times a second, and output written from any thread lands in the log panel.
Deploy 00:00:01 ╭─ Servers ──────────────────────────────────────────────────────────────────────────── 3 workers ─╮ │ ⠏ SRV1 ━━━━━━━━━━━━━━━╸─────────────── 50% ✓ 2 ✗ 0 ▲ 0 swapping folders │ │ ⠋ SRV2 ━━━━━━━━━━━━━━━━━━━━━━━──────── 75% ✓ 3 ✗ 0 ▲ 0 starting the site │ │ ⠙ SRV3 ━━━━━━━━━━━━━━━╸─────────────── 50% ✓ 2 ✗ 0 ▲ 0 swapping folders │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─ Log ────────────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ctrl+c stop
Install-Module ConsoleMonster -Scope CurrentUser# Three servers deployed in parallel. Each runspace updates its own lane by name; Write-Host from any of them lands
# in the log panel instead of writing over the screen.
$dashboard = New-ConsoleDashboard -Title 'Deploy' -Content {
New-ConsolePanel -Title 'Servers' -HeaderRight '3 workers' -Content {
New-ConsoleLanes -WidgetId servers -Content {
foreach ($server in 'SRV1', 'SRV2', 'SRV3') { @{ Key = $server; Total = 4 } }
}
}
New-ConsolePanel -Title 'Log' -Fill -Content { New-ConsoleLogRegion }
}
'SRV1', 'SRV2', 'SRV3' | Invoke-ConsoleDashboard $dashboard -Parallel -ThrottleLimit 3 {
param($Server)
$null = Get-Random -SetSeed ([int] $Server[-1])
foreach ($step in 'copying files', 'stopping the site', 'swapping folders',
'starting the site') {
Update-Console -WidgetId servers -Key $Server -Status Running -Detail $step
Start-Sleep -Milliseconds (400 + (Get-Random -Minimum 0 -Maximum 500))
Update-Console -WidgetId servers -Key $Server -Result Pass
}
Write-Host "$Server done"
Update-Console -WidgetId servers -Key $Server -Complete
}Full program
Import-Module ConsoleMonster
# Three servers deployed in parallel. Each runspace updates its own lane by name; Write-Host from any of them lands
# in the log panel instead of writing over the screen.
$dashboard = New-ConsoleDashboard -Title 'Deploy' -Content {
New-ConsolePanel -Title 'Servers' -HeaderRight '3 workers' -Content {
New-ConsoleLanes -WidgetId servers -Content {
foreach ($server in 'SRV1', 'SRV2', 'SRV3') { @{ Key = $server; Total = 4 } }
}
}
New-ConsolePanel -Title 'Log' -Fill -Content { New-ConsoleLogRegion }
}
'SRV1', 'SRV2', 'SRV3' | Invoke-ConsoleDashboard $dashboard -Parallel -ThrottleLimit 3 {
param($Server)
$null = Get-Random -SetSeed ([int] $Server[-1])
foreach ($step in 'copying files', 'stopping the site', 'swapping folders',
'starting the site') {
Update-Console -WidgetId servers -Key $Server -Status Running -Detail $step
Start-Sleep -Milliseconds (400 + (Get-Random -Minimum 0 -Maximum 500))
Update-Console -WidgetId servers -Key $Server -Result Pass
}
Write-Host "$Server done"
Update-Console -WidgetId servers -Key $Server -Complete
}Run: pwsh ./session.ps1
dotnet new console -n Deploy
cd Deploy
dotnet add package ConsoleMonster// Three servers deployed in parallel. Handles post updates from any thread; Console.WriteLine from any of them lands
// in the log panel instead of writing over the screen.
Lanes lanes = new Lanes();
Dashboard dashboard = Ui.Dashboard().Title("Deploy")
.Content(body => body
.Panel(new Panel(lanes, "Servers") { HeaderRight = "3 workers" })
.Add(new Panel(new LogRegion(), "Log").Fill()));
string[] steps = { "copying files", "stopping the site", "swapping folders", "starting the site" };
foreach (string server in new[] { "SRV1", "SRV2", "SRV3" }
)
{
lanes.Add(server, server, steps.Length);
}
using (LiveSession session = new LiveSession(dashboard))
{
session.Run(s =>
{
LanesHandle servers = lanes.Handle(s);
Parallel.ForEach(new[] { "SRV1", "SRV2", "SRV3" }, server =>
{
Random random = new Random(server[^1]);
servers.Start(server);
foreach (string step in steps)
{
servers.Start(server, step);
Thread.Sleep(400 + random.Next(500));
servers.Advance(server, StatusKind.Pass);
}
Console.WriteLine(server + " done");
servers.Complete(server);
});
});
}Full program
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Live;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Three servers deployed in parallel. Handles post updates from any thread; Console.WriteLine from any of them lands
// in the log panel instead of writing over the screen.
Lanes lanes = new Lanes();
Dashboard dashboard = Ui.Dashboard().Title("Deploy")
.Content(body => body
.Panel(new Panel(lanes, "Servers") { HeaderRight = "3 workers" })
.Add(new Panel(new LogRegion(), "Log").Fill()));
string[] steps = { "copying files", "stopping the site", "swapping folders", "starting the site" };
foreach (string server in new[] { "SRV1", "SRV2", "SRV3" }
)
{
lanes.Add(server, server, steps.Length);
}
using (LiveSession session = new LiveSession(dashboard))
{
session.Run(s =>
{
LanesHandle servers = lanes.Handle(s);
Parallel.ForEach(new[] { "SRV1", "SRV2", "SRV3" }, server =>
{
Random random = new Random(server[^1]);
servers.Start(server);
foreach (string step in steps)
{
servers.Start(server, step);
Thread.Sleep(400 + random.Next(500));
servers.Advance(server, StatusKind.Pass);
}
Console.WriteLine(server + " done");
servers.Complete(server);
});
});
}Run: dotnet run
The recording ran the PowerShell script. This C# program does the same with the library and compiles as shown; its timings are its own.
dotnet new console -n Deploy
cd Deploy
dotnet add package ConsoleMonster// Three servers deployed in parallel. Handles post updates from any thread; Console.WriteLine from any of them lands
// in the log panel instead of writing over the screen.
Lanes lanes = Ui.Lanes();
Dashboard dashboard = Ui.Dashboard()
.Title("Deploy")
.Content(body => body.Panel(Ui.Panel()
.Title("Servers")
.HeaderRight("3 workers")
.Content(panelContent =>
{
panelContent.Add(lanes);
})).Add(Ui.Panel().Title("Log").Content(panelContent =>
{
panelContent.LogRegion();
}).Fill()));
string[] steps = { "copying files", "stopping the site", "swapping folders", "starting the site" };
foreach (string server in new[] { "SRV1", "SRV2", "SRV3" }
)
{
lanes.Add(server, server, steps.Length);
}
using (LiveSession session = dashboard.CreateSession())
{
session.Run(s =>
{
LanesHandle servers = lanes.Handle(s);
Parallel.ForEach(new[] { "SRV1", "SRV2", "SRV3" }, server =>
{
Random random = new Random(server[^1]);
servers.Start(server);
foreach (string step in steps)
{
servers.Start(server, step);
Thread.Sleep(400 + random.Next(500));
servers.Advance(server, StatusKind.Pass);
}
Console.WriteLine(server + " done");
servers.Complete(server);
});
});
}
Full program
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Live;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Three servers deployed in parallel. Handles post updates from any thread; Console.WriteLine from any of them lands
// in the log panel instead of writing over the screen.
Lanes lanes = Ui.Lanes();
Dashboard dashboard = Ui.Dashboard()
.Title("Deploy")
.Content(body => body.Panel(Ui.Panel()
.Title("Servers")
.HeaderRight("3 workers")
.Content(panelContent =>
{
panelContent.Add(lanes);
})).Add(Ui.Panel().Title("Log").Content(panelContent =>
{
panelContent.LogRegion();
}).Fill()));
string[] steps = { "copying files", "stopping the site", "swapping folders", "starting the site" };
foreach (string server in new[] { "SRV1", "SRV2", "SRV3" }
)
{
lanes.Add(server, server, steps.Length);
}
using (LiveSession session = dashboard.CreateSession())
{
session.Run(s =>
{
LanesHandle servers = lanes.Handle(s);
Parallel.ForEach(new[] { "SRV1", "SRV2", "SRV3" }, server =>
{
Random random = new Random(server[^1]);
servers.Start(server);
foreach (string step in steps)
{
servers.Start(server, step);
Thread.Sleep(400 + random.Next(500));
servers.Advance(server, StatusKind.Pass);
}
Console.WriteLine(server + " done");
servers.Complete(server);
});
});
}
Run: dotnet run
The recording ran the PowerShell script. This C# program does the same with the library and compiles as shown; its timings are its own.
See also: Invoke-ConsoleDashboard, LiveSession (C#)
The live dashboards page shows larger programs built the same way, recorded under load.
What a session takes care of
- Threads. Handles (
lanes.Handle(session)) post events from any thread. An ambientTerminalScopelets deep code report status without passing the session around. Threads and concurrency explains the model and what is safe from which thread. - Console output.
Console.OutandConsole.Errorare captured into the log region while the session runs (CaptureConsole, on by default). In PowerShell,Invoke-ConsoleDashboardruns the script in a runspace whoseWrite-Host, warnings, errors and verbose output land there too. - The end. The screen is restored, also on Ctrl+C and exceptions, and the final state (or
LiveSessionOptions.Summary) is printed to the scrollback. - Problems. Updates for an unknown
WidgetId, failed updates and frames that could not be laid out are counted (GetCounters()) and reported once the screen is restored.
Inline areas and Write-Progress
LiveMode.Inline (Invoke-ConsoleDashboard -Inline) draws an area as tall as its content below the cursor; output scrolls above it and the final state stays in the scrollback, or nothing with -PrintFinalState:$false. Write-Progress in a dashboard script shows as nested activities, and Use-ConsoleProgress renders an existing script's Write-Progress inline without changing it.
Progress columns
Lanes and ProgressBar take a column model. Without Columns they keep the classic layout: label, bar, percentage, pass, fail and warning counts, and the detail.
Import-Module ConsoleMonster
$servers = @(
[pscustomobject]@{ Key = 'dc01'; Label = 'DC01'; Total = 40 }
[pscustomobject]@{ Key = 'dc02'; Label = 'DC02'; Total = 40 }
)
$servers | New-ConsoleLanes -WidgetId servers -HideCompleted -Columns Standard, Rate | Show-Console
New-ConsoleProgress -Label 'Upload' -Total 500MB -Columns Description, Bar, Percent, ByteRate, Remaining | Show-Console
using ConsoleMonster;
using ConsoleMonster.Widgets;
Lanes lanes = new Lanes();
lanes.Columns = ProgressColumns.Standard(); // spinner, description, bar, %, count, elapsed, ETA, status
lanes.Columns.Insert(7, ProgressColumns.Rate(unit: "files")); // "12 files/s"; Rate(bytes: true) shows "1.5 MB/s"
lanes.Columns.Add(ProgressColumns.Custom("Phase", row => row.IsFinished ? "verified" : "copying"));
lanes.HideCompleted = true; // finished lanes leave; the summary line counts them
lanes.Add("dc01", "DC01", 40);
lanes.Add("dc02", "DC02", 40);
Terminal.Write(lanes);
using ConsoleMonster;
using ConsoleMonster.Widgets;
IList<ProgressColumn> columns = ProgressColumns.Standard(); // spinner, description, bar, %, count, elapsed, ETA, status
columns.Insert(7, ProgressColumns.Rate(unit: "files")); // "12 files/s"; Rate(bytes: true) shows "1.5 MB/s"
Lanes lanes = Ui.Lanes()
.Columns(columns)
.Column(ProgressColumns.Custom("Phase", row => row.IsFinished ? "verified" : "copying"))
.HideCompleted(); // finished lanes leave; the summary line counts them
lanes.Add("dc01", "DC01", 40);
lanes.Add("dc02", "DC02", 40);
lanes.Show();
Rate and remaining time are smoothed over a moving window (10 seconds by default), so a stalled task's rate falls instead of freezing. When the region is too narrow, the lowest-priority columns go first, and in stream mode the heartbeat line summarises the running lanes through the same columns.
Replaceable regions and live tables
A RegionWidget is a named region whose widget is replaced while the session runs; the swap is safe from any thread and lands between frames. LiveTable is a table whose rows have stable keys and are added, updated, removed or cleared; its column widths only grow, MaxRows keeps the most recent rows and SortColumn keeps them sorted.
Import-Module ConsoleMonster
$controllers = @(
[pscustomobject] @{ Name = 'DC01'; Site = 'Warsaw'; Status = 'Pass' }
[pscustomobject] @{ Name = 'DC02'; Site = 'Dublin'; Status = 'Warn' }
)
$d = New-ConsoleDashboard -Title 'Domain health' -Content {
New-ConsolePanel -Title 'Domain controllers' -Content { New-ConsoleRegion -WidgetId main -Content { New-ConsoleProgress -Label 'Querying' -Indeterminate -WidgetId 'spinner' } }
New-ConsolePanel -Title 'Jobs' -Fill -Content { New-ConsoleTable -WidgetId jobs -MaxRows 8 -Live -Property 'Job', 'State', 'Took' }
}
Invoke-ConsoleDashboard $d {
Update-Console -WidgetId jobs -Row ([pscustomobject]@{ Key = 'dns@DC01'; Values = @('dns', 'Running', ([timespan]::Zero)) })
Start-Sleep -Seconds 1
Update-Console -WidgetId jobs -Row ([pscustomobject]@{ Key = 'dns@DC01'; Values = @('dns', 'Done', ([timespan]::FromSeconds(1))) })
Update-Console -WidgetId main -Content { $using:controllers | New-ConsoleTable }
Start-Sleep -Seconds 1
}
A recording keeps the text form of row values; region swaps carry in-process widgets and are not replayed.
Step ledgers
For a list of build steps, Phases with StepCounter = true draws one numbered row per step. A running step spins and shows its latest detail and how long it has been running; a finished step keeps the time it took after its detail. A group step lists its items under it, and an item can list sub-items (SetSubItem), so a step, its stages and their packages nest; items keep their own time the same way. A step planned after the run started goes in at its place with Insert, and re-adding a step changes only its label, so a running step can be retitled. When the list is taller than an inline area, finished groups fold into their row (149/149 · 40s), so finished rows never push the running step off the screen. If it still does not fit, it shows whole steps around the furthest step that has started, with the next step below it, running steps above pinned under +N earlier, and +N more for the rest. The window only moves forward, and the final printed ledger lists every item. To keep a current-work line and a message log under the ledger, put the ledger in Rows as a fraction row (fraction rows are measured after the auto rows below them) and set LogRegion.FitToEntries, so the log takes no rows until messages arrive. LiveTable.MaxRows keeps only the newest rows and removes older ones, so it suits a recent-items list rather than a ledger.
Host output while a session runs
A PowerShell warning, a verbose line or a prompt does not pass through the session. session.WriteOutside(action) clears an inline area (a full-screen session leaves the alternate screen), runs the action on the calling thread for as long as it needs, then starts the area again below what it wrote, so later frames never draw over it. Nothing is drawn while the action runs, and updates are still applied. Compiled cmdlets use HostOutput.Run, described under add-ons.
Resizing and small windows
A size change clears the screen and redraws it, also while the window is being dragged. Narrower panels drop optional parts first, table columns hide by priority and tables turn into cards. When the window is smaller than the dashboard's MinimumSize, it keeps its highest-priority panels, and when even those do not fit, it shows one status line.
Nightly checks · ad.adatum.com forest assessmen… ● evaluating 332 rules on 6 workers · 00:00:26 ✓ Discover 2.8s › ✓ Collect 4.0s › ⠋ Evaluate › ○ Report ╭─ Targets ───────────────────────────────────────────── 6 workers ─╮ ╭─ Results ──────────────────╮ │ ⠋ ad.adatum.com (domai… ━━━━━━━━━━━━━────── 68% ✓ 7 ✗ 1 ▲ 3 │ │ █████████████████████ 162 │ │ ✗ eu.ad.adatum.com (do… ━━━━━━━━━━━━━━━━━━━ 100% ✓ 13 ✗ 1 ▲ 1 │ │ █ ✓ Passed 131 81% │ │ ▲ DC01.ad.adatum.com ━━━━━━━━━━━━━━━━━━━ 100% ✓ 26 ✗ 0 ▲ 3 │ │ █ ▲ Warnings 21 13% │ │ ▲ DC02.ad.adatum.com ━━━━━━━━━━━━━━━━━━━ 100% ✓ 23 ✗ 0 ▲ 6 │ │ █ ✗ Failed 6 4% │ │ ✓ DC03.ad.adatum.com ━━━━━━━━━━━━━━━━━━━ 100% ✓ 23 ✗ 3 ▲ 4 │ │ █ – Skipped 4 2% │ │ ⠴ DC04.ad.adatum.com ━━━━━━━━━━━━━━━━━╸─ 93% ✓ 23 ✗ 1 ▲ 3 │ │ ────────────────────────── │ │ ⠦ DC05.ad.adatum.com ━━━━╸────────────── 23% ✓ 6 ✗ 0 ▲ 1 │ │ Evaluated 149 / 332 │ │ ⠧ DC06.ad.adatum.com ━━╸──────────────── 13% ✓ 4 ✗ 0 ▲ 0 │ │ Average r… 7.8 rules/s │ │ ⠇ DC07.eu.ad.adatum.com ━━━━─────────────── 20% ✓ 6 ✗ 0 ▲ 0 │ │ Remaining ~24s │ │ ○ DC08.eu.ad.adatum.com ─────────────────── │ │ Targets d… 3 / 12 │ │ ○ DC09.eu.ad.adatum.com ─────────────────── │ │ Targets f… 1 │ │ ○ DC10.eu.ad.adatum.com ─────────────────── │ │ │ ╰───────────────────────────────────────────────────────────────────╯ ╰────────────────────────────╯ ╭─ Throughput ─────────── rules/s ─╮ ╭─ Rule duration ────────────╮ ╭─ Failures by category ───────╮ │ 13│ ⢠⠋1 │ │ 50│ ███ ▄▄▄ │ │ Domain controllers ▆▆ ✗ 1 │ │ │ ⢀ ⡜⡄ ⡰⡄ ⡰⡀ ⢠⠃ │ │ │ ███ ███ │ │ Replication ▆▆ ✗ 1 │ │ │ ⡜⢣⢀⠤⠢⢄⡀⡰⠁⠸⡰⠁⠘⡤⠔⠢⢄ ⢠⠃⢇ ⢠⠊⠁ │ │ │▇▇ ███ ███ │ │ DNS ▆▆ ✗ 1 │ │ │⢠⠃ ⠁ ⠈⠁ ⠁ ⠑⠎ ⠸⣠⠃ │ │ │██ ███ ███ │ │ Kerberos ▆▆ ✗ 1 │ │ │⡜ ⠁ ⡀ │ │ │██ ███ ███ ███ │ │ Security ✗ 0 │ │ 0│⣀⣀⣀⣀⣀⡠⠔⠤⣀⣀⣀⡠⠔⠤⣀⣀⣀⣀⣀⣀⣀⠤⠢⢄⡠⠔⠉⠈2 │ │ │██ ███ ███ ███ ▂▂▂ │ │ Group Policy ✗ 0 │ │ └───────────────────────────── │ │ 0│██ ███ ███ ███ ███ ▁▁▁ │ │ Accounts ▆▆▆▆▆ ✗ 2 │ │ 1 completed 2 ✗ failed │ │ 0s 0.5s 2s 8s │ │ PKI ✗ 0 │ ╰──────────────────────────────────╯ ╰────────────────────────────╯ ╰──────────────────────────────╯ 00:26 ▲ WARN DC04.ad.adatum.com: Local administrators - nested group in BUILTIN\Administrators ctrl+c stop
Nightly checks · ad.adat… ● evaluating 332 rules on 6 workers ✓ Discover 2.8s › ✓ Collect 4.0s › ⠋ Evaluate › ○ Report ╭─ Targets ─────────────────── 6 workers ─╮ ╭─ Results ────────╮ │ ⠋ ad.adatum.co… ━━━━━━━━━━━╸───── 68% │ │ ███████████ 162 │ │ ✗ eu.ad.adatum… ━━━━━━━━━━━━━━━━━ 100% │ │ █ ✓ Pa… 131 81% │ │ ▲ DC01.ad.adat… ━━━━━━━━━━━━━━━━━ 100% │ │ █ ▲ Wa… 21 13% │ │ ▲ DC02.ad.adat… ━━━━━━━━━━━━━━━━━ 100% │ │ █ ✗ Fa… 6 4% │ │ ✓ DC03.ad.adat… ━━━━━━━━━━━━━━━━━ 100% │ │ █ – Sk… 4 2% │ │ ⠴ DC04.ad.adat… ━━━━━━━━━━━━━━━━─ 93% │ │ ──────────────── │ │ ⠦ DC05.ad.adat… ━━━━───────────── 23% │ │ Evalu… 149 / │ │ ⠧ DC06.ad.adat… ━━╸────────────── 13% │ │ 332 │ │ ⠇ DC07.eu.ad.a… ━━━╸───────────── 20% │ │ Avera… 7.8 │ │ ○ DC08.eu.ad.a… ───────────────── │ │ rules/s │ │ ○ DC09.eu.ad.a… ───────────────── │ │ Remai… ~24s │ │ ○ DC10.eu.ad.a… ───────────────── │ │ Targe… 3 / 12 │ │ │ │ Targe… 1 │ ╰─────────────────────────────────────────╯ ╰──────────────────╯ ctrl+c stop
Nightly checks · 162/332 · ✗6 ▲21 ·… · needs 60×20 ✓ Discover › ✓ Collect › ⠋ Evaluate › ○ Report 2.8s 4.0s ⠋ ad.adatum.com (… ━━━━━━─── 68% ✓ 7 ✗ 1 ▲ 3 ▲ DC02.ad.adatum.… ━━━━━━━━━ 100% ✓ 23 ✗ 0 ▲ 6 ✓ DC03.ad.adatum.… ━━━━━━━━━ 100% ✓ 23 ✗ 3 ▲ 4 ⠴ DC04.ad.adatum.… ━━━━━━━━╸ 93% ✓ 23 ✗ 1 ▲ 3 ⠦ DC05.ad.adatum.… ━━─────── 23% ✓ 6 ✗ 0 ▲ 1 ⠧ DC06.ad.adatum.… ━──────── 13% ✓ 4 ✗ 0 ▲ 0 ⠇ DC07.eu.ad.adat… ━━─────── 20% ✓ 6 ✗ 0 ▲ 0 +5 more · 2 done · 3 queued
// Replays a recorded assessment into its dashboard: every line of the recording is an update addressed to a widget
// by name, so the layout knows nothing about where the updates come from (a live run, or this file).
// dotnet run -- assessment-run.jsonl 6 (the recording, and the speed)
string path = args.Length > 0 ? args[0] : "assessment-run.jsonl";
double speed = args.Length > 1 ? double.Parse(args[1], CultureInfo.InvariantCulture) : 1;
const int TotalRules = 332;
const int Workers = 6;
Phases phases = new Phases().Set("Discover").Set("Collect").Set("Evaluate").Set("Report");
StackedBar results = new StackedBar("results")
.Add("Passed", 0, ThemeToken.Pass)
.Add("Warnings", 0, ThemeToken.Warn)
.Add("Failed", 0, ThemeToken.Fail)
.Add("Skipped", 0, ThemeToken.Skip);
KeyValueList summary = new KeyValueList("summary")
.Add("Evaluated", "0 / " + TotalRules)
.Add("Average rate", "-")
.Add("Remaining", "-")
.Add("Targets done", "0 / 12")
.Add("Targets failing", "0");
LineChart throughput = new LineChart("throughput").Height(7);
throughput.Series("completed", ThemeToken.Accent);
throughput.Series("failed", ThemeToken.Fail);
Histogram durations = new Histogram(new double[] { 0, 0.25, 0.5, 1, 2, 4, 8 }, "durations")
.Height(6)
.Unit("s");
BarChart findings = new BarChart("findings").Role(ThemeToken.Fail);
foreach (string category in new[]
{
"Domain controllers", "Replication", "DNS", "Kerberos", "Security", "Group Policy", "Accounts",
"PKI"
}
)
{
findings.Add(category, 0);
}
Lanes targets = new Lanes
{
MaxLabelWidth = 28
};
Dashboard dashboard = Ui.Dashboard().Title("[bold]Nightly checks[/]")
.Subtitle("ad.adatum.com forest assessment · 12 targets · " + TotalRules + " rules")
.Content(body => body
.Add(new Prioritized(new Padding(phases, 1, 0, 1, 1), 10, 1, 30))
.Columns(columns => columns.Content(c => c.Add((new Panel(
new Prioritized(targets, 8, 4, 40),
"Targets") { HeaderRight = Workers + " workers" }).Fill(2.3))
.Add(new Panel(new Rows(results, new Rule(), summary), "Results").Fill(1))))
.Columns(columns => columns.Content(c => c.Add((new Panel(throughput,
"Throughput") { HeaderRight = "rules/s" }).Fill(1.2))
.Add(new Panel(durations, "Rule duration").Fill(1))
.Add(new Panel(findings, "Failures by category").Fill(1))))
.Add(new Panel(new LogRegion { PreferredHeight = 6 }, "Log").Fill()));
// Below 60 x 20 the dashboard shows one status line, the phases and the lanes that fit.
dashboard.MinimumSize = new Size(60, 20);
dashboard.CompactSummary = () =>
{
double done = results.Segments.Sum(s => s.Value);
double failed = results.Segments.First(s => s.Label == "Failed").Value;
double warned = results.Segments.First(s => s.Label == "Warnings").Value;
return done + "/" + TotalRules + " · [fail]✗" + failed + "[/] [warn]"
+ GlyphSet.Full.Get(Glyph.Warning) + warned + "[/]";
};
using StreamReader recording = new StreamReader(path);
LiveSession.Replay(
dashboard,
recording,
new LiveSessionOptions { Summary = new RunSummary(targets) },
speed);
// A widget written by hand (IWidget): the run summary printed to the scrollback when the session ends.
// … 39 more lines in the full programFull program
using ConsoleMonster;
using System.Globalization;
using ConsoleMonster.Canvas;
using ConsoleMonster.Glyphs;
using ConsoleMonster.Layout;
using ConsoleMonster.Live;
using ConsoleMonster.Styling;
using ConsoleMonster.Text;
using ConsoleMonster.Widgets;
// Replays a recorded assessment into its dashboard: every line of the recording is an update addressed to a widget
// by name, so the layout knows nothing about where the updates come from (a live run, or this file).
// dotnet run -- assessment-run.jsonl 6 (the recording, and the speed)
string path = args.Length > 0 ? args[0] : "assessment-run.jsonl";
double speed = args.Length > 1 ? double.Parse(args[1], CultureInfo.InvariantCulture) : 1;
const int TotalRules = 332;
const int Workers = 6;
Phases phases = new Phases().Set("Discover").Set("Collect").Set("Evaluate").Set("Report");
StackedBar results = new StackedBar("results")
.Add("Passed", 0, ThemeToken.Pass)
.Add("Warnings", 0, ThemeToken.Warn)
.Add("Failed", 0, ThemeToken.Fail)
.Add("Skipped", 0, ThemeToken.Skip);
KeyValueList summary = new KeyValueList("summary")
.Add("Evaluated", "0 / " + TotalRules)
.Add("Average rate", "-")
.Add("Remaining", "-")
.Add("Targets done", "0 / 12")
.Add("Targets failing", "0");
LineChart throughput = new LineChart("throughput").Height(7);
throughput.Series("completed", ThemeToken.Accent);
throughput.Series("failed", ThemeToken.Fail);
Histogram durations = new Histogram(new double[] { 0, 0.25, 0.5, 1, 2, 4, 8 }, "durations")
.Height(6)
.Unit("s");
BarChart findings = new BarChart("findings").Role(ThemeToken.Fail);
foreach (string category in new[]
{
"Domain controllers", "Replication", "DNS", "Kerberos", "Security", "Group Policy", "Accounts",
"PKI"
}
)
{
findings.Add(category, 0);
}
Lanes targets = new Lanes
{
MaxLabelWidth = 28
};
Dashboard dashboard = Ui.Dashboard().Title("[bold]Nightly checks[/]")
.Subtitle("ad.adatum.com forest assessment · 12 targets · " + TotalRules + " rules")
.Content(body => body
.Add(new Prioritized(new Padding(phases, 1, 0, 1, 1), 10, 1, 30))
.Columns(columns => columns.Content(c => c.Add((new Panel(
new Prioritized(targets, 8, 4, 40),
"Targets") { HeaderRight = Workers + " workers" }).Fill(2.3))
.Add(new Panel(new Rows(results, new Rule(), summary), "Results").Fill(1))))
.Columns(columns => columns.Content(c => c.Add((new Panel(throughput,
"Throughput") { HeaderRight = "rules/s" }).Fill(1.2))
.Add(new Panel(durations, "Rule duration").Fill(1))
.Add(new Panel(findings, "Failures by category").Fill(1))))
.Add(new Panel(new LogRegion { PreferredHeight = 6 }, "Log").Fill()));
// Below 60 x 20 the dashboard shows one status line, the phases and the lanes that fit.
dashboard.MinimumSize = new Size(60, 20);
dashboard.CompactSummary = () =>
{
double done = results.Segments.Sum(s => s.Value);
double failed = results.Segments.First(s => s.Label == "Failed").Value;
double warned = results.Segments.First(s => s.Label == "Warnings").Value;
return done + "/" + TotalRules + " · [fail]✗" + failed + "[/] [warn]"
+ GlyphSet.Full.Get(Glyph.Warning) + warned + "[/]";
};
using StreamReader recording = new StreamReader(path);
LiveSession.Replay(
dashboard,
recording,
new LiveSessionOptions { Summary = new RunSummary(targets) },
speed);
// A widget written by hand (IWidget): the run summary printed to the scrollback when the session ends.
sealed class RunSummary : IWidget
{
private readonly Lanes _lanes;
public RunSummary(Lanes lanes) => _lanes = lanes;
public Size Measure(Constraints constraints,
RenderContext context) => Content().Measure(constraints, context);
public void Render(Region region, RenderContext context) => Content().Render(region, context);
private IWidget Content()
{
Table table = new Table()
.Border(TableBorder.Minimal)
.Title("[bold]Run summary[/]")
.Column("Target", c => c.Wrap(false))
.Column("Status")
.Column("Passed")
.Column("Failed")
.Column("Warnings")
.Column("Skipped")
.Column("Duration");
int passed = 0, failed = 0, warned = 0, skipped = 0;
foreach (Lane lane in _lanes.Items)
{
string duration = lane.Started.HasValue && lane.Finished.HasValue
? NumberFormat.Duration(lane.Finished.Value - lane.Started.Value)
: "-";
table.Row(Markup.Escape(lane.Label), TableCell.ForStatus(lane.Status),
lane.Passed.ToString(), lane.Failed.ToString(), lane.Warned.ToString(),
lane.Skipped.ToString(), duration);
passed += lane.Passed;
failed += lane.Failed;
warned += lane.Warned;
skipped += lane.Skipped;
}
table.Footer("[bold]Total[/]", string.Empty, passed.ToString(), failed.ToString(),
warned.ToString(), skipped.ToString(), string.Empty);
return new Padding(table, 1, 1, 1, 1);
}
}// Replays a recorded assessment into its dashboard: every line of the recording is an update addressed to a widget
// by name, so the layout knows nothing about where the updates come from (a live run, or this file).
// dotnet run -- assessment-run.jsonl 6 (the recording, and the speed)
string path = args.Length > 0 ? args[0] : "assessment-run.jsonl";
double speed = args.Length > 1 ? double.Parse(args[1], CultureInfo.InvariantCulture) : 1;
const int TotalRules = 332;
const int Workers = 6;
Phases phases = Ui.Phases().Set("Discover").Set("Collect").Set("Evaluate").Set("Report");
StackedBar results = Ui.StackedBar("results")
.Add("Passed", 0, ThemeToken.Pass)
.Add("Warnings", 0, ThemeToken.Warn)
.Add("Failed", 0, ThemeToken.Fail)
.Add("Skipped", 0, ThemeToken.Skip);
KeyValueList summary = Ui.KeyValue("summary")
.Add("Evaluated", "0 / " + TotalRules)
.Add("Average rate", "-")
.Add("Remaining", "-")
.Add("Targets done", "0 / 12")
.Add("Targets failing", "0");
LineChart throughput = Ui.LineChart("throughput").Height(7);
throughput.Series("completed", ThemeToken.Accent);
throughput.Series("failed", ThemeToken.Fail);
Histogram durations = (Histogram)Ui.Chart()
.Type(ChartType.Histogram)
.Edges(new double[] { 0, 0.25, 0.5, 1, 2, 4, 8 })
.WidgetId("durations")
.Height(6)
.Unit("s")
.Build();
BarChart findings = Ui.BarChart("findings").Role(ThemeToken.Fail);
foreach (string category in new[]
{
"Domain controllers", "Replication", "DNS", "Kerberos", "Security", "Group Policy", "Accounts",
"PKI"
}
)
{
findings.Add(category, 0);
}
Lanes targets = Ui.Lanes().MaxLabelWidth(28);
Dashboard dashboard = Ui.Dashboard()
.Title("[bold]Nightly checks[/]")
.Subtitle("ad.adatum.com forest assessment · 12 targets · " + TotalRules + " rules")
.Content(body => body.Add(new Prioritized(
Ui.Padding().Left(1).Top(0).Right(1).Bottom(1).Content(paddingContent =>
{
paddingContent.Add(phases);
}),
10,
1,
30))
.Columns(columns => columns.Content(c => c.Add((Ui.Panel()
.Title("Targets")
.Content(panelContent =>
{
panelContent.Add(new Prioritized(targets, 8, 4, 40));
})
.HeaderRight(Workers + " workers")).Fill(2.3))
.Add(Ui.Panel().Title("Results").Content(panelContent =>
{
panelContent.Rows(r => r.Content(rowsContent =>
{
rowsContent.Add(results);
rowsContent.Rule();
rowsContent.Add(summary);
}));
}).Fill(1))))
.Columns(columns => columns.Content(c => c.Add((Ui.Panel()
.Title("Throughput")
.HeaderRight("rules/s")
.Content(panelContent =>
{
panelContent.Add(throughput);
})).Fill(1.2)).Add(Ui.Panel().Title("Rule duration").Content(panelContent =>
{
panelContent.Add(durations);
}).Fill(1)).Add(Ui.Panel().Title("Failures by category").Content(panelContent =>
{
panelContent.Add(findings);
}).Fill(1))))
.Add(Ui.Panel().Title("Log").Content(panelContent =>
{
panelContent.LogRegion(logRegion => logRegion.PreferredHeight(6));
}).Fill()));
// Below 60 x 20 the dashboard shows one status line, the phases and the lanes that fit.
dashboard.MinimumSize(new Size(60, 20)).CompactSummaryBy(() =>
{
double done = results.Segments.Sum(s => s.Value);
double failed = results.Segments.First(s => s.Label == "Failed").Value;
double warned = results.Segments.First(s => s.Label == "Warnings").Value;
return done + "/" + TotalRules + " · [fail]✗" + failed + "[/] [warn]"
+ GlyphSet.Full.Get(Glyph.Warning) + warned + "[/]";
});
using StreamReader recording = new StreamReader(path);
LiveSession.Replay(
dashboard,
recording,
new LiveSessionOptions().Summary(new RunSummary(targets)),
speed);
// A widget written by hand (IWidget): the run summary printed to the scrollback when the session ends.
sealed class RunSummary : IWidget
{
private readonly Lanes _lanes;
public RunSummary(Lanes lanes) => _lanes = lanes;
public Size Measure(Constraints constraints,
RenderContext context) => Content().Measure(constraints, context);
public void Render(Region region, RenderContext context) => Content().Render(region, context);
private IWidget Content()
{
Table table = Ui.Table()
.Border(TableBorder.Minimal)
.Title("[bold]Run summary[/]")
.Column("Target", c => c.Wrap(false))
.Column("Status")
.Column("Passed")
.Column("Failed")
.Column("Warnings")
.Column("Skipped")
.Column("Duration");
int passed = 0, failed = 0, warned = 0, skipped = 0;
foreach (Lane lane in _lanes.Items)
{
string duration = lane.Started.HasValue && lane.Finished.HasValue
? NumberFormat.Duration(lane.Finished!.Value - lane.Started!.Value)
: "-";
table.Row(Markup.Escape(lane.Label), TableCell.ForStatus(lane.Status),
lane.Passed.ToString(), lane.Failed.ToString(), lane.Warned.ToString(),
lane.Skipped.ToString(), duration);
passed += lane.Passed;
failed += lane.Failed;
warned += lane.Warned;
skipped += lane.Skipped;
}
table.Footer("[bold]Total[/]", string.Empty, passed.ToString(), failed.ToString(),
warned.ToString(), skipped.ToString(), string.Empty);
return Ui.Padding().Left(1).Top(1).Right(1).Bottom(1).Content(paddingContent =>
{
paddingContent.Add(table);
});
}
}
Full program
using ConsoleMonster;
using System.Globalization;
using ConsoleMonster.Canvas;
using ConsoleMonster.Glyphs;
using ConsoleMonster.Layout;
using ConsoleMonster.Live;
using ConsoleMonster.Styling;
using ConsoleMonster.Text;
using ConsoleMonster.Widgets;
// Replays a recorded assessment into its dashboard: every line of the recording is an update addressed to a widget
// by name, so the layout knows nothing about where the updates come from (a live run, or this file).
// dotnet run -- assessment-run.jsonl 6 (the recording, and the speed)
string path = args.Length > 0 ? args[0] : "assessment-run.jsonl";
double speed = args.Length > 1 ? double.Parse(args[1], CultureInfo.InvariantCulture) : 1;
const int TotalRules = 332;
const int Workers = 6;
Phases phases = Ui.Phases().Set("Discover").Set("Collect").Set("Evaluate").Set("Report");
StackedBar results = Ui.StackedBar("results")
.Add("Passed", 0, ThemeToken.Pass)
.Add("Warnings", 0, ThemeToken.Warn)
.Add("Failed", 0, ThemeToken.Fail)
.Add("Skipped", 0, ThemeToken.Skip);
KeyValueList summary = Ui.KeyValue("summary")
.Add("Evaluated", "0 / " + TotalRules)
.Add("Average rate", "-")
.Add("Remaining", "-")
.Add("Targets done", "0 / 12")
.Add("Targets failing", "0");
LineChart throughput = Ui.LineChart("throughput").Height(7);
throughput.Series("completed", ThemeToken.Accent);
throughput.Series("failed", ThemeToken.Fail);
Histogram durations = (Histogram)Ui.Chart()
.Type(ChartType.Histogram)
.Edges(new double[] { 0, 0.25, 0.5, 1, 2, 4, 8 })
.WidgetId("durations")
.Height(6)
.Unit("s")
.Build();
BarChart findings = Ui.BarChart("findings").Role(ThemeToken.Fail);
foreach (string category in new[]
{
"Domain controllers", "Replication", "DNS", "Kerberos", "Security", "Group Policy", "Accounts",
"PKI"
}
)
{
findings.Add(category, 0);
}
Lanes targets = Ui.Lanes().MaxLabelWidth(28);
Dashboard dashboard = Ui.Dashboard()
.Title("[bold]Nightly checks[/]")
.Subtitle("ad.adatum.com forest assessment · 12 targets · " + TotalRules + " rules")
.Content(body => body.Add(new Prioritized(
Ui.Padding().Left(1).Top(0).Right(1).Bottom(1).Content(paddingContent =>
{
paddingContent.Add(phases);
}),
10,
1,
30))
.Columns(columns => columns.Content(c => c.Add((Ui.Panel()
.Title("Targets")
.Content(panelContent =>
{
panelContent.Add(new Prioritized(targets, 8, 4, 40));
})
.HeaderRight(Workers + " workers")).Fill(2.3))
.Add(Ui.Panel().Title("Results").Content(panelContent =>
{
panelContent.Rows(r => r.Content(rowsContent =>
{
rowsContent.Add(results);
rowsContent.Rule();
rowsContent.Add(summary);
}));
}).Fill(1))))
.Columns(columns => columns.Content(c => c.Add((Ui.Panel()
.Title("Throughput")
.HeaderRight("rules/s")
.Content(panelContent =>
{
panelContent.Add(throughput);
})).Fill(1.2)).Add(Ui.Panel().Title("Rule duration").Content(panelContent =>
{
panelContent.Add(durations);
}).Fill(1)).Add(Ui.Panel().Title("Failures by category").Content(panelContent =>
{
panelContent.Add(findings);
}).Fill(1))))
.Add(Ui.Panel().Title("Log").Content(panelContent =>
{
panelContent.LogRegion(logRegion => logRegion.PreferredHeight(6));
}).Fill()));
// Below 60 x 20 the dashboard shows one status line, the phases and the lanes that fit.
dashboard.MinimumSize(new Size(60, 20)).CompactSummaryBy(() =>
{
double done = results.Segments.Sum(s => s.Value);
double failed = results.Segments.First(s => s.Label == "Failed").Value;
double warned = results.Segments.First(s => s.Label == "Warnings").Value;
return done + "/" + TotalRules + " · [fail]✗" + failed + "[/] [warn]"
+ GlyphSet.Full.Get(Glyph.Warning) + warned + "[/]";
});
using StreamReader recording = new StreamReader(path);
LiveSession.Replay(
dashboard,
recording,
new LiveSessionOptions().Summary(new RunSummary(targets)),
speed);
// A widget written by hand (IWidget): the run summary printed to the scrollback when the session ends.
sealed class RunSummary : IWidget
{
private readonly Lanes _lanes;
public RunSummary(Lanes lanes) => _lanes = lanes;
public Size Measure(Constraints constraints,
RenderContext context) => Content().Measure(constraints, context);
public void Render(Region region, RenderContext context) => Content().Render(region, context);
private IWidget Content()
{
Table table = Ui.Table()
.Border(TableBorder.Minimal)
.Title("[bold]Run summary[/]")
.Column("Target", c => c.Wrap(false))
.Column("Status")
.Column("Passed")
.Column("Failed")
.Column("Warnings")
.Column("Skipped")
.Column("Duration");
int passed = 0, failed = 0, warned = 0, skipped = 0;
foreach (Lane lane in _lanes.Items)
{
string duration = lane.Started.HasValue && lane.Finished.HasValue
? NumberFormat.Duration(lane.Finished!.Value - lane.Started!.Value)
: "-";
table.Row(Markup.Escape(lane.Label), TableCell.ForStatus(lane.Status),
lane.Passed.ToString(), lane.Failed.ToString(), lane.Warned.ToString(),
lane.Skipped.ToString(), duration);
passed += lane.Passed;
failed += lane.Failed;
warned += lane.Warned;
skipped += lane.Skipped;
}
table.Footer("[bold]Total[/]", string.Empty, passed.ToString(), failed.ToString(),
warned.ToString(), skipped.ToString(), string.Empty);
return Ui.Padding().Left(1).Top(1).Right(1).Bottom(1).Content(paddingContent =>
{
paddingContent.Add(table);
});
}
}
dotnet run -- assessment-run.jsonl 2, with the recording offered there) halfway through, in windows of 100×30, 64×20 and 50×12. Its MinimumSize is 60×20.Without a console
In CI, with redirected output and in stream mode, a session narrates append-only lines instead of redrawing, with [mm:ss] prefixes when a CI system is detected. Plain mode does the same in ASCII without colour, and text that reaches stream and plain output is stripped of escape sequences and control characters.
Next
- Live runs: run a script block for many items in parallel with a live view.
- Threads and concurrency: what is safe from which thread.
- Recording and replay: save a session's updates and replay them.