npm install cli-styler
In this example we will put cli-styler in the variable cs
.
var cs = require('cli-styler');
Clear the console screen.
cs.clearScreen('cli-styler');
Prevent wrist injuries, use the short console log.
cs.l('Hello world');
Write text to the console based on process.stdout.write
. Extra options are 'text alignment' and 'prevent new line after text'.
cs.writeText('Hello world');
cs.writeText('Hi, we are ', 'left', true) /* Set the text alignment, prevent new line after text */;
cs.write('on the same line') /* Same as writeText() */;
cs.writeText('Wow, I am centered', 'center');
cs.writeText('Looks good, right?', 'right');
Write characters in a loop to the console. Handy to write multiple spaces or line breaks. Internal used in writeText()
for positioning text. Also available as get function.
cs.writeCharacters('Loopy Loop ', 3);
cs.writeChars(' ', 5) /* Same as writeCharacters() */;
cs.write(cs.getCharacters('Whoop Loop ', 3)) /* Get character */;
cs.writeCharacters('\n', 3);
Return width and height.
cs.write('Console width : ' + cs.getConsoleWidth());
cs.write('Console height: ' + cs.getConsoleHeight());
Write a rule to the console. Choose your own character and size. By default the rule has the full width of your console and does not prevent a new line.
cs.writeRule();
cs.writeRule('.') /* Set character */;
cs.writeRule('=', 10, true) /* Set character, size and prevent new line after text */;