UNPKG

console-gui-tools

Version:

A simple library to draw option menu, text popup or other widgets and layout on a Node.js console.

159 lines 6.16 kB
/// <reference types="node" /> /// <reference types="node" /> import { EventEmitter } from "events"; import { ConsoleManager, KeyListenerArgs } from "../../ConsoleGui.js"; import { PhisicalValues } from "../Utils.js"; /** * @description The configuration for the InputPopup class. * @typedef {Object} InputPopupConfig * * @prop {string} id - The id of the popup. * @prop {string} title - The title of the popup. * @prop {string | number} value - The value of the popup. * @prop {boolean} numeric - If the input is numeric. * @prop {boolean} [visible] - If the popup is visible. * @prop {string} [placeholder] - Optional placeholder to show if empty * @prop {number} [maxLen] - Optional max length of the input (default 20). Set to 0 for no limit (not recommended). Since v3.4.0 * * @export * @interface InputPopupConfig */ export interface InputPopupConfig { id: string; title: string; value: string | number; numeric?: boolean; visible?: boolean; placeholder?: string; maxLen?: number; } /** * @class InputPopup * @extends EventEmitter * @description This class is used to create a popup with a text or numeric input. * * ![InputPopup](https://github.com/Elius94/console-gui-tools/assets/14907987/eecac72f-9ccc-444b-a0e3-2b7e277fdeea) * * Emits the following events: * - "confirm" when the user confirm the input * - "cancel" when the user cancel the input * - "exit" when the user exit the input * @param {InputPopupConfig} config - The config of the popup. * * @example ```ts * const popup = new InputPopup({ * id: "popup1", * title: "Choose the number", * value: selectedNumber, * numeric: true * }).show().on("confirm", (value) => { console.log(value) }) // show the popup and wait for the user to confirm * ``` */ export declare class InputPopup extends EventEmitter { readonly CM: ConsoleManager; readonly id: string; title: string; value: string | number; /** @var {number} cursorPos - Since v3.1.0 a blinking cursor has been added to InputPopup (thanks @Compositr) */ cursorPos: number; /** @var {setInterval} flashLoop - Since v3.1.0 a blinking cursor has been added to InputPopup (thanks @Compositr) */ flashLoop: NodeJS.Timer; private numeric; private visible; private marginTop; private parsingMouseFrame; /** @var {number} x - The x offset of the popup to be drown. If 0 it will be placed on the center */ private offsetX; /** @var {number} y - The y offset of the popup to be drown. If 0 it will be placed on the center */ private offsetY; private absoluteValues; private dragging; private dragStart; private focused; private placeholder?; private maxLen; constructor(config: InputPopupConfig); /** * @description This function is used to make the ConsoleManager handle the key events when the input is numeric and it is showed. * Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed. * @param {string} _str - The string of the input. * @param {Object} key - The key object. * @memberof InputPopup */ keyListenerNumeric(_str: string, key: KeyListenerArgs): void; /** * @description This function is used to make the ConsoleManager handle the key events when the input is text and it is showed. * Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed. * @param {string} _str - The string of the input. * @param {Object} key - The key object. * @memberof InputPopup */ keyListenerText(_str: string, key: KeyListenerArgs): void; /** * @description This function is used to get the value of the input. * @returns {string | number} The value of the input. * @memberof InputPopup */ getValue(): string | number; /** * @description This function is used to change the value of the input. It also refresh the ConsoleManager. * @param {string | number} newValue - The new value of the input. * @memberof InputPopup * @returns {InputPopup} The instance of the InputPopup. */ setValue(newValue: string | number): this; /** * @description This function is used to show the popup. It also register the key events and refresh the ConsoleManager. * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ show(): InputPopup; /** * @description This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager. * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ hide(): InputPopup; /** * @description This function is used to get the visibility of the popup. * @returns {boolean} The visibility of the popup. * @memberof InputPopup */ isVisible(): boolean; /** * @description This function is used to return the PhisicalValues of the popup (x, y, width, height). * @memberof InputPopup * @private * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ getPosition(): PhisicalValues; /** * @description This function is used to add the InputPopup key listener callback to te ConsoleManager. * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ private manageInput; /** * @description This function is used to remove the InputPopup key listener callback to te ConsoleManager. * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ private unManageInput; /** * @description This function is used to manage the mouse events on the OptionPopup. * @param {MouseEvent} event - The string of the input. * @memberof OptionPopup */ private mouseListener; /** * @description This function is used to draw the InputPopup to the screen in the middle. * @returns {InputPopup} The instance of the InputPopup. * @memberof InputPopup */ draw(): InputPopup; confirmDel(): void; delete(): void; } export default InputPopup; //# sourceMappingURL=InputPopup.d.ts.map