By SchizoDuckie
Updated By Cory Gross, xkxx Super simple CLI cursor position control to spice up your script's functionality in terminal/console windows
Updated for 0.4.*
v2.0
Free to use and modify. Report any issues you encountered.
Node.cli uses ANSI control codes to control console behavior. For details see: http://en.wikipedia.org/wiki/ANSI_escape_code
See screenshot.png for an impression of what you can do.
Enjoy!
var cli = require('./node-cli.js');
cli.clear().move(20,20).color('red').write('Node.js').down(1).back(7).color('yellow').write('Rocks!').down(10);
Try node example.js to see this in action.
Print the text to console without adding a new line after it
Example:
cli.write('We are');
cli.write('in the same line.');
Same as cli.write(), except will add a new line
Example:
cli.print('We are');
cli.print('In different lines');
Set colors and styles
Choices of Text and background colors: 'default', 'gray', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'.
Choices of Text styles: 'bold', 'underscore', 'blink', 'inverse', 'conceal', 'nobold', 'nounderscore', 'noblink', 'noinverse', 'noconceal', 'frame', 'encircle', 'overline', 'no_frame_or_circle', 'nooverline'.
Example:
cli.color('yellow', cli.bold).write('Here is some yellow text.');
If you are not satisfied with the provided text styles, it's possible to pass SGR codes directly. For example:
cli.color('green', 'default', 'bold', 4, 7); //same as cli.color('green', 'default', 'bold', 'underscore', 'inverse');
Set only the background color
Set only the text style
Reset the console to default
Reset only the text color
Reset only the background color
Reset only text styles
Move the cursor in x,y position
Move the cursor up, down, fwd or back x rows/columns
Clear the screen. If no parameter is given or x = 2, the entire screen will be cleared; x = 0, the screen above the cursor; x = 1, the screen under the cursor
Clear the line. Works similarly as cli.clear().
Clear the next n letters in the line
Save you a '\x1B['.