Skip to content
ConsoleMonster

Prompts, menus and forms

Questions, menus, wizards and a grid for the console on Windows PowerShell 5.1 and PowerShell 7. Every screen here was drawn by scripted keys.

ConsoleMonster.Examples toolbox 120×3424-bitFull
 Server toolbox › Tasks                                                                                lab · 11 servers
╭───────────────────────╮ ╭─ Tasks ───────────────────────────────────────────────────────────────── 3 of 11 selected ─╮
│                     ╭─ Commands ─────────────────────────── Search items, actions and presets ─╮                     │
│  t  ● Targets    4/9│                                                                          │s; the rest only     │
│▌ k  ■ Tasks     3/11│ › cert                                                                   │                     │
│  o  ◆ Options       │ ▌ Toggle Certificate expiry                                        Task  │                     │
│  p  ★ Presets       │   Finds machine certificates that expire within 30 days and the servic…  │──────────────────╮  │
│                     │  ↑↓ move  enter select  esc cancel                                       │ity updates and   │  │
│  r  ► Review & run  ╰──────────────────────────────────────────────────────────────────────────╯t successful      │  │
│  h  History   3 runs  │ │      [ ] Log rotation            changes ~2 min  │ install.                             │  │
│     Quit              │ │      [ ] Pending restart check           ~1 min  │                                      │  │
│                       │ │    ▾ [–] Security                           2/4  │ Group      Security                  │  │
│                       │ │      [✓] Patch status                    ~2 min  │ Duration   about 2 min per server    │  │
│                       │ │      [✓] Certificate expiry              ~1 min  │ Changes    no, read only             │  │
│                       │ │      [ ] Local administrators audit      ~1 min  │ Parameter  PatchStatus               │  │
│                       │ │      [ ] Firewall rules review           ~2 min  │                                      │  │
│                       │ │    ▾ [ ] Health                             0/4  │                                      │  │
│                       │ │      [ ] Event log errors                ~1 min  │                                      │  │
│                       │ │      [ ] Service health          changes ~1 min  │                                      │  │
│                       │ │      [ ] Disk space                      ~1 min  │                                      │  │
│                       │ │      [ ] Uptime and reboots              ~1 min  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  ╰──────────────────────────────────────╯  │
╰───────────────────────╯ ╰────────────────────────────────────────────────────────────────────────────────────────────╯
 ↑↓ move  enter select  esc cancel

The site tool runs each example with a scripted key sequence and draws it into a ScreenCapture, the same in-memory surface ConsoleMonster's tests and exports use. Lists filter as you type, the footer lists the keys that work right now and ? shows them all, and answers come back as typed values or as the chosen objects themselves.

When nobody can answer (CI, redirected input, pwsh -NonInteractive, CONSOLEMONSTER_NONINTERACTIVE=1), a prompt returns its default or fails with a message that names the parameter to pass. In remoting and the ISE, prompts ask through the host, and CONSOLEMONSTER_ACCESSIBLE=1 switches to plain numbered questions.

Selection

A list that filters as you type, with groups, badges, and choices that are unavailable with their reason. The answer comes back as the chosen object, not a string.

Selection 100×1624-bitFull
? Target server
  Type to filter; offline servers show why they cannot be picked.
  › type to filter
    Warsaw                               ┃
  ▌ FS01                            File ┃
    FS02                            File ┃
    WEB01                            Web ┃
    SQL01                       Database ┃
    Berlin                               ┃
    FS11                            File │
    WEB11                            Web │
    PRN11                          Print │
    Dublin                               │

  ↑↓ move  enter select  esc cancel  f1 keys

Keys Down Down "we" Down Enter

C#
SelectPrompt<ToolboxServer> prompt = new SelectPrompt<ToolboxServer>("Target server", ToolboxData.Servers, s => s.Name, s => s.Site) {
    Description = "Type to filter; offline servers show why they cannot be picked."
};
foreach (Choice choice in prompt.Choices) {
    ToolboxServer server = (ToolboxServer)choice.Value!;
    choice.Badge = RichText.Plain(server.Role, new RichStyle(ThemeToken.Muted));
    choice.DisabledReason = server.Offline;
}
ToolboxServer target = prompt.Show(options);
PowerShell
$server = Read-ConsoleSelection 'Target server' -Choices $servers -Display Name -GroupBy Site

Multi-selection with a preview

Tri-state group checkboxes, a live count and a preview pane beside the list. Ctrl+A selects all, Ctrl+N none and Ctrl+T inverts.

Multi-selection with a preview 110×2024-bitFull
? Tasks
  › type to filter       1 of 11 selected  ╭─ Log rotation ──────────────────────────────────────────────────╮
    ▾ [–] Maintenance                1/3 ┃ │ Compresses application logs older than 7 days and deletes       │
      [ ] Disk cleanup                   ┃ │ archives older than 90 days.                                    │
  ▌   [✓] Log rotation                   ┃ │                                                                 │
      [ ] Pending restart check          ┃ │ Group      Maintenance                                          │
    ▾ [ ] Security                   0/4 ┃ │ Duration   about 2 min per server                               │
      [ ] Patch status                   ┃ │ Changes    yes, makes changes                                   │
      [ ] Certificate expiry             ┃ │ Parameter  LogRotation                                          │
      [ ] Local administrators audit     ┃ │                                                                 │
      [ ] Firewall rules review          ┃ │                                                                 │
    ▾ [ ] Health                     0/4 ┃ │                                                                 │
      [ ] Event log errors               │ │                                                                 │
      [ ] Service health                 │ │                                                                 │
                                           ╰─────────────────────────────────────────────────────────────────╯
  ↑↓ move  space toggle  enter confirm  ctrl+a all  ctrl+n none  esc cancel  f1 keys

Keys Down Space Down Down Space Down Down Down Space Enter

C#
IReadOnlyList<ToolboxTask> tasks = new MultiSelectPrompt<ToolboxTask>("Tasks", ToolboxData.Tasks, t => t.Name, t => t.Category) {
    Minimum = 1,
    Preview = ToolboxData.TaskPreview
}.Show(options);
PowerShell
$tasks = $allTasks | Read-ConsoleMultiSelection 'Tasks' -Display Name -GroupBy Category -Minimum 1

Text with validation

A pattern, a length or a scriptblock validates the answer, and the message stays inline until the input is valid.

Text with validation 90×1024-bitFull
? Share name  default: Reports
  Shown to users when they browse the server.
  › 9reports
  ✗ Start with a letter; letters, digits, - and _ only
  enter confirm  esc cancel

Keys "9reports" Enter Home Delete Enter

C#
string name = new TextPrompt("Share name") {
    Default = "Reports",
    Pattern = "[A-Za-z][A-Za-z0-9_-]{1,23}",
    PatternMessage = "Start with a letter; letters, digits, - and _ only",
    Description = "Shown to users when they browse the server."
}.Show(options);
PowerShell
$name = Read-ConsoleText 'Share name' -Pattern '[A-Za-z][A-Za-z0-9_-]{1,23}' -PatternMessage 'Start with a letter; letters, digits, - and _ only'

Typed confirmation

For destructive actions the name has to be typed; anything else keeps the prompt open.

Typed confirmation 90×1024-bitFull
▴ Remove FS01 from the inventory?
  Its history and reports are deleted too. This cannot be undone.
  Type FS01 to confirm
  › FS0
  ✗ That doesn't match FS01.
  enter confirm  esc cancel

Keys "FS0" Enter "1" Enter

C#
bool remove = new TypedConfirmPrompt("Remove FS01 from the inventory?", "FS01") {
    Warning = "Its history and reports are deleted too. This cannot be undone."
}.Show(options);
PowerShell
if (Read-ConsoleConfirm 'Remove FS01 from the inventory?' -TypedConfirmation 'FS01') { Remove-Server FS01 }

A menu as an app

The Shell layout: a breadcrumb title bar, a sidebar, the content pane and a footer that lists the keys that work right now. Ctrl+K opens the command palette, and the review shows the equivalent command line.

A menu as an app 120×3424-bitFull
 Server toolbox › Tasks                                                                                lab · 11 servers
╭───────────────────────╮ ╭─ Tasks ───────────────────────────────────────────────────────────────── 3 of 11 selected ─╮
│                     ╭─ Commands ─────────────────────────── Search items, actions and presets ─╮                     │
│  t  ● Targets    4/9│                                                                          │s; the rest only     │
│▌ k  ■ Tasks     3/11│ › cert                                                                   │                     │
│  o  ◆ Options       │ ▌ Toggle Certificate expiry                                        Task  │                     │
│  p  ★ Presets       │   Finds machine certificates that expire within 30 days and the servic…  │──────────────────╮  │
│                     │  ↑↓ move  enter select  esc cancel                                       │ity updates and   │  │
│  r  ► Review & run  ╰──────────────────────────────────────────────────────────────────────────╯t successful      │  │
│  h  History   3 runs  │ │      [ ] Log rotation            changes ~2 min  │ install.                             │  │
│     Quit              │ │      [ ] Pending restart check           ~1 min  │                                      │  │
│                       │ │    ▾ [–] Security                           2/4  │ Group      Security                  │  │
│                       │ │      [✓] Patch status                    ~2 min  │ Duration   about 2 min per server    │  │
│                       │ │      [✓] Certificate expiry              ~1 min  │ Changes    no, read only             │  │
│                       │ │      [ ] Local administrators audit      ~1 min  │ Parameter  PatchStatus               │  │
│                       │ │      [ ] Firewall rules review           ~2 min  │                                      │  │
│                       │ │    ▾ [ ] Health                             0/4  │                                      │  │
│                       │ │      [ ] Event log errors                ~1 min  │                                      │  │
│                       │ │      [ ] Service health          changes ~1 min  │                                      │  │
│                       │ │      [ ] Disk space                      ~1 min  │                                      │  │
│                       │ │      [ ] Uptime and reboots              ~1 min  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  │                                      │  │
│                       │ │                                                  ╰──────────────────────────────────────╯  │
╰───────────────────────╯ ╰────────────────────────────────────────────────────────────────────────────────────────────╯
 ↑↓ move  enter select  esc cancel

Keys wait:1600 Enter Space Down Space Down Down Down Space Escape Down Enter Down Down Down Down wait:300 Escape Ctrl+K "cert" wait:300 Escape Escape r wait:300 Ctrl+Q y

C#
Menu menu = ServerToolbox.Build();
menu.Run(new MenuOptions { Layout = MenuLayout.Shell, Interactive = options, StorageRoot = Path.Combine(Path.GetTempPath(), "cmsite-toolbox") });
PowerShell
Show-ConsoleMenu $menu -Layout Shell

A form as a wizard

Fields with pages become a wizard with a progress strip. Dependent fields reload their choices with a spinner, and the review page shows every answer and the equivalent command.

A form as a wizard 110×3024-bitFull
 Install Toolbox Agent › Review                                                                               
╭─ Review ───────────────────────────────────────────────────────────────────────────────────────────── 5/5 ─╮
│                                                                                                            │
│  ● Location ── ● Components ── ● Service ── ● Connection ── ● Review                                       │
│                                                                                                            │
│  Review                                                                                                    │
│                                                                                                            │
│    Install folder         C:\Program Files\Toolbox Agent                                                   │
│    Data folder            C:\ProgramData\Toolbox Agent                                                     │
│    Start menu shortcuts   Yes                                                                              │
│    Components             3 of 6 selected: Agent service, Command-line tools, HTML reports                 │
│    Service account        A specific account                                                               │
│    User name              svc-toolbox                                                                      │
│    Password               ••••••••                                                                         │
│    Start automatically    Yes                                                                              │
│    Region                 Europe                                                                           │
│    Server                 eu-west-1                                                                        │
│    Port                   443                                                                              │
│    Use a proxy            No                                                                               │
│                                                                                                            │
│  ╭─ Equivalent command ─────────────────────────────────────────────────────────────────────────────────╮  │
│  │ Install-ToolboxAgent -Account Custom -UserName svc-toolbox -Password (Read-Host -AsSecureString)     │  │
│  │ -Region eu -Server eu-west-1                                                                         │  │
│  ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯  │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                                                                           Install   Copy command   Back    │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 ←→ move  enter install  esc back  f1 keys

Keys PageDown Enter Escape PageDown Right Down "svc-toolbox" Down "Example-Pass1" PageDown Right wait:400 Down wait:1800 Enter Enter PageDown wait:300 Escape Escape Escape y

C#
FormResult result = SetupWizard.Build().Show(new FormOptions { Interactive = options });
PowerShell
$answers = Read-ConsoleForm $form -AppName 'Agent setup'

The grid

An Out-GridView for the console on 5.1 and 7: typing filters, F3 sorts by column, Space marks rows, Enter shows every column of a row and Ctrl+Enter returns the original objects.

The grid 110×2224-bitFull
 Services on FS01                                                                    7 of 7 rows · 2 selected

 › type to filter
╭─ Name ↑ ───────────────────────────────────────────────────────────────────────────────────────────────────╮
│    Name          ╭─ SQLSERVERAGENT ─────────────────────────────────────────────────────╮                  │
│ ─  ──────────────│                                                                      │                  │
│    DFSR          │ Name        SQLSERVERAGENT                                           │                  │
│    LanmanServer  │ Status      ▴ WARN                                                   │                  │
│    MSSQLSERVER   │ Start type  Manual                                                   │                  │
│ ✓  Spooler       │ Memory      40.1 MB                                                  │                  │
│ ✓  SQLSERVERAGENT│  ↑↓ move  esc close                                                  │                  │
│    W32Time       ╰──────────────────────────────────────────────────────────────────────╯                  │
│    WinRM           ✓ PASS  Automatic   9.38 MB                                                             │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
│                                                                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 ↑↓ move  esc close

Keys "sql" wait:200 Backspace Backspace Backspace F3 Down Space Down Space Enter wait:200 Escape Ctrl+Enter

C#
ConsoleMonster.Interactive.Grid grid = new ConsoleMonster.Interactive.Grid("Services on FS01");
grid.AddColumn(new TableColumn("Name") { IsKey = true });
grid.AddColumn(new TableColumn("Status") { Presenter = CellPresenters.Status });
grid.AddColumn("Start type");
grid.AddColumn(new TableColumn("Memory") { Presenter = CellPresenters.Bytes });
grid.AddRow("Spooler", "Spooler", StatusKind.Pass, "Automatic", 14_221_312L);
// … 6 more lines in the full program
GridResult picked = grid.Show(new GridOptions { Interactive = options });
Full program
ConsoleMonster.Interactive.Grid grid = new ConsoleMonster.Interactive.Grid("Services on FS01");
grid.AddColumn(new TableColumn("Name") { IsKey = true });
grid.AddColumn(new TableColumn("Status") { Presenter = CellPresenters.Status });
grid.AddColumn("Start type");
grid.AddColumn(new TableColumn("Memory") { Presenter = CellPresenters.Bytes });
grid.AddRow("Spooler", "Spooler", StatusKind.Pass, "Automatic", 14_221_312L);
grid.AddRow("MSSQLSERVER", "MSSQLSERVER", StatusKind.Pass, "Automatic", 812_466_176L);
grid.AddRow("SQLSERVERAGENT", "SQLSERVERAGENT", StatusKind.Warn, "Manual", 42_004_480L);
grid.AddRow("W32Time", "W32Time", StatusKind.Pass, "Automatic", 3_276_800L);
grid.AddRow("WinRM", "WinRM", StatusKind.Pass, "Automatic", 9_830_400L);
grid.AddRow("DFSR", "DFSR", StatusKind.Fail, "Automatic", 0L);
grid.AddRow("LanmanServer", "LanmanServer", StatusKind.Pass, "Automatic", 6_553_600L);
GridResult picked = grid.Show(new GridOptions { Interactive = options });
PowerShell
Get-Service | Show-ConsoleGrid -Property Name, Status, StartType -Title 'Services' | Restart-Service -WhatIf