
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
terminal-api
Advanced tools
terminal-api is a thin layer around low-level terminal commands, providing easy access without escape codes or other dirty details.
Installation | Usage | API | Colors | Styles | License
terminal-api is a thin layer around low-level terminal commands, providing easy access without escape codes or other dirty details.
npm install --save terminal-api
const TerminalApi = require('terminal-api');
// initialize
const t = new TerminalApi();
// clear screen
t.clear();
// show/hide cursor
t.setCursor(false);
// set background/foreground color
t.setBgColor(t.colors.basic.magenta);
t.setFgColor(t.colors.rgb6(4, 5, 1));
// set styles
t.setStyles({bold: true, underline: true});
// set position
t.setPosition(10, 5);
// write
t.write('Hello world!');
// shortcut methods
t.w('Goodbye world!', {
x: 10, y: 7,
bgColor: t.colors.basic.white,
fgColor: t.colors.gray[3],
styles: ['strikethrough', 'dim'],
wrap: true
});
Also, run examples/demo.js to see a more colorful example:
node examples/demo.js
Creates terminal-api instance.
- stream: WritableStream. Default:
process.stdout- encoding: String. Default:
'utf8'
Sets stream.
- stream: WritableStream. Default:
process.stdout
Sets encoding.
- encoding: String. Default:
'utf8'
Sets multiple options at a time.
- options: Object. Possible keys:
wrap,x,y,bgColor,fgColor,cursor,styles- force: Boolean. Forces operation even if not needed. Default:
false
Enables/disables wrapping at the end of the line.
- wrap: Boolean. Default:
true
Sets cursor position.
- x: Number. Default:
0- y: Number. Default:
0- force: Boolean. Forces operation even if not needed. Default:
false
Sets cursor x position.
- x: Number. Default:
0- force: Boolean. Forces operation even if not needed. Default:
false
Sets cursor y position.
- y: Number. Default:
0- force: Boolean. Forces operation even if not needed. Default:
false
Sets background color. See Colors for more information.
- color: Number.
- force: Boolean. Forces operation even if not needed. Default:
false
Sets foreground color. See Colors for more information.
- color: Number.
- force: Boolean. Forces operation even if not needed. Default:
false
Resets background color to terminal default.
- force: Boolean. Forces operation even if not needed. Default:
false
Resets foreground color to terminal default.
- force: Boolean. Forces operation even if not needed. Default:
false
Shows/hides cursor.
- cursor: Boolean. Default:
true- force: Boolean. Forces operation even if not needed. Default:
false
Enables/disables multiple styles at once. See Styles for more information.
- styles: Object. Should be structured as {styleName: styleState}
- force: Boolean. Forces operation even if not needed. Default:
false
Enables multiple styles at once. See Styles for more information.
- styleList: Array. List of style names.
- force: Boolean. Forces operation even if not needed. Default:
false
Disables multiple styles at once. See Styles for more information.
- styleList: Array. List of style names.
- force: Boolean. Forces operation even if not needed. Default:
false
Resets terminal and instance state.
Clears terminal.
Writes text on terminal.
- text: String.
Shortcut method for changing options, writing text, and optionally reverting options back.
- text: String.
- options: Object. See
setOptionsmethod.- revert: Boolean. Whether to revert options back after writing. Default:
false- force: Boolean. Forces operation even if not needed. Default:
false
Color availability and representations might differ between systems and configurations. For maximum compatibility, only basic and bright colors should be used.
Even though there are 256 colors, it's not the usual 256 color space. On most systems, these color groups partially overlap with each other.
While terminal-api accepts only color codes, colors object provides access to color codes in a user-friendly way. It can be accessed from class or instance:
const TerminalApi = require('terminal-api');
const colors = TerminalApi.colors;
// or
const t = new TerminalApi();
const colors = t.colors;
colors object is structured as:
const colors = {
basic: { /* black, red, green, yellow, blue, magenta, cyan, white */ },
bright: { /* black, red, green, yellow, blue, magenta, cyan, white */ },
gray: [/* 0, ..., 23 */]
};
Also, it has a minimal API.
Returns color code for given rgb values of 256 colors.
- r: Number. Must be in range 0 - 5. Default:
0- g: Number. Must be in range 0 - 5. Default:
0- b: Number. Must be in range 0 - 5. Default:
0
Returns closest color code for given rgb values of 16M colors.
- r: Number. Must be in range 0 - 255. Default:
0- g: Number. Must be in range 0 - 255. Default:
0- b: Number. Must be in range 0 - 255. Default:
0
Returns closest color code for given rgb values of 16M colors.
- hex: String. Must be hexadecimal RGB code. Default:
000000
const TerminalApi = require('terminal-api');
const t = new TerminalApi();
t.setBgColor(t.colors.basic.magenta);
t.setFgColor(t.colors.rgb256Hex('#ff9900'));
Available styles: 'bold', 'dim', 'italic', 'underline', 'blink', 'inverse', 'hidden', 'strikethrough'
Style availability depends on system. For maximum compatibility, only bold, underline and reverse should be used.
FAQs
terminal-api is a thin layer around low-level terminal commands, providing easy access without escape codes or other dirty details.
We found that terminal-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.