1.0.2 • Published 6 months ago

escprint v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

escprint

A minimalist package for styling command line outputs

Usage

prnt function

  • Use <style...> to add that style to the current output style
  • Use </style...> to reset the output style and then set the style to whatever is in the tag
  • Use </> to reset the output style
  • Use a , to deliminate multiple styles

Example

import {prnt} from "escprint";

prnt(`
    This is normal 
    <cyan> this is cyan 
    <underline> this is cyan and underlined 
    </green> this is just green 
    </> this is normal again
`);

// use "," to use multiple styles

prnt(`
    <red,underline> This is red and underlined
    </italic> This is just italic 
`);

The prnt function automatically resets the command line styles after it has been called.

Importing Styles Directly

If you don't feel like using the prnt function, you can import the styles directly and use them in a console.log or other functions;

Don't forget to reset the styles after using them

import {BLUE,UNDERLINE,X,YELLOW} from "escprint"; 

// X means reset styles
console.log(`
    This is normal 
    ${BLUE} This is blue
    ${UNDERLINE} this is blue and underlined
    ${X+YELLOW} this is just yellow
    ${X}
`);

or

import readline from "readline";
import {CYAN,X} from "escprint"; 

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

const prompt = `${CYAN}What is your name? ${X}`; 

rl.question(prompt, (input) => {
    rl.close();
    resolve(input);
});

Recognized Styles

Text Decoration

StringDescription
resetreset formatting to default
boldmake text bold
dimmake text dim
blinkmake text blink
italicmake text italic
iitalic shorthand
underlineunderline text
uunderline shorthand

Color

StringDescription
blackset foreground color to black
whiteset foreground color to white
redset foreground color to red
greenset foreground color to green
yellowset foreground color to yellow
blueset foreground color to blue
magentaset foreground color to magenta
cyanset foreground color to cyan
Blackset foreground color to bright black
Whiteset foreground color to bright white
Redset foreground color to bright red
Greenset foreground color to bright green
Yellowset foreground color to bright yellow
Blueset foreground color to bright blue
Magentaset foreground color to bright magenta
Cyanset foreground color to bright cyan
bblackset background color to black
bwhiteset background color to white
bredset background color to red
bgreenset background color to green
byellowset background color to yellow
bblueset background color to blue
bmagentaset background color to magenta
bcyanset background color to cyan
bBlackset background color to bright black
bWhiteset background color to bright white
bRedset background color to bright red
bGreenset background color to bright green
bYellowset background color to bright yellow
bBlueset background color to bright blue
bMagentaset background color to bright magenta
bCyanset background color to bright cyan

Other

StringDescription
reversereverse foreground & background
hiddenhide text
strikestrikethrough text
strikethroughstrikethrough text
deletedelete character
homeset cursor to home position
requestrequest cursor position
savecursorsave cursor position
restorecursorrestore cursor position
1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago