Public/Formatting/Write-Emphatic.ps1

Set-StrictMode -Version 2.0

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

    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) + '...'
        }

        if ($value.Length > 0) {
            $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

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

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