Skip to content
Kyle Alexis Sargeant edited this page May 25, 2017 · 2 revisions

Pageant can be used as an enhanced console or as a string colorizer. Or both.

Pageant doesn't care what you use it for - or how you use it!

You can import it, rename it, override built-ins or use alongside them.

It has no dependencies other than an internal one to the system console and "plays nicely" with other code.

As a console drop-in...

Completely safe to use with existing code... just import and assign Pageant at the top of your script:-

    const Pageant = require("pageant");
    const console = new Pageant();

Then, just as you would normally:-

console.log("Hi there!!!");
console.log(123);
console.log({
    name: "Almost",
    middle: "A",
    last: "Person",
    isOnline: true
});

console.warn("Warning: Ooh 'eck, something's happenin'.");

console.error("Error: Total, complete and absolute system failure and melt-down! Exiting the building is advised.");

However, you will also find that the normal 'dumb' alias of console.debug()... isn't so dumb anymore!

console.debug("This message only shows if Pageant is in debug-mode.");

Debug-mode, as well as all of Pageant's other configuration settings can be defined - either at instantiation:-

const console = new Pageant({debug: true});

Or with the settings in fixed config file:-

const console = new Pageant({config: "./conf/pageant.json"});

Or "on-the-fly" during operation:-

console.config.debug = false;

As a string colorizer and styler...

Pageant doesn't modify JavaScript's built-in string - or any other nastiness! Instead, it colorizes text by inserting invisible unicode markers to tell the console how to color the text it's working with.

So Pageant's colored strings - are simply ordinary JavaScript strings... and will do anything an ordinary JavaScript string will do.

Ok to start coloring - first we importing and instantiating Pageant at the top of the script - and also tell it - how many colors our console supports:-

const Pageant = require("pageant");
const color = new Pageant({
    scheme: "256"
    isBrowser: false
});

Single style or color:-

console.log(color.green("I'm green!"));

console.log(color.redBg("I've a red background!"));

console.log(color.underline("This text uses underline."));

Multiple styles using CSS naming:-

console.log(color.style("I'm multi-styled!", "cornflowerblue", "orange", "italic"));

Composing styles

let composed = "I'm " + color.green("green") + " and " + color.red("red") + " together.";
console.log(composed);

let composed = `I'm ${color.green("blue")} and ${color.red("white")} together.`;
console.log(composed);

TrueColor support.

If your console supports TrueColor then Pageant also gives you access to it's full RGB range.

console.log(color.style("I'm multi-styled!", [255,255,128], [192, 0, 55], "italic"));

Object colorization

//TODO

Clone this wiki locally