Skip to content

Customizing menus

Héctor Barreras Almarcha edited this page Dec 15, 2017 · 12 revisions

It may be boring (or not, depends on who you ask) if everyone's menus looked identical. You get to customize many things about them:

Welcome message

When you show your menu to a user, it is common to find something like:

Hello user! Please choose among the following options:
1 - Blah blah
2 - Whatever
...

You want to be able to set that message, and perhaps you want to only show it when the user first enters the menu, and not every time he completes an option. Check out the welcomeMsg and welcomeMsgDisplayScenario properties to those ends.

Option display style

Let's have a look at different ways you might want to display your options in an Index-based menu:

1 Option
1 - Option
[1] Option
Option - 1 // You could, but please don't.

You can choose to have your menu items printed however you like. The itemPrintFormat property allows you to set a string that defines how to print your items. Let's say we have an instance of the Menu class called myMenu:

myMenu.itemPrintFormat = "[%item_key%] => %item_text%"; // Yield an output like "[1] Option"
myMenu.itemPrintFormat = "%item_key% - %item_text%"; // Yield an output like "1 - Option"

Prompt string

After you've displayed all available options, you will expect the user to choose one of them. Usually, the user takes notice of your expectation from him via a prompt string, which may look like Please, choose one of the available options: or a simple > . The promptMsg property is how you can define such string.

Error message on item selection

In the event that the user input cannot be mapped to an enabled IMenuItem in the menu (for example, you ask the user for a number from 1 to 4 and he dares to input a 5, or an 'e' character), you probably want to gently inform your user something is wrong with his selection. The onInvalidItemSelectedMsg property takes care of this.

Menu exit message

Maybe you want to say goodbye to your user when he decides to exit the menu. Maybe you don't. The onMenuExitMsg property defines what is written to screen just before the menu finishes execution.

Clone this wiki locally