Last active
April 21, 2024 11:46
-
-
Save wtarr/19b457bd77f305c51829e6d36e813a3f to your computer and use it in GitHub Desktop.
Template to build a CLI app launcher. Requires nugets CliWrap and Spectre.Console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CliWrap; | |
using Spectre.Console; | |
while (true) | |
{ | |
var mainMenuResult = AnsiConsole.Prompt( | |
new SelectionPrompt<string>() | |
.Title("Main Menu") | |
.PageSize(3) | |
.AddChoices(new [] { "1. Text Editors", "2. Exit"}) | |
); | |
if (mainMenuResult == "1. Text Editors") | |
{ | |
var result = AnsiConsole.Prompt( | |
new SelectionPrompt<string>() | |
.Title("What would you like to do?") | |
.PageSize(3) | |
.AddChoices(new[] { "1. Open Notepad", "2. Open VS Code", "3. Return" })); | |
if (result == "1. Open Notepad") | |
{ | |
var cmd = Cli.Wrap("notepad.exe"); | |
await cmd.ExecuteAsync(); | |
} | |
else if (result == "2. Open VS Code") | |
{ | |
var cmd = Cli.Wrap("code"); | |
await cmd.ExecuteAsync(); | |
} | |
else if (result == "3. Return") | |
{ | |
} | |
else | |
{ | |
AnsiConsole.MarkupLine("Invalid option"); | |
} | |
} | |
else if (mainMenuResult == "2. Exit") | |
{ | |
AnsiConsole.MarkupLine("Goodbye"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment