powershell-interactive-menu

Logo

Interactive powershell menu

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

Interactive Choose 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
$answerItems = @(
    [InteractiveMenuChooseMenuItem]::new("I choose good", "good", "Good info"),
    [InteractiveMenuChooseMenuItem]::new("I choose bad", "bad", "Bad info")
);

# Define the question of the menu
$question = "Choos between good and bad"

# Instantiate new menu object
$menu = [InteractiveMenuChooseMenu]::new($question, $answerItems);

# [Optional] You can change the colors and the separator
$options = @{
    MenuInfoColor = [ConsoleColor]::DarkYellow
    QuestionColor = [ConsoleColor]::Magenta
    HelpColor = [ConsoleColor]::Cyan
    ErrorColor = [ConsoleColor]::DarkRed
    HighlightColor = [ConsoleColor]::DarkGreen
    OptionSeparator = "      "
}
$menu.SetOptions($options)

# Trigger the menu and receive the user answer
$answer = $menu.GetAnswer()

Write-Host "The user answered: $answer"

Using functions

# Import the module
Import-Module InteractiveMenu

# Define the items for the menu
$answerItems = @(
    Get-InteractiveChooseMenuOption `
        -Label "I choose good" `
        -Value "good" `
        -Info "Good info"
    Get-InteractiveChooseMenuOption `
        -Label "I choose bad" `
        -Value "bad" `
        -Info "Bad info"
)

# [Optional] You can change the colors and the symbols
$options = @{
    MenuInfoColor = [ConsoleColor]::DarkYellow
    QuestionColor = [ConsoleColor]::Magenta
    HelpColor = [ConsoleColor]::Cyan
    ErrorColor = [ConsoleColor]::DarkRed
    HighlightColor = [ConsoleColor]::DarkGreen
    OptionSeparator = "      "
}

# Define the question of the menu
$question = "Choos between good and bad"

# Trigger the menu and receive the user answer
# Note: the options parameter is optional
$answer = Get-InteractiveMenuChooseUserSelection -Question $question -Answers $answerItems -Options $options

Refferences

Class InteractiveMenuChooseMenuItem

Constructors

Fields

Class InteractiveMenuChooseMenu

Constructors

Fields

Methods

Options