windows - batch menu outlines and design -


a while ago googling find out how make batch menu more "professional look" instead of using symbols such as:

|=====| |-----| |_____| 

to make outlines aroudn menu in batch. had no luck. today randomly found site:

http://http-server.carleton.ca/~dmcfet/menu.html 

and explains using ms-dos (edit.com) can this. computer 64 bit win 10. dot have edit.com so.... how make kind of menu hand? (printing special characters shown on left side of header "step 3, lines, lines, lines.")

here's batch + powershell menu maker i've been working on. set values in batch portion, , powershell stuff auto resize , reposition needed. when selection made, console buffer restores former contents, vanishing menu.

it looks this:

arrow navigated menu

here's code. save .bat extension.

<# : batch portion @echo off & setlocal enabledelayedexpansion  set "menu[0]=format c:" set "menu[1]=send spam boss" set "menu[2]=truncate database *" set "menu[3]=randomize user password" set "menu[4]=download dilbert" set "menu[5]=hack local ad"  set "default=0"  powershell -noprofile "iex (gc \"%~f0\" | out-string)" echo chose !menu[%errorlevel%]!.  goto :eof : end batch / begin powershell hybrid chimera #>  $menutitle = "=== menu ===" $menuprompt = "use arrow keys.  hit enter select."  $maxlen = $menuprompt.length + 6 $menu = gci env: | ?{ $_.name -match "^menu\[\d+\]$" } | %{     $_.value.trim()     $len = $_.value.trim().length + 6     if ($len -gt $maxlen) { $maxlen = $len } } [int]$selection = $env:default $h = $host.ui.rawui.windowsize.height $w = $host.ui.rawui.windowsize.width $xpos = [math]::floor(($w - ($maxlen + 5)) / 2) $ypos = [math]::floor(($h - ($menu.length + 4)) / 3)  $offy = [console]::windowtop; $rect = new-object management.automation.host.rectangle `     0,$offy,($w - 1),($offy+$ypos+$menu.length+4) $buffer = $host.ui.rawui.getbuffercontents($rect)  function destroy {     $coords = new-object management.automation.host.coordinates 0,$offy     $host.ui.rawui.setbuffercontents($coords,$buffer) }  function getkey {     while (-not ((37..40 + 13 + 48..(47 + $menu.length)) -contains $x)) {         $x = $host.ui.rawui.readkey('noecho,includekeydown').virtualkeycode     }     $x }  # http://goo.gl/iamdr6 function writeto-pos ([string]$str, [int]$x = 0, [int]$y = 0,     [string]$bgc = [console]::backgroundcolor, [string]$fgc = [console]::foregroundcolor) {     if($x -ge 0 -and $y -ge 0 -and $x -le [console]::windowwidth -and         $y -le [console]::windowheight) {         $savey = [console]::cursortop         $offy = [console]::windowtop                [console]::setcursorposition($x,$offy+$y)         write-host $str -b $bgc -f $fgc -nonewline         [console]::setcursorposition(0,$savey)     } }  function center([string]$what) {     $what = "    $what  "     $lpad = " " * [math]::max([math]::floor(($maxlen - $what.length) / 2), 0)     $rpad = " " * [math]::max(($maxlen - $what.length - $lpad.length), 0)     writeto-pos "$lpad   $what   $rpad" $xpos $line blue yellow }  function menu {     $line = $ypos     center $menutitle     $line++     center " "     $line++      ($i=0; $item = $menu[$i]; $i++) {         # write-host $xpad -nonewline         $rtpad = " " * ($maxlen - $item.length)         if ($i -eq $selection) {             writeto-pos "  > $item <$rtpad" $xpos ($line++) yellow blue         } else {             writeto-pos " $i`: $item  $rtpad" $xpos ($line++) blue yellow         }     }     center " "     $line++     center $menuprompt     1 }  while (menu) {      [int]$key = getkey      switch ($key) {          37 {}   # left or         38 { if ($selection) { $selection-- }; break }          39 {}   # right or down         40 { if ($selection -lt ($menu.length - 1)) { $selection++ }; break }          # number or enter         default { if ($key -gt 13) {$selection = $key - 48}; destroy; exit($selection) }     } } 

Comments