Skip to content

Instantly share code, notes, and snippets.

@synikil
Created May 17, 2019 22:20
Show Gist options
  • Save synikil/76a1cce16d148ce8bca40957a92fe854 to your computer and use it in GitHub Desktop.
Save synikil/76a1cce16d148ce8bca40957a92fe854 to your computer and use it in GitHub Desktop.
Function MenuMaker{
param(
[parameter(Mandatory=$true)][String[]]$Selections,
[switch]$IncludeExit,
[string]$Title = $null
)
$Width = if($Title){$Length = $Title.Length;$Length2 = $Selections|%{$_.length}|Sort -Descending|Select -First 1;$Length2,$Length|Sort -Descending|Select -First 1}else{$Selections|%{$_.length}|Sort -Descending|Select -First 1}
$Buffer = if(($Width*1.5) -gt 78){[math]::floor((78-$width)/2)}else{[math]::floor($width/4)}
if($Buffer -gt 6){$Buffer = 6}
$MaxWidth = $Buffer*2+$Width+$($Selections.count).length+2
$Menu = @()
$Menu += "╔"+"═"*$maxwidth+"╗"
if($Title){
$Menu += "║"+" "*[Math]::Floor(($maxwidth-$title.Length)/2)+$Title+" "*[Math]::Ceiling(($maxwidth-$title.Length)/2)+"║"
$Menu += "╟"+"─"*$maxwidth+"╢"
}
For($i=1;$i -le $Selections.count;$i++){
$Item = "$(if ($Selections.count -gt 9 -and $i -lt 10){" "})$i`. "
$Menu += "║"+" "*$Buffer+$Item+$Selections[$i-1]+" "*($MaxWidth-$Buffer-$Item.Length-$Selections[$i-1].Length)+"║"
}
If($IncludeExit){
$Menu += "║"+" "*$MaxWidth+"║"
$Menu += "║"+" "*$Buffer+"X - Exit"+" "*($MaxWidth-$Buffer-8)+"║"
}
$Menu += "╚"+"═"*$maxwidth+"╝"
$menu
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment