powershell-interactive-menu

Logo

Interactive powershell menu

View the Project on GitHub bibistroc/powershell-interactive-menu

Interactive Multi Menu

Demo

asciicast

Install

Install-Module -Name InteractiveMenu

Prerequisites

This module only works in Powershell version 5.0 and up.

Usage

Sample code can be found here

Using classes

# Import the module
using module InteractiveMenu

# Define the items for the menu
# Note: the url and info are optional
$menuItems = @(
    [InteractiveMultiMenuItem]::new("option1", "First Option", $true, 0, $false, "First option info", "https://example.com/")
    [InteractiveMultiMenuItem]::new("Option 2", "Second Option", $true, 1, $false, "Second option info", "https://example.com/")
)

# Define the header of the menu
$header = "Choose your options"

# Instantiate new menu object
$menu = [InteractiveMultiMenu]::new($header, $menuItems);

# [Optional] You can change the colors and the symbols
$options = @{
    HeaderColor = [ConsoleColor]::Magenta;
    HelpColor = [ConsoleColor]::Cyan;
    CurrentItemColor = [ConsoleColor]::DarkGreen;
    LinkColor = [ConsoleColor]::DarkCyan;
    CurrentItemLinkColor = [ConsoleColor]::Black;
    MenuDeselected = "[ ]";
    MenuSelected = "[x]";
    MenuCannotSelect = "[/]";
    MenuCannotDeselect = "[!]";
    MenuInfoColor = [ConsoleColor]::DarkYellow;
    MenuErrorColor = [ConsoleColor]::DarkRed;
}
$menu.SetOptions($options)

# Trigger the menu and receive the user selections
$selectedItems = $menu.GetSelections()

foreach ($item in $selectedItem) {
    Write-Host $item
}

Using functions

# Import the module
Import-Module InteractiveMenu

# Define the items for the menu
# Note: the url, info, selected and readonly parameters are optional
$menuItems = @(
    Get-InteractiveMultiMenuOption `
        -Item "option1" `
        -Label "First Option" `
        -Order 0 `
        -Info "First option info" `
        -Url "https://example.com"
    Get-InteractiveMultiMenuOption `
        -Item "option2" `
        -Label "Second Option" `
        -Order 1 `
        -Info "Second option info" `
        -Url "https://example.com" `
        -Selected `
        -Readonly
)

# [Optional] You can change the colors and the symbols
$options = @{
    HeaderColor = [ConsoleColor]::Magenta;
    HelpColor = [ConsoleColor]::Cyan;
    CurrentItemColor = [ConsoleColor]::DarkGreen;
    LinkColor = [ConsoleColor]::DarkCyan;
    CurrentItemLinkColor = [ConsoleColor]::Black;
    MenuDeselected = "[ ]";
    MenuSelected = "[x]";
    MenuCannotSelect = "[/]";
    MenuCannotDeselect = "[!]";
    MenuInfoColor = [ConsoleColor]::DarkYellow;
    MenuErrorColor = [ConsoleColor]::DarkRed;
}

# Define the header of the menu
$header = "Choose your options"

# Trigger the menu and receive the user selections
# Note: the options parameter is optional
$selectedOptions = Get-InteractiveMenuUserSelection -Header $header -Items $menuItems -Options $options

Refferences

Class InteractiveMultiMenuItem

Constructors

Fields

Class InteractiveMultiMenu

Constructors

Fields

Methods

Options