Skip to footer content
Iron Academy Logo
C# Application
C# Application

Other Categories

Selecting Items from a List - Spectre Console Series

Tim Corey
6m 26s

Spectre Console is a powerful NuGet package for .NET that lets developers build interactive console applications instead of plain, static text programs. One of its most useful features is the Spectre Console Selection Prompt, which allows you to present a list of options the user can scroll through and select directly with their keyboard. This makes console input more reliable, user-friendly, and visually polished compared to having people type their answers manually.

In his video “Selecting Items from a List – Spectre Console Series,” Tim Corey shows exactly how to use this feature. In this article, we’ll follow along with his explanations step by step, pointing out the time stamps so you can watch and code along. This is a great way to learn how to create and customize a Selection Prompt in your own .NET console apps.

Introduction to the Lesson

At 0:00, Tim explains that Spectre Console allows developers to turn C# console apps into visually appealing, informative applications. His series of videos covers the library in 10-minute chunks, with source code linked in the description.

In this lesson (0:18), Tim focuses on how to ask a user to choose an option from a list and then use the keyboard to navigate that list. This “ask and answer” pattern is the backbone of building console apps that feel modern and interactive. He also reminds viewers (0:27) to subscribe to his channel and visit iamtimcorey.com for more training resources.

Creating a Selection Prompt

At 0:34, Tim shows a list of placeholder names he commonly uses in his applications. This could just as easily be a list of fruits—apple, banana, orange—if you wanted a “favorite fruit” example. He sets up a variable of type string to hold the answer that the user will choose:

string favoriteName;
string favoriteName;

Spectre Console Selecting Items List 1 related to Creating a Selection Prompt

Then, at 0:57, Tim moves on from the basic prompt covered in the previous lesson to a full SelectionPrompt function:

favoriteName = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("Which is your favorite placeholder name")
        .AddChoices(names)
);
favoriteName = AnsiConsole.Prompt(
    new SelectionPrompt<string>()
        .Title("Which is your favorite placeholder name")
        .AddChoices(names)
);

He explains (1:13) that the SelectionPrompt requires a title, which in his case is “Which is your favorite placeholder name.” If you were asking for a favorite fruit, you’d change the title accordingly to “Which is your favorite fruit.”

While you can decorate the text (1:24) with Spectre Console’s styles—using blue, green, or grey colors, for example—in this lesson he is focusing on the selection prompt itself.

At 1:39, Tim adds the choices—his list of names—by calling .AddChoices(). These choices could be anything: fruit, numbers, objects, or even a “search” function’s results.

Finally, at 1:55, Tim uses Spectre Console’s markup line to display the chosen item back to the user:

AnsiConsole.MarkupLine($"Your favorite name is [red]{favoriteName}[/].");
AnsiConsole.MarkupLine($"Your favorite name is [red]{favoriteName}[/].");

This uses inline markup to color the selected answer in red, but you could just as easily use blue or green if your console theme requires it.

Running the Selection Prompt

Tim saves and runs the code at 2:34. The console displays:

  • A list of names or fruits.

  • Arrow keys let you move up and down (2:41).

  • Press Enter to select an item.

Tim demonstrates selecting “Sue Storm” (2:50). Once Enter is pressed, the list disappears and the console outputs:

Your favorite name is Sue Storm.
Your favorite name is Sue Storm.

If this had been a fruit list, you might see: “Your favorite fruit is Banana” or “Your favorite fruit is Apple.”

Handling Long Lists

Tim then addresses a common problem: long lists. At 3:13, he introduces the PageSize property to limit visible items:

.PageSize(4)
.PageSize(4)

He explains (3:19) that four is intentionally small to demonstrate the feature. Only that many items show at once. If you had a large fruit list - apple, banana, orange, mango, pineapple—PageSize prevents the console from endlessly scrolling.

To guide users, Tim adds a MoreChoicesText message in grey at 3:34:

.MoreChoicesText("[grey](Move down to reveal more choices)[/]")
.MoreChoicesText("[grey](Move down to reveal more choices)[/]")

This text tells the user they can move down to reveal more choices. This is especially helpful when the size of your list is big and you want a clear hint instead of risking an error or confusion.

Demonstrating the Long List Behavior

Tim runs the program again at 4:08:

  • Only four options appear initially.

  • The grey message says “Move down to reveal more choices” (4:13).

  • Scrolling down reveals additional items.

  • Scrolling back up shows the first ones again (4:20).

Tim notes (4:25) this is ideal for large lists—no endless console scrolling. You might display 10 or 15 at a time and let the user page through the rest. This solves the problem of overwhelming the console with too much output at once.

Why Selection Prompt Is Better Than Typing

At 4:38, Tim highlights why Selection Prompt is better than typing:

  • Once you make a choice, the list disappears (4:41).

  • You immediately see your chosen answer (4:45).

He compares this (5:05) to old prompts where users had to type “yes” or “no.” With SelectionPrompt, you can offer those choices directly and let users select with arrow keys, reducing errors and making the experience smoother.

Tim says (5:35) the prompt is a “really cool addition” because it simplifies input, makes console apps more interactive, and provides a clear solution to input problems.

Other Uses and Future Topics

Tim mentions (5:43) this lesson covers selecting one item from a list. In future videos, he will show multi selection prompts (5:39) where users can toggle multiple items on and off and then press Enter to confirm.

He also notes (5:47) the list can be any object type - strings, integers, fruits, even default options returned from a function. For example, you could prompt the user for their favorite fruit (“apple,” “banana,” “orange”) instead of a name (5:55).

With Spectre Console’s Selection Prompt you can even set defaults, handle required answers, and customize the action taken after a selection.

Conclusion

Tim wraps up (6:01) his video by reaffirming that this is how you implement item selection in Spectre Console - a clean, user-friendly way to handle lists in console applications. Whether you’re asking for a favorite fruit, a number, or an object, the Selection Prompt gives your app a polished experience without extra typing or errors.

Key Takeaways from Tim Corey’s Video

  • Spectre Console’s SelectionPrompt lets users navigate lists with arrow keys instead of typing input manually.

  • Customize with Title, Choices, Colors (blue, green, grey), PageSize, and MoreChoicesText to help reveal more options.

  • Once an item is selected, the list disappears and the chosen answer is displayed.

  • Ideal for both short and long lists, preventing console scrolling problems.

  • Works with any data type (string, numbers, fruits like apple, banana, orange, or custom objects).

  • Tim will cover multi selection prompts in future videos, where users can toggle multiple options and then press Enter to confirm.
Hero Worlddot related to Selecting Items from a List - Spectre Console Series
Hero Affiliate related to Selecting Items from a List - Spectre Console Series

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!