@aqo/ansi-codes
v1.0.0
Published
console text colors, move the cursor, potentially more
Downloads
6
Readme
ansi-codes
Console text colors, move the cursor, potentially more.
Usage
Whenever you use codes that alter the global terminal program state, make sure to append RESET at the end, or else it will stay in effect after you finish printing.
This might be a desirable effect, it's up to you to decide.
You don't need to reset when switching states, i.e.:
RED + 'red' + RESET + BLUE + 'blue' + RESET
is redundant, instead, do:RED + 'red' + BLUE + 'blue' + RESET
Example
const { RESET, RED, GREEN, BLUE, CURSOR_UP, SET_COLUMN } = require('../ansi-codes');
console.log(
RED + 'this text is red\n' +
GREEN + 'this text is green...\n' +
CURSOR_UP(1) + SET_COLUMN('this text is '.length + 1) + BLUE + 'blue' + RESET + '\n'
);
To find the full list of commands open the source code. It's just one file.
Why
Why not other NPM packages that do the same thing:
- because they're bloated, slow, and opinionated
- this one is minimal, fast, and provides the bare minimum, with very little opinions
Why bother coloring your text at all:
- it just looks nice.
- has practical uses if your program prints a lot of logs, helps skim critical points faster.
Why all-capital names for exports:
- to reduce the chance of collision with other names you have, and allow you to use the defaults 99% of the time.
Why is not every single ANSI code ever supported:
- there are countless ANSI codes and not all of them are very useful. Let me know if there are more that you'd like to have.
License
ISC