Skip to content

Latest commit

 

History

History
526 lines (402 loc) · 18.6 KB

ConsoleGui.md

File metadata and controls

526 lines (402 loc) · 18.6 KB

Classes

ConsoleManager ⇐ EventEmitter

Constants

Screen : Screen

The screen instance

logLocation : number | 'popup'

Choose where the logs are displayed: number (0,1) - to pot them on one of the two layouts, string ("popup") - to put them on a CustomPopup that can be displayed on the window.

stdOut : PageBuilder

The logs page

changeLayoutKey : string

The key or combination to switch the selected page

homePage : Array.<PageBuilder>

The main application

layout : LayoutManager

The layout instance

Interfaces

KeyListenerArgs : Object

This type is used to define the parameters of the KeyListener event (keypress).

ConsoleGuiOptions : Object

This type is used to define the ConsoleGui options.

KeyListenerArgs : Object

This type is used to define the parameters of the KeyListener event (keypress).

Kind: global interface
Properties

Name Type Description
name string

The name of the key pressed.

ctrl boolean

If the ctrl key is pressed.

shift boolean

If the shift key is pressed.

alt boolean

If the alt key is pressed.

meta boolean

If the meta key is pressed.

sequence boolean

If the sequence of keys is pressed.

ConsoleGuiOptions : Object

This type is used to define the ConsoleGui options.

Kind: global interface
Properties

Name Type Default Description
[title] string

The title of the ConsoleGui.

[logLocation] 0 | 1 | 2 | 3 | "popup"

The location of the logs.

[showLogKey] string

The key to show the log.

[logPageSize] number

The size of the log page.

[layoutOptions] LayoutOptions

The options of the layout.

[enableMouse] boolean

If the mouse should be enabled.

[overrideConsole] boolean true

If the console.log

[focusKey] string "&quot;tab&quot;"

The key to focus the next widget.

ConsoleManager ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new ConsoleManager(options)

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:

  • "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 Type Description
options object

The options of the ConsoleManager.

Example

const CM = new ConsoleManager({ logPageSize: 10, layoutBorder: true, changeLayoutKey: 'ctrl+l', title: 'Console Application' })

consoleManager.setLayoutOptions(options, [update])

This method is used to change the layout options. if update is true, the layout will be updated.

Kind: instance method of ConsoleManager

Param Type Default
options LayoutOptions
[update] boolean true

Example

CM.setLayoutOptions({ showTitle: true, boxed: true, boxColor: 'cyan', boxStyle: 'bold', changeFocusKey: 'ctrl+l', type: 'double', direction: 'vertical' })

Example

CM.setLayoutOptions({ ...CM.getLayoutOptions(), type: "quad" })

consoleManager.updateLayout()

This method is used to update the layout

Kind: instance method of ConsoleManager

consoleManager.getLayoutOptions() ⇒ LayoutOptions

This method is used to get the layout options.

Kind: instance method of ConsoleManager
Returns: LayoutOptions -

The layout options.


Example

CM.getLayoutOptions()

Example

CM.getLayoutOptions().boxed

consoleManager.getLogPageSize() ⇒ number

This method is used to get the log page size.

Kind: instance method of ConsoleManager
Returns: number -

The log page size.


Example

CM.getLogPageSize()

consoleManager.setLogPageSize(size) ⇒ void

This method is used to set the log page size.

Kind: instance method of ConsoleManager

Param Type Description
size number

The new log page size.

Example

CM.setLogPageSize(10)

consoleManager.unfocusOtherWidgets(widget)

This method is used to remove focus from other widgets.

Kind: instance method of ConsoleManager

Param Type
widget string

consoleManager.addGenericListeners()

This function is used to make the ConsoleManager handle the key events when no widgets are 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 ConsoleManager

consoleManager.setKeyListener(id, manageFunction)

This function is used to set a key listener for a specific widget. The event listener is stored in the eventListenersContainer object.

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the widget.

manageFunction function

The function to call when the key is pressed.

Example

CM.setKeyListener('inputPopup', popup.keyListener)

consoleManager.removeKeyListener(id)

This function is used to remove a key listener for a specific widget. The event listener is removed from the eventListenersContainer object.

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the widget.

Example

CM.removeKeyListener('inputPopup')

consoleManager.setMouseListener(id, manageFunction)

This function is used to set a mouse listener for a specific widget. The event listener is stored in the eventListenersContainer object.

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the widget.

manageFunction function

The function to call when the key is pressed.

Example

CM.setMouseListener('inputPopup', popup.mouseListener)

consoleManager.removeMouseListener(id)

This function is used to remove a mouse listener for a specific widget. The event listener is removed from the eventListenersContainer object.

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the widget.

Example

CM.removeMouseListener('inputPopup')

consoleManager.registerPopup(popup)

This function is used to register a popup. The popup is stored in the popupCollection object. That is called by the popups in show().

Kind: instance method of ConsoleManager

Param Type Description
popup popup

The popup to register.

consoleManager.unregisterPopup(id)

This function is used to unregister a popup. The popup is removed from the popupCollection object. That is called by the popups in hide().

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the popup.

consoleManager.registerControl(control)

This function is used to register a control. The control is stored in the controlCollection object. That is called by the controls in show().

Kind: instance method of ConsoleManager

Param Type Description
control control

The control to register.

consoleManager.unregisterControl(id)

This function is used to unregister a control. The control is removed from the controlCollection object. That is called by the controls in hide().

Kind: instance method of ConsoleManager

Param Type Description
id string

The id of the control.

consoleManager.setHomePage(page)

Deprecated

This function is used to set the home page. It also refresh the screen.

Kind: instance method of ConsoleManager

Param Type Description
page PageBuilder

The page to set as home page.

Example

CM.setHomePage(p)

consoleManager.setPage(page, [pageNumber], [title])

This function is used to set a page of layout. It also refresh the screen.

Kind: instance method of ConsoleManager

Param Type Default Description
page PageBuilder

The page to set as home page.

[pageNumber] number 0

The page number to set. 0 is the first page, 1 is the second page.

[title] string | null null

The title of the page to overwrite the default title. Default is null.

Example

CM.setPage(p, 0)

consoleManager.setPages(pages, [titles])

This function is used to set both pages of layout. It also refresh the screen.

Kind: instance method of ConsoleManager

Param Type Default Description
pages Array.<PageBuilder>

The page to set as home page.

[titles] Array.<string> | null

The titles of the page to overwrite the default titles. Default is null.

Example

CM.setPages([p1, p2], 0)

consoleManager.refresh()

This function is used to refresh the screen. It do the following sequence: Clear the screen, draw layout, draw widgets and finally print the screen to the stdOut.

Kind: instance method of ConsoleManager
Example

CM.refresh()

consoleManager.showLogPopup() ⇒

This function is used to show a popup containing all the stdOut of the console.

Kind: instance method of ConsoleManager
Returns:

the instance of the generated popup.


Example

CM.showLogPopup()

consoleManager.log(message)

This function is used to log a message. It is used to log messages in the log page. Don't add colors to the message.

Kind: instance method of ConsoleManager

Param Type Description
message string

The message to log.

Example

CM.log("Hello world")

consoleManager.error(message)

This function is used to log an error message. It is used to log red messages in the log page. Don't add colors to the message.

Kind: instance method of ConsoleManager

Param Type Description
message string

The message to log.

Example

CM.error("Anomaly detected")

consoleManager.warn(message)

This function is used to log a warning message. It is used to log yellow messages in the log page. Don't add colors to the message.

Kind: instance method of ConsoleManager

Param Type Description
message string

The message to log.

Example

CM.warn("Anomaly detected")

consoleManager.info(message)

This function is used to log an info message. It is used to log blue messages in the log page. Don't add colors to the message.

Kind: instance method of ConsoleManager

Param Type Description
message string

The message to log.

Example

CM.info("Anomaly detected")

consoleManager.updateLogsConsole(resetCursor)

This function is used to update the logs console. It is called by the log functions.

Kind: instance method of ConsoleManager

Param Type Description
resetCursor boolean

If true, the log scroll index is resetted.

consoleManager.overrideConsole()

This function is used to override the console.log, console.error, console.warn and console.info functions.

Kind: instance method of ConsoleManager
Since: 1.1.42
Example

CM.overrideConsole()

Example

console.log("Hello world") // Will be logged in the log page.

Example

console.error("Anomaly detected") // Will be logged in the log page.

Example

console.warn("Anomaly detected") // Will be logged in the log page.

Example

console.info("Anomaly detected") // Will be logged in the log page.

Example

console.debug("Anomaly detected") // Will be logged in the log page.

Screen : Screen

The screen instance

Kind: global constant

logLocation : number | 'popup'

Choose where the logs are displayed: number (0,1) - to pot them on one of the two layouts, string ("popup") - to put them on a CustomPopup that can be displayed on the window.

Kind: global constant

stdOut : PageBuilder

The logs page

Kind: global constant

changeLayoutKey : string

The key or combination to switch the selected page

Kind: global constant

homePage : Array.<PageBuilder>

The main application

Kind: global constant

layout : LayoutManager

The layout instance

Kind: global constant