simple-terminal
v1.0.7
Published
a module for rendering a simple console with user input. Useful for text games and basic text applications.
Downloads
7
Readme
API
Simple Terminal is a module aimed at allowing users to quickly begin building basic terminal applications in node such as text games or CLI utilities.
It's built to intercept and relay keypresses using the input-handler module. And is built to be an automated module. You can technically manually render but it's not recommended.
You can instantiate a terminal as follows:
// You'll only need these two lines if you want to semi-manually render the terminal.
let simpleTerminal = require('simple-terminal');
let terminal = new simpleTerminal();
// If you want this to be handled automatically you can add this line.
// By default it will rely on input-handler to intercept keypresses.
terminal.automate();
For interfacing with the terminal you have the collowing options:
// You can intercept extraneous keypresses.
terminal.on('keypress', (key) => {
terminal.print(`Key "${key.name}" was pressed`);
});
// You can intercept typed user input
terminal.on('inputSent', (query) => {
terminal.print (`User typed: "${query.input}"`)
})
// You can intercept when the terminal is ready for use.
terminal.on('ready', () => {
terminal.print('Ready!');
})
// You can push new messages to the terminal, like this
terminal.print('Hello, World!');
// You can manually force the terminal to render.
terminal.render();