Skip to content
Snippets Groups Projects
Commit 93d71feb authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Merge branch 'dd_lightbar_menu_non_ansi_input_update' into 'master'

DDLightbarMenu: AdditionalQuitKeys now are honored in traditional (non-lightbar) mode, and there's a new menu property, nonANSIPromptText, which allows customization of the prompt text when in traditional/non-ANSI mode.

See merge request !518
parents eecc05b8 0d3726b5
No related branches found
No related tags found
1 merge request!518DDLightbarMenu: AdditionalQuitKeys now are honored in traditional (non-lightbar) mode, and there's a new menu property, nonANSIPromptText, which allows customization of the prompt text when in traditional/non-ANSI mode.
...@@ -355,6 +355,19 @@ By default, DDLightbarMenu ignores the isSelectable attribute of items and consi ...@@ -355,6 +355,19 @@ By default, DDLightbarMenu ignores the isSelectable attribute of items and consi
selectable (for efficiency). To enable usage of unselectable items, set the allowUnselectableItems selectable (for efficiency). To enable usage of unselectable items, set the allowUnselectableItems
property to true: property to true:
lbMenu.allowUnselectableItems = true; lbMenu.allowUnselectableItems = true;
If the user's terminal doesn't support ANSI, DDLightbarMenu will work in a non-lightbar
mode. When not using a lightbar interface, DDLightbarMenu will automatically use numbered
mode, where the menu will output numbers to the left of the menu items and let the user
type a number to choose an item.
You can also tell DDLightbarMenu to not work in lightbar mode if you want a more traditional
user interface (colors will still be supported) by setting the allowANSI property to false:
lbMenu.allowANSI = false;
For the traditional/non-lightbar mode, you can customize the prompt text that is used, by
changing the nonANSIPromptText property. For instance:
lbMenu.nonANSIPromptText = "Type a number to choose an item: ";
*/ */
"use strict"; "use strict";
...@@ -535,6 +548,9 @@ function DDLightbarMenu(pX, pY, pWidth, pHeight) ...@@ -535,6 +548,9 @@ function DDLightbarMenu(pX, pY, pWidth, pHeight)
// Whether or not to allow ANSI behavior. Mainly for testing (this should be true). // Whether or not to allow ANSI behavior. Mainly for testing (this should be true).
this.allowANSI = true; this.allowANSI = true;
// Text to use for the user input prompt for the non-ANSI interface
this.nonANSIPromptText = "\x01n\x01c\x01hY\x01n\x01cour \x01hC\x01n\x01choice\x01h\x01g: \x01c";
// Member functions // Member functions
this.Add = DDLightbarMenu_Add; this.Add = DDLightbarMenu_Add;
this.Remove = DDLightbarMenu_Remove; this.Remove = DDLightbarMenu_Remove;
...@@ -2291,10 +2307,42 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) ...@@ -2291,10 +2307,42 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes)
{ {
// The user's terminal doesn't support ANSI // The user's terminal doesn't support ANSI
var userAnswerIsValid = false; var userAnswerIsValid = false;
var writePromptText = true;
do do
{ {
if (writePromptText)
{
if (typeof(this.nonANSIPromptText) === "string" && console.strlen(this.nonANSIPromptText) > 0)
console.print(this.nonANSIPromptText);
else
console.print("\x01n\x01c\x01hY\x01n\x01cour \x01hC\x01n\x01choice\x01h\x01g: \x01c"); console.print("\x01n\x01c\x01hY\x01n\x01cour \x01hC\x01n\x01choice\x01h\x01g: \x01c");
}
writePromptText = true; // Default value
console.attributes = "N"; console.attributes = "N";
var inputMode = K_NOECHO|K_NOSPIN|K_NOCRLF;
var userInput = console.getkey(inputMode);
var userInputUpper = userInput.toUpperCase();
// Set this.lastUserInput if it's valid
if (console.aborted || userInputUpper == "Q" || userInput == CTRL_C || userInput == KEY_ESC)
{
if (userInputUpper == "Q")
this.lastUserInput = "Q";
else if (userInput == CTRL_C || userInput == KEY_ESC)
this.lastUserInput = userInput;
else if (console.aborted)
this.lastUserInput = CTRL_C;
userAnswerIsValid = true;
}
else if (this.QuitKeysIncludes(userInput))
{
this.lastUserInput = userInput;
userAnswerIsValid = true;
}
else if (/[0-9]/.test(userInput))
{
// Put the user's input back in the input buffer to
// be used for getting the rest of the message number.
console.ungetstr(userInput);
var userEnteredItemNum = console.getnum(numItems); var userEnteredItemNum = console.getnum(numItems);
this.lastUserInput = userEnteredItemNum.toString(); this.lastUserInput = userEnteredItemNum.toString();
if (!console.aborted && userEnteredItemNum > 0) if (!console.aborted && userEnteredItemNum > 0)
...@@ -2312,6 +2360,9 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) ...@@ -2312,6 +2360,9 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes)
this.lastUserInput = "Q"; // To signify quitting this.lastUserInput = "Q"; // To signify quitting
userAnswerIsValid = true; userAnswerIsValid = true;
} }
}
else
writePromptText = false; // Invalid user input
} while (!userAnswerIsValid && bbs.online && !js.terminated); } while (!userAnswerIsValid && bbs.online && !js.terminated);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment