Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Adding lots of Progress produces MaxListenersExceededWarning #88

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions examples/querty.mjs
Original file line number Diff line number Diff line change
@@ -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
}))

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/ConsoleGui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ConsoleManager extends EventEmitter {
layoutOptions!: LayoutOptions
layout!: LayoutManager
changeLayoutKey!: string
maxListeners = 128
private changeLayoutkeys!: string[]
applicationTitle!: string
private showLogKey!: string
Expand All @@ -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

Expand All @@ -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 = {}
Expand Down
Loading