A key and value list aligns the keys in a column and the values beside them. Use it for the header of a report, the settings a script runs with, or a summary of what it changed.
Install-Module ConsoleMonster -Scope CurrentUser# Show a summary of settings as aligned key and value pairs in a panel.
Import-Module -Name ConsoleMonster
# Layout: an ordered hashtable gives plain pairs; objects with a Status add a mark to their value.
$summary = New-ConsolePanel -Title 'Deployment' -Content {
$keyValueOptions = @{
InputObject = [ordered] @{
Application = 'Orders API'
Version = '4.2.1'
Environment = 'staging'
Region = 'westeurope'
}
Content = {
[pscustomobject] @{ Key = 'Health check'; Value = 'passing'; Status = 'Pass' }
[pscustomobject] @{ Key = 'Migration'; Value = 'waiting for approval'; Status = 'Warn' }
}
}
New-ConsoleKeyValue @keyValueOptions
}
# Behaviour: print once.
$summary | Show-ConsoleFull program
# Show a summary of settings as aligned key and value pairs in a panel.
Import-Module -Name ConsoleMonster
# Layout: an ordered hashtable gives plain pairs; objects with a Status add a mark to their value.
$summary = New-ConsolePanel -Title 'Deployment' -Content {
$keyValueOptions = @{
InputObject = [ordered] @{
Application = 'Orders API'
Version = '4.2.1'
Environment = 'staging'
Region = 'westeurope'
}
Content = {
[pscustomobject] @{ Key = 'Health check'; Value = 'passing'; Status = 'Pass' }
[pscustomobject] @{ Key = 'Migration'; Value = 'waiting for approval'; Status = 'Warn' }
}
}
New-ConsoleKeyValue @keyValueOptions
}
# Behaviour: print once.
$summary | Show-ConsoleRun: ./settings-summary.ps1
dotnet new console -n DeploymentSummary
cd DeploymentSummary
dotnet add package ConsoleMonster// Show a summary of settings as aligned key and value pairs in a panel.
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Layout: plain pairs first; a status adds a mark to its value.
KeyValueList pairs = new KeyValueList()
.Add("Application", "Orders API")
.Add("Version", "4.2.1")
.Add("Environment", "staging")
.Add("Region", "westeurope")
.Add("Health check", "passing", StatusKind.Pass)
.Add("Migration", "waiting for approval", StatusKind.Warn);
Panel summary = new Panel(pairs, "Deployment");
// Behaviour: print once.
Terminal.Write(summary);Full program
// Show a summary of settings as aligned key and value pairs in a panel.
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Layout: plain pairs first; a status adds a mark to its value.
KeyValueList pairs = new KeyValueList()
.Add("Application", "Orders API")
.Add("Version", "4.2.1")
.Add("Environment", "staging")
.Add("Region", "westeurope")
.Add("Health check", "passing", StatusKind.Pass)
.Add("Migration", "waiting for approval", StatusKind.Warn);
Panel summary = new Panel(pairs, "Deployment");
// Behaviour: print once.
Terminal.Write(summary);Run: dotnet run
dotnet new console -n DeploymentSummary
cd DeploymentSummary
dotnet add package ConsoleMonster// Show a summary of settings as aligned key and value pairs in a panel.
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Layout: plain pairs first; a status adds a mark to its value.
KeyValueList pairs = Ui.KeyValue()
.Add("Application", "Orders API")
.Add("Version", "4.2.1")
.Add("Environment", "staging")
.Add("Region", "westeurope")
.Add("Health check", "passing", StatusKind.Pass)
.Add("Migration", "waiting for approval", StatusKind.Warn);
Panel summary = Ui.Panel().Title("Deployment").Content(panelContent =>
{
panelContent.Add(pairs);
});
// Behaviour: print once.
summary.Show();
Full program
// Show a summary of settings as aligned key and value pairs in a panel.
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Styling;
using ConsoleMonster.Widgets;
// Layout: plain pairs first; a status adds a mark to its value.
KeyValueList pairs = Ui.KeyValue()
.Add("Application", "Orders API")
.Add("Version", "4.2.1")
.Add("Environment", "staging")
.Add("Region", "westeurope")
.Add("Health check", "passing", StatusKind.Pass)
.Add("Migration", "waiting for approval", StatusKind.Warn);
Panel summary = Ui.Panel().Title("Deployment").Content(panelContent =>
{
panelContent.Add(pairs);
});
// Behaviour: print once.
summary.Show();
Run: dotnet run
╭─ Deployment ─────────────────────────────────────────────────────────────────╮ │ Application Orders API │ │ Version 4.2.1 │ │ Environment staging │ │ Region westeurope │ │ Health check ✓ passing │ │ Migration ▲ waiting for approval │ ╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Deployment ─────────────────────────────────────────────────────────────────╮ │ Application Orders API │ │ Version 4.2.1 │ │ Environment staging │ │ Region westeurope │ │ Health check ✓ passing │ │ Migration ▲ waiting for approval │ ╰──────────────────────────────────────────────────────────────────────────────╯
A deployment summary in a panel at 80 columns.
-InputObjecttakes an ordered hashtable of plain pairs.-Contentadds objects withKey,Valueand optionallyStatus, which puts a status mark before the value. Both can be used together, in that order.- A value can use markup when its object has
Markup = $true, for example'1.4 [muted]→[/] [bold]2.0[/]'. In C# the value is always markup. -Columns 2lays the pairs out in two columns when the window is wide enough.- In C#,
KeyValueList.Addtakes the key, the value and an optionalStatusKind. APanelwith a title frames it.
Next
- Show pass, warn and fail results: results as status lines.
- Layout: panels side by side and in grids.
- Your first report: a summary, a table and bars in one report.