Advertisement
Guest User

Untitled

a guest
May 20th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ShowMenu
  2. {
  3.     param
  4.     (
  5.         [Parameter(Mandatory = $true)]
  6.         [string]
  7.         $Title,
  8.  
  9.         [Parameter(Mandatory = $true)]
  10.         [array]
  11.         $Options,
  12.  
  13.         [Parameter(Mandatory = $true)]
  14.         [int]
  15.         $Default
  16.     )
  17.  
  18.     Write-Host $Title
  19.     $minY = [Console]::CursorTop
  20.     $y = [Math]::Max([Math]::Min($Default, $Options.Count), 0)
  21.     do
  22.     {
  23.         [Console]::CursorTop = $minY
  24.         [Console]::CursorLeft = 0
  25.         $i = 0
  26.         foreach ($item in $Options)
  27.         {
  28.             $colors = @{
  29.                 BackgroundColor = if ($i -ne $y)
  30.                 {
  31.                     [Console]::BackgroundColor
  32.                 }
  33.                 else
  34.                 {
  35.                     "Cyan"
  36.                 }
  37.                 ForegroundColor = if ($i -ne $y)
  38.                 {
  39.                     [Console]::ForegroundColor
  40.                 }
  41.                 else
  42.                 {
  43.                     "Blue"
  44.                 }
  45.             }
  46.             Write-Host (' {0}. {1} ' -f ($i+1), $item) @colors
  47.             $i++
  48.         }
  49.         switch ([Console]::ReadKey().Key)
  50.         {
  51.             "UpArrow"
  52.             {
  53.                 if ($y -gt 0)
  54.                 {
  55.                     $y--
  56.                 }
  57.             }
  58.             "DownArrow"
  59.             {
  60.                 if ($y -lt ($Options.Count - 1))
  61.                 {
  62.                     $y++
  63.                 }
  64.             }
  65.             "Enter"
  66.             {
  67.                 return $Options[$y]
  68.             }
  69.         }
  70.     }
  71.     while ([Console]::ReadKey().Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))
  72. }
  73. if ($RU)
  74. {
  75.     $Title = "Выберите букву диска"
  76. }
  77. else
  78. {
  79.     $Title = "Desktop"
  80. }
  81. #$Options = 'test1', 'text2', 'menu3', 'result4'
  82. $Options = [string[]](Get-Disk | Where-Object -FilterScript {$_.BusType -ne "USB"} | Get-Partition | Get-Volume | Where-Object -FilterScript {$null -ne $_.DriveLetter}).DriveLetter | Sort-Object
  83.  
  84. ShowMenu -Title $Title -Options $Options -Default 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement