Welcome to the docs of 0x81/multiwindow
The docs document all the classes and functions so here are just a few usage examples
Module version 1.4.3
Installation
npm i multiwindow
(https://www.npmjs.com/package/multiwindow)
Example usage of the class:
//require the core class
const multiwindow = require("multiwindow").extended;
//create a new Instance with almost all configs on default
let main = new multiwindow([10,10], [10,10], "\x1b[36m");
//as no options are specified, it uses the default on all
//we now have 4 10*10 containers, we can get these like this
let topLeft = main.container(0, 0);
//we can call all functions on this as they are defined in the container class, like writing some text
topLeft.clearWrite("some text");
//or setting a title
topLeft.setTitle("topLeft");
//the docs contain all other functions that you can use
Example of getting some input and displaying it in a container
//same as above, we already have a main object which is an instance of the main extended class
//lets first enable the input handling
main.enableInput();
//now lets display inputted text in a container, and clear it on pressing enter
main.pipeInput(1,1);
//and lets append every new line of text to another container
main.emitter.on("line", (line) => {
main.containers(0,1).append(line)
});
Example of using the helper class with default settings to create a menu
//setup a instance of the main class
const multiwindow = require("multiwindow").extended;
let main = new multiwindow([20,100], [10], "\x1b[36m");
//we will have this container to display the menu in
let menuBar = main.container(0,0);
//lets use this container to display other things such as output, and lets set a title matching that intention
let output = main.container(0,1);
output.setTitle("Output");
//the functions for our menu, named by each option, with two options total
let menuOptions = {
"Main": {
hover: () => {
//lets display some text on hovering
output.clearWrite("Runs some function on pressing enter.")
},
run: () => {
//and the function to run on pressing enter, we'll just have it clear everything
main.clearAll();
}
},
"Exit": {
hover: () => {
//some more hover info
output.clearWrite("Exit the programm.");
},
run: () => {
//exit on pressing enter at this option
main.exit();
}
}
}
//creating the menu
//since we are leaving the options on default, we need to pass an instance as the default mode is "internal"
let mainMenu = new multiwindow.menuCore(menuOptions, {instance: menuBar});
//starting the menu
mainMenu.enable();
//it will be active until some option is selected
© 2020 Ulrich Barnstedt All Rights Reserved