src/private/Write-CustomHost.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
function Write-CustomHost { [CmdletBinding()] param ( [String] $String, # [datetime] $StartTime = [datetime]::Now, [string] $StartChar = [char]9654, [int] $Indentation = 1, [System.ConsoleColor] $Color = "White", [switch] $AddTime ) begin { $3spaces = " " $Indent = $3spaces*$Indentation $TimeDelta = [datetime]::Now - $StartTime if($TimeDelta.TotalSeconds -ge 60){ $Duration = "{0}m {1}s" -f $TimeDelta.Minutes, $TimeDelta.Seconds } elseif($TimeDelta.TotalSeconds -lt 60 -and $TimeDelta.TotalSeconds -gt 1){ $Duration = "{0:n2}s" -f $TimeDelta.TotalSeconds } elseif($TimeDelta.TotalSeconds -le 1){ $Duration = "{0}ms" -f [int]$TimeDelta.TotalMilliseconds } } process { Write-Host $Indent $StartChar $String -ForegroundColor $Color -NoNewline if($AddTime){ Write-Host " ${Duration}" -ForegroundColor DarkGray } else{ Write-Host "" } } end { } } # Write-CustomHost -String "Hello World!" -Indentation 1 # Write-CustomHost -String "Hello World!" -Indentation 2 # Write-CustomHost -String "Hello World!" -Indentation 3 |