Skip to content

Instantly share code, notes, and snippets.

View pitermarx's full-sized avatar

ριтєя мαяχ pitermarx

View GitHub Profile
@pitermarx
pitermarx / menu.ps1
Created August 28, 2024 13:28
A powershell menu
function menu($items, $HighlightColor = "Yellow", [Switch]$ReturnIndex, [Switch]$MultiSelect) {
$selected=@()
:w while ($true) {
# prevent overflow
$pos = if ($null -eq $pos -or $pos -lt 0) { 0 } else { [Math]::Min($pos, $items.Length-1) }
# draw
$i=0
$items | ForEach-Object {
$x = if (-not $MultiSelect) { "" } elseif ($selected -contains $i) { " [x]" } else { " [ ]" }
if ($i++ -eq $pos) { Write-Host ">$x $_" -ForegroundColor $HighlightColor }