Private/Console.ps1

# What a Technician sees while a Run is happening.
#
# The Report is the product of a Run; this is only the running commentary, captured into
# console.log by the transcript. Nothing here decides anything, and no Check calls it:
# Findings are returned as values and the Run displays them.

# One Severity, one colour, in one place. The Report renders the same decision as CSS
# classes; these are the console's half of it.
$script:SeverityColour = @{ OK = 'Green'; INFO = 'Gray'; WARN = 'Yellow'; FAIL = 'Red' }

function Show-Banner {
    [CmdletBinding()]
    param($Version)

    # The version goes on its own line rather than inside the block: the art is fixed
    # width, and a version number is not. The taglines are placed rather than written in,
    # for the same reason - German is longer than English and the box must not move.
    $art = @(
        ''
        ' .================.'
        ' || - - || gutcheck'
        ' || o o ||'
        (' || ____ || {0}' -f (Get-Text 'Console.Banner.Tagline1'))
        (' || || {0}' -f (Get-Text 'Console.Banner.Tagline2'))
        " '================'"
    )
    Write-Host ($art -join [Environment]::NewLine) -ForegroundColor Cyan
    Write-Host (" v{0}`n" -f $Version) -ForegroundColor DarkCyan
}

function Write-FindingToHost {
    [CmdletBinding()]
    param([Parameter(Mandatory)]$Finding)

    Write-Host (' [{0,-4}] {1}: {2}' -f $Finding.Severity, $Finding.Check, $Finding.Value) `
        -ForegroundColor $script:SeverityColour[$Finding.Severity]
}

function Write-WorstFindingsToHost {
    <#
    .SYNOPSIS
        Repeats the Findings that matter, worst first, once a Run has finished.
    .DESCRIPTION
        A Technician watching a Run scroll past needs the FAILs and WARNs gathered in one
        place at the end. This is not the Report; it is a pointer to it.
    #>

    [CmdletBinding()]
    param(
        [AllowNull()][AllowEmptyCollection()]$Finding,
        [Parameter(Mandatory)][string]$ReportPath
    )

    $failed = @($Finding | Where-Object { $_.Severity -eq 'FAIL' }).Count
    $warned = @($Finding | Where-Object { $_.Severity -eq 'WARN' }).Count

    Write-Host (Get-Text 'Console.Summary.Heading' $failed $warned) -ForegroundColor Cyan
    Sort-Finding -Finding $Finding | Where-Object { $_.Severity -eq 'FAIL' -or $_.Severity -eq 'WARN' } | ForEach-Object {
        Write-Host (' [{0}] {1}: {2}' -f $_.Severity, $_.Check, $_.Value) `
            -ForegroundColor $script:SeverityColour[$_.Severity]
    }
    Write-Host (Get-Text 'Console.Summary.Report' $ReportPath) -ForegroundColor Cyan
}