Last active
October 26, 2020 16:46
-
-
Save pfmoore/92939c114ca8ca2539078f4ec84b3b84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function to_pos($pos, $str) { | |
$text_width = ($str -replace '\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])','').Length | |
$rpos = $host.UI.RawUI.WindowSize.Width - $text_width + 1 | |
$bot = $host.UI.RawUI.WindowSize.Height | |
$setloc = switch ($pos) { | |
"UL" { "`e[1;1f" } | |
"UR" { "`e[1;${rpos}f" } | |
"LL" { "`e[${bot};1f" } | |
"LR" { "`e[${bot};${rpos}f" } | |
"L" { "`e[1G" } | |
"R" { "`e[${rpos}G" } | |
} | |
"`e7${setloc}${str}`e8" | |
} | |
$parts = @{ | |
Defaults = @{ | |
# Fore = "AliceBlue"; | |
Post = [Char]0xe0b0 | |
} | |
Main = @( | |
@{ Fore = "Cyan"; Text = "PS"; Post = " "}, | |
@{ Fore = "Red"; Script = { get-date -uformat "%H:%M" } } | |
) | |
Right = @( | |
@{ Fore = "Green"; Script = { $pwd } } | |
) | |
} | |
foreach ($part in $parts.Main) { | |
if ($null -ne $part.Script) { | |
$text = & $part.Script | |
} | |
elseif ($null -ne $part.Text) { | |
$text = $part.Text | |
} | |
Write-Host -NoNewLine -Fore $part.Fore $text | |
Write-Host -NoNewLine $part.Sep | |
# Newline and > at the end??? | |
# Begs the question of multi-line prompts. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment