Skip to content

Commit

Permalink
Added "layoutratiochanged" emit on CM
Browse files Browse the repository at this point in the history
### new ConsoleManager(options)
<p>This class is used to manage the console GUI and all the widgets.
This is a singleton class, so you can use it like this: const CM = new ConsoleManager()
Emits the following events:</p>
<ul>
<li>&quot;keypressed&quot; to propagate the key pressed event to the application</li>
<li>&quot;layoutratiochanged&quot; when the layout ratio is changed</li>
<li>&quot;exit&quot; when the user wants to exit the application</li>
</ul>
  • Loading branch information
Elius94 committed Jan 10, 2023
1 parent f4d1707 commit a9c6c32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
13 changes: 1 addition & 12 deletions docs/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,4 @@
| enabled | <code>boolean</code> | <p>If the button is enabled. Default is true (make it disabled using disable()).</p> |

**Example**
```js
new Button("btnRun", "Run me!", 10, 3, 21, 18,
{
color: "magentaBright",
bold: true,
italic: true,
borderColor: "green"
},
() => {
GUI.log("Button clicked!")
})
```
```jsnew Button("btnRun", "Run me!", 10, 3, 21, 18, { color: "magentaBright", bold: true, italic: true, borderColor: "green" }, () => { GUI.log("Button clicked!") })```
Expand Down
17 changes: 9 additions & 8 deletions docs/ConsoleGui.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<dd><p>The screen instance</p></dd>
<dt><a href="#logLocation">logLocation</a> : <code>number</code> | <code>&#x27;popup&#x27;</code></dt>
<dd><p>Choose where the logs are displayed: number (0,1) - to pot them on one of the two layouts, string (&quot;popup&quot;) - to put them on a CustomPopup that can be displayed on the window.</p></dd>
<dt><a href="#stdOut">stdOut</a> : <code>PageBuilder</code></dt>
<dd><p>The logs page</p></dd>
<dt><a href="#changeLayoutKey">changeLayoutKey</a> : <code>string</code></dt>
<dd><p>The key or combination to switch the selected page</p></dd>
<dt><a href="#homePage">homePage</a> : <code>Array.&lt;PageBuilder&gt;</code></dt>
<dd><p>The main application</p></dd>
<dt><a href="#stdOut">stdOut</a> : <code>PageBuilder</code></dt>
<dd><p>The logs page</p></dd>
<dt><a href="#layout">layout</a> : <code>LayoutManager</code></dt>
<dd><p>The layout instance</p></dd>
</dl>
Expand Down Expand Up @@ -64,6 +64,7 @@ This is a singleton class, so you can use it like this: const CM = new ConsoleMa
Emits the following events:</p>
<ul>
<li>&quot;keypressed&quot; to propagate the key pressed event to the application</li>
<li>&quot;layoutratiochanged&quot; when the layout ratio is changed</li>
<li>&quot;exit&quot; when the user wants to exit the application</li>
</ul>

Expand Down Expand Up @@ -437,6 +438,12 @@ console.info("Anomaly detected") // Will be logged in the log page.
## logLocation : <code>number</code> \| <code>&#x27;popup&#x27;</code>
<p>Choose where the logs are displayed: number (0,1) - to pot them on one of the two layouts, string (&quot;popup&quot;) - to put them on a CustomPopup that can be displayed on the window.</p>

**Kind**: global constant
<a name="stdOut"></a>

## stdOut : <code>PageBuilder</code>
<p>The logs page</p>

**Kind**: global constant
<a name="changeLayoutKey"></a>

Expand All @@ -449,12 +456,6 @@ console.info("Anomaly detected") // Will be logged in the log page.
## homePage : <code>Array.&lt;PageBuilder&gt;</code>
<p>The main application</p>

**Kind**: global constant
<a name="stdOut"></a>

## stdOut : <code>PageBuilder</code>
<p>The logs page</p>

**Kind**: global constant
<a name="layout"></a>

Expand Down
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": "2.3.3",
"version": "2.4.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
4 changes: 3 additions & 1 deletion src/ConsoleGui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface ConsoleGuiOptions {
* This is a singleton class, so you can use it like this: const CM = new ConsoleManager()
* Emits the following events:
* - "keypressed" to propagate the key pressed event to the application
* - "layoutratiochanged" when the layout ratio is changed
* - "exit" when the user wants to exit the application
* @param {object} options - The options of the ConsoleManager.
* @example const CM = new ConsoleManager({ logPageSize: 10, layoutBorder: true, changeLayoutKey: 'ctrl+l', title: 'Console Application' })
Expand Down Expand Up @@ -170,7 +171,7 @@ class ConsoleManager extends EventEmitter {
/** @const {PageBuilder} stdOut - The logs page */
this.stdOut = new PageBuilder()
this.stdOut.setRowsPerPage(this.logPageSize)

this.updateLayout()
this.addGenericListeners()

Expand Down Expand Up @@ -343,6 +344,7 @@ class ConsoleManager extends EventEmitter {
this.refresh()
return
}
this.emit("layoutratiochanged", key)
}
this.emit("keypressed", key)
}
Expand Down

0 comments on commit a9c6c32

Please sign in to comment.