From ef58837549ce5f1470b57d6268576c9ff137e3e7 Mon Sep 17 00:00:00 2001 From: Elia Lazzari Date: Fri, 31 May 2024 17:32:47 +0200 Subject: [PATCH] [Bug]: Adding lots of Progress produces MaxListenersExceededWarning Fixes #86 Added instruction to set Input and mouse maxListeners to 128 Use "querty.mjs" example to test with a lot of controls. --- examples/querty.mjs | 66 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/ConsoleGui.ts | 3 +++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 examples/querty.mjs diff --git a/examples/querty.mjs b/examples/querty.mjs new file mode 100644 index 0000000..3a1d212 --- /dev/null +++ b/examples/querty.mjs @@ -0,0 +1,66 @@ +import { ConsoleManager, Progress, ConfirmPopup, Button } from "../dist/esm/ConsoleGui.mjs" + +const opt = { + title: "QWERTY Keyboard", + layoutOptions: { + type: "single" + }, + logLocation: "popup", + enableMouse: true +} + +const GUI = new ConsoleManager(opt) + +GUI.on("exit", () => { + closeApp() +}) + +GUI.on("keypressed", (key) => { + switch (key.name) { + case "q": + new ConfirmPopup({ + id: "popupQuit", + title: "Are you sure you want to quit?" + }).show().on("confirm", () => closeApp()) + break + default: + break + } +}) + +const closeApp = () => { + console.clear() + process.exit() +} + +GUI.refresh() + +// Definizione della posizione di ciascun tasto della tastiera QWERTY +const keys = [ + { label: "Q", x: 2, y: 2 }, { label: "W", x: 7, y: 2 }, { label: "E", x: 12, y: 2 }, { label: "R", x: 17, y: 2 }, + { label: "T", x: 22, y: 2 }, { label: "Y", x: 27, y: 2 }, { label: "U", x: 32, y: 2 }, { label: "I", x: 37, y: 2 }, + { label: "O", x: 42, y: 2 }, { label: "P", x: 47, y: 2 }, + + { label: "A", x: 3, y: 5 }, { label: "S", x: 8, y: 5 }, { label: "D", x: 13, y: 5 }, { label: "F", x: 18, y: 5 }, + { label: "G", x: 23, y: 5 }, { label: "H", x: 28, y: 5 }, { label: "J", x: 33, y: 5 }, { label: "K", x: 38, y: 5 }, + { label: "L", x: 43, y: 5 }, + + { label: "Z", x: 4, y: 8 }, { label: "X", x: 9, y: 8 }, { label: "C", x: 14, y: 8 }, { label: "V", x: 19, y: 8 }, + { label: "B", x: 24, y: 8 }, { label: "N", x: 29, y: 8 }, { label: "M", x: 34, y: 8 } +] + +const style1 = { + borderColor: "red", + color: "red", +} + +const keyBars = keys.map(key => new Button({ + id: key.label, + x: key.x, + y: key.y, + length: 3, + text: key.label, + key: { name: key.label.toLowerCase(), ctrl: false }, + style: style1 +})) + diff --git a/package.json b/package.json index 1cda3af..e78dbf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "console-gui-tools", - "version": "3.5.0", + "version": "3.6.0", "description": "A simple library to draw option menu, text popup or other widgets and layout on a Node.js console.", "main": "dist/esm/ConsoleGui.mjs", "types": "dist/types/ConsoleGui.d.ts", diff --git a/src/ConsoleGui.ts b/src/ConsoleGui.ts index c199c84..23c8f0e 100644 --- a/src/ConsoleGui.ts +++ b/src/ConsoleGui.ts @@ -98,6 +98,7 @@ class ConsoleManager extends EventEmitter { layoutOptions!: LayoutOptions layout!: LayoutManager changeLayoutKey!: string + maxListeners = 128 private changeLayoutkeys!: string[] applicationTitle!: string private showLogKey!: string @@ -111,6 +112,7 @@ class ConsoleManager extends EventEmitter { super() this.Terminal = process.stdout this.Input = process.stdin + this.Input.setMaxListeners(this.maxListeners) if (!ConsoleManager.instance) { ConsoleManager.instance = this @@ -124,6 +126,7 @@ class ConsoleManager extends EventEmitter { }) this.mouse = new MouseManager(this.Terminal, this.Input) + this.mouse.setMaxListeners(this.maxListeners) this.popupCollection = {} this.controlsCollection = {} this.eventListenersContainer = {}