Releases: Elius94/console-gui-tools
v1.1.16
What's Changed
- InputPopup numeric should be able to manage decimal numbers by @Elius94 in #31
- In PageBuilder Class: getPageHeight returns the exact number of rows but not the visible rows. Need to fix by @Elius94 in #32
- GUI.log(), GUI.warn(), GUI.info(), GUI.error() functions have issues when the input is a number by @Elius94 in #34
Full Changelog: v1.1.15...v1.1.16
v1.1.15
Full Changelog: v1.1.14...v1.1.15
v1.1.14
Full Changelog: v1.1.13...v1.1.14
v1.1.13
Full Changelog: 1.1.12...v1.1.13
1.1.12
1.1.11
What's Changed
Full Changelog: 1.1.10...1.1.11
Classes
- FileSelectorPopup ⇐
EventEmitter
Constants
- CM :
ConsoleManager
the instance of ConsoleManager (singleton)
FileSelectorPopup ⇐ EventEmitter
Kind: global class
Extends: EventEmitter
- FileSelectorPopup ⇐
EventEmitter
- new FileSelectorPopup(id, title, basePath, [limitToPath], [allowedExtensions], visible)
- .listDir(path) ⇒
Promise.<Array.<object>>
- .updateList(path)
- .keyListner(str, key)
- .getSelected() ⇒
string
|number
- .setSelected(selected) ⇒
FileSelectorPopup
- .show() ⇒
FileSelectorPopup
- .hide() ⇒
FileSelectorPopup
- .isVisible() ⇒
boolean
- .manageInput() ⇒
FileSelectorPopup
- .unManageInput() ⇒
FileSelectorPopup
- .draw() ⇒
FileSelectorPopup
new FileSelectorPopup(id, title, basePath, [limitToPath], [allowedExtensions], visible)
This class is used to create a popup with a file input to select a file or a directory.
It will run a promise with fs.readdir to get the list of files and directories.
The user can select a file or a directory and the popup will be closed.
Emits the following events:
- "confirm" when the user confirm the file or directory selection. The file or directory path is passed as parameter like this: {path: "path/to/file", name: "file.ext"}
- "cancel" when the user cancel the file or directory selection.
- "exit" when the user exit
Param | Type | Default | Description |
---|---|---|---|
id | string |
The id of the popup. | |
title | string |
The title of the popup. | |
basePath | string |
The main path of the popup. re case sensitive. | |
[limitToPath] | boolean |
false |
If true, the user can select a directory. Otherwise, only files are selectable. When true, to enter a directory, the user must press the space key instead of the enter key. |
[allowedExtensions] | Array.<string> |
[] |
The allowed extensions. If not set, all extensions are allowed. The extensions a can only select files in the path. If false, the user can select files in the path and parent directories. |
visible | boolean |
If the popup is visible. Default is false (make it appears using show()). |
Example
const popup = new FileSelectorPopup("popup1", "Choose the file", "./examples").show().on("confirm", (selected) => { console.log(selected) }) // show the popup and wait for the user to confirm
fileSelectorPopup.listDir(path) ⇒ Promise.<Array.<object>>
This function is used to load the list of files and directories in the current path.
it return a promise with the list of files and directories. The list is an array of objects like this:
[{text: "📄 file.ext", name: "file.ext", type: "file", path: "path/to/file.ext"}, {text: "📁 dir/", name: "dir", type: "dir", path: "path/to/dir"}]
Kind: instance method of FileSelectorPopup
Returns: Promise.<Array.<object>>
- The list of files and directories.
Param | Type | Description |
---|---|---|
path | string |
The path to load the list. |
fileSelectorPopup.updateList(path)
This function calls the updateList function and store the result to this.options, it also refresh the list of files and directories.
Kind: instance method of FileSelectorPopup
Param | Type | Description |
---|---|---|
path | string |
The path to load the list. |
fileSelectorPopup.keyListner(str, key)
This function is used to make the ConsoleManager handle the key events when the popup is showed.
Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed.
Kind: instance method of FileSelectorPopup
Param | Type | Description |
---|---|---|
str | string |
The string of the input. |
key | Object |
The key object. |
fileSelectorPopup.getSelected() ⇒ string
| number
This function is used to get the selected option.
Kind: instance method of FileSelectorPopup
Returns: string
| number
- The selected value of the popup.
fileSelectorPopup.setSelected(selected) ⇒ FileSelectorPopup
This function is used to change the selection of the popup. It also refresh the ConsoleManager.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
Param | Type | Description |
---|---|---|
selected | string | number |
The new value of the selection. |
fileSelectorPopup.show() ⇒ FileSelectorPopup
This function is used to show the popup. It also register the key events and refresh the ConsoleManager.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
fileSelectorPopup.hide() ⇒ FileSelectorPopup
This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
fileSelectorPopup.isVisible() ⇒ boolean
This function is used to get the visibility of the popup.
Kind: instance method of FileSelectorPopup
Returns: boolean
- The visibility of the popup.
fileSelectorPopup.manageInput() ⇒ FileSelectorPopup
This function is used to add the FileSelectorPopup key listener callback to te ConsoleManager.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
fileSelectorPopup.unManageInput() ⇒ FileSelectorPopup
This function is used to remove the FileSelectorPopup key listener callback to te ConsoleManager.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
fileSelectorPopup.draw() ⇒ FileSelectorPopup
This function is used to draw the FileSelectorPopup to the screen in the middle.
Kind: instance method of FileSelectorPopup
Returns: FileSelectorPopup
- The instance of the FileSelectorPopup.
CM : ConsoleManager
the instance of ConsoleManager (singleton)
Kind: global constant
1.1.10
What's Changed
Full Changelog: 1.1.9...1.1.10
New widget: Free content popup
Fixes #21
Added new widget: CustomPopup
See the example using
npm test
and press "1"
Usage
const p = new PageBuilder(5) // Add a scroll limit so it will be scrollable with up and down
p.addRow({ text: `Example of a custom popup content!`, color: 'yellow' })
p.addRow({ text: `This is a custom popup!`, color: 'green' })
p.addRow({ text: `It can be used to show a message,`, color: 'green' })
p.addRow({ text: `or to show variables.`, color: 'green' })
p.addRow({ text: `TCP Message sent: `, color: 'green' }, { text: `${tcpCounter}`, color: 'white' })
p.addRow({ text: `Connected clients: `, color: 'green' }, { text: `${connectedClients}`, color: 'white' })
p.addRow({ text: `Mode: `, color: 'green' }, { text: `${mode}`, color: 'white' })
p.addRow({ text: `Message period: `, color: 'green' }, { text: `${period} ms`, color: 'white' })
new CustomPopup("popupCustom1", "See that values", p, 32).show()
Description
Draws a popup that allows to pass a PageBuilder class to be drawed
inside it.
Docs
Classes
- CustomPopup ⇐
EventEmitter
Constants
- CM :
ConsoleManager
the instance of ConsoleManager (singleton)
CustomPopup ⇐ EventEmitter
Kind: global class
Extends: EventEmitter
- CustomPopup ⇐
EventEmitter
- new CustomPopup(id, title, content, width, visible)
- .keyListner(str, key)
- .getContent() ⇒
PageBuilder
- .setContent(newContent) ⇒
CustomPopup
- .setWidth(newWidth) ⇒
CustomPopup
- .show() ⇒
CustomPopup
- .hide() ⇒
CustomPopup
- .isVisible() ⇒
boolean
- .manageInput() ⇒
CustomPopup
- .unManageInput() ⇒
CustomPopup
- .drawLine(line) ⇒
void
- .draw() ⇒
CustomPopup
new CustomPopup(id, title, content, width, visible)
This class is used to create a popup with a free content built- "data" when the user send custom event - the data is an object with the data and the event name
Param | Type | Description |
---|---|---|
id | string |
The id of the popup. |
title | string |
The title of the popup. |
content | PageBuilder |
The content of the popup. |
width | number |
The width of the popup. |
visible | boolean |
If the popup is visible. Default is false (make it appears using show()). |
Example
const popup = new CustomPopup("popup1", "Choose the number", selectedNumber, true).show().on("confirm", (value) => { console.log(value) }) // show the popup and wait for the user to confirm
customPopup.keyListner(str, key)
This function is used to make the ConsoleManager handle the keInside this function are defined all the keys that can be pressed and the actions to do when they are pressed.
Kind: instance method of CustomPopup
Param | Type | Description |
---|---|---|
str | string |
The string of the input. |
key | Object |
The key object. |
customPopup.getContent() ⇒ PageBuilder
This function is used to get the content of the popup.
Kind: instance method of CustomPopup
Returns: PageBuilder
- The content of the popup.
customPopup.setContent(newContent) ⇒ CustomPopup
This function is used to change the content of the popup. It also refresh the ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
Param | Type | Description |
---|---|---|
newContent | PageBuilder |
The new content of the popup. |
customPopup.setWidth(newWidth) ⇒ CustomPopup
This function is used to change the popup width. It also refresh the ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
Param | Type | Description |
---|---|---|
newWidth | number |
The new width of the popup. |
customPopup.show() ⇒ CustomPopup
This function is used to show the popup. It also register the key events and refresh the ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
customPopup.hide() ⇒ CustomPopup
This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
customPopup.isVisible() ⇒ boolean
This function is used to get the visibility of the popup.
Kind: instance method of CustomPopup
Returns: boolean
- The visibility of the popup.
customPopup.manageInput() ⇒ CustomPopup
This function is used to add the CustomPopup key listener callback to te ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
customPopup.unManageInput() ⇒ CustomPopup
This function is used to remove the CustomPopup key listener callback to te ConsoleManager.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
customPopup.drawLine(line) ⇒ void
This function is used to draw a single line of the layout to the screen. It also trim the line if it is too long.
Kind: instance method of CustomPopup
Param | Type | Description |
---|---|---|
line | Array.<object> |
the line to be drawn |
customPopup.draw() ⇒ CustomPopup
This function is used to draw the CustomPopup to the screen in the middle.
Kind: instance method of CustomPopup
Returns: CustomPopup
- The instance of the CustomPopup.
CM : ConsoleManager
the instance of ConsoleManager (singleton)
Kind: global constant
1.1.9
1.1.8
Full Changelog: 1.1.7...1.1.8
1.1.7
What's Changed
- Add PageDown and PageUp function in scrollable OptionPopup by @Elius94 in #18
- Add new widget: Confirm Popup (Yes, no) by @Elius94 in #19
Full Changelog: 1.1.6...1.1.7
Added two Widgets
ButtonPopup
Classes
- ButtonPopup ⇐
EventEmitter
Constants
- CM :
ConsoleManager
the instance of ConsoleManager (singleton)
Functions
- key)(str, key)
This function is used to make the ConsoleManager handle the key events when the popup is showed. Inside this function are defined all the keys that can be pressed and the actions to do when they are pressed.
ButtonPopup ⇐ EventEmitter
Kind: global class
Extends: EventEmitter
- ButtonPopup ⇐
EventEmitter
new ButtonPopup(id, title, message, buttons, visible)
- "exit" when the user exitncelrmpup with That asks for a confirm.
Param | Type | Description |
---|---|---|
id | string |
The id of the popup. |
title | string |
The title of the popup. |
message | string |
The message of the popup. |
buttons | Array.<string> |
The buttons of the popup (default is ["Yes", "No"]). |
visible | boolean |
If the popup is visible. Default is false (make it appears using show()). |
Example
const popup = new ButtonPopup("popup1", "Choose the option", ["YES", "NO", "?"]).show().on("confirm", (answer) => { console.log(answer) }) // show the popup and wait for the user to confirm
buttonPopup.show() ⇒ ButtonPopup
This function is used to show the popup. It also register the key events and refresh the ConsoleManager.
Kind: instance method of ButtonPopup
Returns: ButtonPopup
- The instance of the ButtonPopup.
buttonPopup.hide() ⇒ ButtonPopup
This function is used to hide the popup. It also unregister the key events and refresh the ConsoleManager.
Kind: instance method of ButtonPopup
Returns: ButtonPopup
- The instance of the ButtonPopup.
buttonPopup.isVisible() ⇒ boolean
This function is used to get the visibility of the popup.
Kind: instance method of ButtonPopup
Returns: boolean
- The visibility of the popup.
buttonPopup.manageInput() ⇒ ButtonPopup
This function is used to add the ButtonPopup key listener callback to te ConsoleManager.
Kind: instance method of ButtonPopup
Returns: ButtonPopup
- The instance of the ButtonPopup.
buttonPopup.unManageInput() ⇒ ButtonPopup
This function is used to remove the ButtonPopup key listener callback to te ConsoleManager.
Kind: instance method of ButtonPopup
Returns: ButtonPopup
- The instance of the ButtonPopup.
buttonPopup.draw() ⇒ ButtonPopup
This function is used to draw the ButtonPopup to the screen in the middle.
Kind: instance method of ButtonPopup
Returns: ButtonPopup
- The instance of the ButtonPopup.
CM : ConsoleManager
the instance of ConsoleManager (singleton)
Kind: global constant
ConfirmPopup
ConfirmPopup ⇐ ButtonPopup
Kind: global class
Extends: ButtonPopup
new ConfirmPopup(id, title, message, visible)
This class is an overload of ButtonPopup that is used to create a popup wi- "exit" when the user exitncelrmNo].
Param | Type | Description |
---|---|---|
id | string |
The id of the popup. |
title | string |
The title of the popup. |
message | string |
The message of the popup. |
visible | boolean |
If the popup is visible. Default is false (make it appears using show()). |
Example
const popup = new ConfirmPopup("popup1", "Are you shure").show().on("confirm", (answer) => { console.log(answer) }) // show the popup and wait for the user to confirm