diff --git a/exec/load/dd_lightbar_menu.js b/exec/load/dd_lightbar_menu.js index 9a9b04a6c0a5b00e6b6c4074d8e38e9e9564a665..dfa31d3c91ea961756c29663ae749d87d1a14041 100644 --- a/exec/load/dd_lightbar_menu.js +++ b/exec/load/dd_lightbar_menu.js @@ -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 property to 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"; @@ -535,6 +548,9 @@ function DDLightbarMenu(pX, pY, pWidth, pHeight) // Whether or not to allow ANSI behavior. Mainly for testing (this should be 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 this.Add = DDLightbarMenu_Add; this.Remove = DDLightbarMenu_Remove; @@ -2291,27 +2307,62 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) { // The user's terminal doesn't support ANSI var userAnswerIsValid = false; + var writePromptText = true; do { - console.print("\x01n\x01c\x01hY\x01n\x01cour \x01hC\x01n\x01choice\x01h\x01g: \x01c"); + 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"); + } + writePromptText = true; // Default value console.attributes = "N"; - var userEnteredItemNum = console.getnum(numItems); - this.lastUserInput = userEnteredItemNum.toString(); - if (!console.aborted && userEnteredItemNum > 0) + 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)) { - if (this.ItemIsSelectable(userEnteredItemNum-1)) + 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); + this.lastUserInput = userEnteredItemNum.toString(); + if (!console.aborted && userEnteredItemNum > 0) + { + if (this.ItemIsSelectable(userEnteredItemNum-1)) + { + var chosenItem = this.GetItem(userEnteredItemNum-1); + if (typeof(chosenItem) === "object" && chosenItem.hasOwnProperty("retval")) + retVal = chosenItem.retval; + userAnswerIsValid = true; + } + } + else { - var chosenItem = this.GetItem(userEnteredItemNum-1); - if (typeof(chosenItem) === "object" && chosenItem.hasOwnProperty("retval")) - retVal = chosenItem.retval; + this.lastUserInput = "Q"; // To signify quitting userAnswerIsValid = true; } } else - { - this.lastUserInput = "Q"; // To signify quitting - userAnswerIsValid = true; - } + writePromptText = false; // Invalid user input } while (!userAnswerIsValid && bbs.online && !js.terminated); }