Public/Formatting/Write-Emphatic.ps1

Set-StrictMode -Version 2.0

Function Write-Emphatic {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost','')]
    param(
        [Parameter(Mandatory=$true)]
        [string]$Message
    )

    function StringFormat {
        param(
            [int]$length,
            [string]$value,
            [string]$prefix = '',
            [string]$postfix = '',
            [switch]$padright
        )

        # wraps string in spaces so we reduce length by two
        $length = $length - 2 #- $postfix.Length - $prefix.Length
        if($value.Length -gt $length){
            # Reduce to length - 4 for elipsis
            $value = $value.Substring(0, $length - 4) + '...'
        }

        $value = " $value "
        if($padright){
            $value = $value.PadRight($length, '-')
        } else {
            $value = $value.PadLeft($length, '-')
        }

        return $prefix + $value + $postfix
    }

    $actualWidth = (Get-Host).UI.RawUI.BufferSize.Width
    $width = $actualWidth - ($actualWidth % 2)
    $half = $width / 2

    $messageString = StringFormat -length $half -value $Message -prefix '[' -postfix ']' -padright
    #$rightString = StringFormat -length $half -value $TaskType -postfix ']' -padright

    #$message = ($leftString + $rightString)
    #Write-Host ''
    # Write-Host $message -ForegroundColor 'Green'
    Write-Host $messageString -ForegroundColor 'Magenta'
}