GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Sebazzz/PSMenu: Simple powershell menu to render interactive console menu

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

87 Commits
87 Commits

Folders and files

NameName
Last commit message
Last commit date
PSMenu
PSMenu
 
 
docs
docs
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Test-Module.ps1
Test-Module.ps1
 
 
build.ps1
build.ps1
 
 
deploy.psdeploy.ps1
deploy.psdeploy.ps1
 
 
psake.ps1
psake.ps1
 
 

Repository files navigation

PSMenu

Simple module to generate interactive console menus (like yeoman)

Examples

Very basic example.

Show-Menu @("option 1", "option 2", "option 3")

Basic example

Custom formatting

Custom formatting of menu items and multi-selection:

Show-Menu -MenuItems $(Get-NetAdapter) -MultiSelect -MenuItemFormatter { $Args | Select -Exp Name }

Classes as options (complex example)

Custom options

You can also use custom options (enriched options). A more complicated example:

class MyMenuOption {
    [String]$DisplayName
    [ScriptBlock]$Script

    [String]ToString() {
        Return $This.DisplayName
    }
}

function New-MenuItem([String]$DisplayName, [ScriptBlock]$Script) {
    $MenuItem = [MyMenuOption]::new()
    $MenuItem.DisplayName = $DisplayName
    $MenuItem.Script = $Script
    Return $MenuItem
}

$Opts = @(
    $(New-MenuItem -DisplayName "Say Hello" -Script { Write-Host "Hello!" }),
    $(New-MenuItem -DisplayName "Say Bye!" -Script { Write-Host "Bye!" })
)

$Chosen = Show-Menu -MenuItems $Opts

& $Chosen.Script

This will show the menu items like you expect.

Custom formatters and multiselect

Separators

Show-Menu @("Option A", "Option B", $(Get-MenuSeparator), "Quit")

Separators are unselectable items used for visual distinction in the menu.

Separator support

Callback

The Callback option can be used to perform actions while the menu is displayed. Note: always save & restore the cursor position like in the following example if the host output is changed in the callback.

Clear-Host
Write-Host "Current time: $(Get-Date)"
Write-Host ""
Show-Menu @("Option A", "Option B") -Callback {
    $lastTop = [Console]::CursorTop
    [System.Console]::SetCursorPosition(0, 0)
    Write-Host "Current time: $(Get-Date)"
    [System.Console]::SetCursorPosition(0, $lastTop)
}

Callback example

Installation

You can install it from the PowerShellGallery using PowerShellGet

Install-Module PSMenu

Features

  • Returns value of selected menu item
  • Returns index of selected menu item (using -ReturnIndex switch)
  • Multi-selection support (using -MultiSelect switch), use spacebar to select items
  • Navigation with up/down/page-up/page-down/home/end keys
  • Longer list scroll within window
  • Support for separators
  • Esc key quits the menu ($null returned)
  • Extensively documented
  • Perform actions while the menu is displayed (using -Callback)

Documentation

For details, check out the comment-based help in the source code, or use Get-Help Show-Menu from the command-line. See also Get-Help.

Contributing

  • Source hosted at GitHub
  • Report issues/questions/feature requests on GitHub Issues

Pull requests are very welcome!

About

Simple powershell menu to render interactive console menu

Resources

Readme
License
Activity

Stars

95 stars

Watchers

4 watching

Forks

11 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.