WriteHost.psm1
for($l=0; $l -lt $blocks.Length; $l++) { $block = $blocks[$l] if($block -is [string]) { if($block -eq "`n") { $lineCount++ $leftLength = 0 $rightLength = 0 Write-Host } elseif($block -eq "`t") { # the length of the rest of the line $rightLength = ($(for($r=$l+1; $r -lt $blocks.Length -and $blocks[$r] -is [hashtable]; $r++) { $blocks[$r].length + 1 }) | Measure-Object -Sum).Sum $space = $width - $rightLength - $leftLength if($leftLength) { $last = $blocks[($l-1)] $c = @{} if($last.bg) { $c.ForegroundColor = $last.bg } if($last.fg) { $c.BackgroundColor = $last.fg } Write-Host -NoNewLine $RIGHT @c } Write-Host -NoNewLine (" " * ${space}) if($rightLength) { $next = $blocks[($l+1)] $c = @{} if($next.bg) { $c.ForegroundColor = $next.bg } if($next.fg) { $c.BackgroundColor = $next.fg } Write-Host -NoNewLine $LEFT @c } } } else { if($leftLength -eq 0 -and $rightLength -eq 0) { # On a new line, recalculate the length of the "left-aligned" line $leftLength = ($(for($r=$l; $r -lt $blocks.Length -and $blocks[$r] -is [hashtable]; $r++) { $blocks[$r].length + 1 }) | Measure-Object -Sum).Sum } $c = @{} if($block.fg) { $c.ForegroundColor = $block.fg } if($block.bg) { $c.BackgroundColor = $block.bg } Write-Host -NoNewLine $block.Text @c if($blocks[($l+1)] -is [hashtable]) { if($block.bg -eq $blocks[($l+1)].bg) { Write-Host $GT -NoNewLine @c } else { $c = @{} $c.ForegroundColor = if($block.bg) { $block.bg } else { [PowerLineOutput]::EscapeCodes.bg.Default } if($block.bg) { $c.BackgroundColor = $blocks[($l+1)].bg } Write-Host -NoNewLine $RIGHT @c } } } } # if there's anything on the right and there's no ANSI VT support, put the prompt on the next line if($rightLength) { Write-Host "`n$RIGHT" -NoNewLine } |