console-term
v1.0.3
Published
Terminal control extensions to Node's default console class
Maintainers
Readme
Console Terminal Extensions
Alternate terminal object to replace Node's default console. Adds colors, styles, cursor control, and clearing support.
To Install
npm i --save console-termUsage
If you only want to use it like the global console, it works the same way so it's a drop-in replacement.
const terminal = require('console-term');
terminal.log('Hello, world!');You can also create instances of it tied to streams (it defaults to process.stdout and process.stderr), like this:
const { ConsoleTerminal } = require('console-term'),
fs = require('fs'),
terminal = new ConsoleTerminal(fs.createWriteStream('out.log'), fs.createWriteStream('err.log'));Keep in mind that any operation that prints an escape sequence will continue to do so regardless of what stream is attached. You can chain functions together like this:
const terminal = require('console-term');
terminal.clear()
.setColor('red')
.setStyle('bold')
.log('This is a message in red printed using console.log!')
.log('This is another log message chained to it!')
.resetStyle();Functions
All the standard Console functions are available as well as the ones documented below.
Clearing
clear(): Clears the entire screen and puts the cursor at 0,0clearLine(): Clears the current line and puts the cursor at the first columnclearUp(): Clears lines above the current lineclearDown(): Clears lines below the current lineclearRight(): Clears the current line right of the cursorclearLeft(): Clears the current line left of the cursor
Styling
resetStyle(): Resets the current formatting, colors, etc.setColor(color): Sets the current foreground color, see Colors belowsetBackgroundColor(color): Sets the current background colorsetStyle(style): Sets the current display style, see Styles
Cursor
setCursorPos(x, y): Sets the current cursor position from top-leftmoveCursor(c, direction): Moves the cursor the specified spaces in the specified direction, see DirectionsmoveCursorUp(c): Moves the cursor up the specified number of linesmoveCursorDown(c): Moves the cursor down the specified number of linesmoveCursorLeft(c): Moves the cursor left the specified number of columnsmoveCursorRight(c): Moves the cursor right the specified number of columns
Printing
print(str): Prints a string (no added newline)printHuge(str): Prints a string double height (newline added)printWide(str): Prints a string double width
Meta
sendEscape(str): Prints the\033escape sequence followed by the specified stringsetEnableEscapes(allow): Sets whether to allow escape sequences to be printed (disabling this disables everything butprint)enableEscapes(): Same assetEnableEscapes(true)disableEscapes(): Same assetEnableEscapes(false)
Reference
Below are reference lists for colors, styles, etc.
Colors
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray (or grey, only supported for foreground colors)
Styles
- bold
- dim
- italic
- underline
- inverted
- invisible
- strikethrough
Directions
- up
- down
- left
- right
