rex-shell

A lightweight library for Node.js that will help developers display nice, pretty, colored messages in a console window.

rex-shell

A lightweight library for Node.js that will help developers display nice, pretty, colored messages in the console.

  1. Require it
var cli = require('rex-shell');
  1. Use that sheezy like this:
cli("This will send a log message to the console");

Don't worry about whether the message is a string, object, integer, whatever. It doesn't matter at all. Any arguments you pass to rex-shell will get logged properly, no matter what. It's all about rapid development, baby!

cli("String", 42, false, ["a", 1, {foo : bar}], { baz : { bax : zap } });

Outputs

[ rex-shell: Log ] String 42 false [a, 1, {foo : bar}] { baz : { bax : zap } }

sigh Yeah, I know. Soak it up, baby. rex-shell gon' be gooood to you.

cli.log("An event happened that you shouldn't be worried about");
cli.lg("Save yourself a whole letter when calling this! You're welcome.");

Rather Important Note: As far as I can tell, most of the time people just need basic log messages. The above 3 functions will make that happen, and are identical. I just tried to get more options for people to be comfortable.

cli("Your log message here!");
cli.log("Your log message here!");
cli.lg("Your log message here!");

So yeah. Just giving you a heads up. Because I'm a nice guy like that. Anyway, carry on.

cli.warn("Something happened that wasn't an error that you should be worried about.";
cli.error("Yeah, something actually went wrong here :(");
cli.ok("This is a message telling you it is all good in the hood!");
cli.success("This is an identical message, just using the word success to make people feel better");

Note: Similar to the log() functions above, these two success functions have identical output.

cli.ok("Success message");
cli.success("Success message");

The configuration file looks a little like this

var config = {
  nameVisible : true,
  app : {
    name : "rex-shell",
    showName : true
  },
  messages : {
    log : "Log",
    error : " Error",
    success : "Success",
    warning : "Warning",
    ok : "OK"
  }
};

And HERE is how you can make this module work better for you.

Right now, all messages are prepended with rex-shell when they are displayed. If you want to set that to your own application name, and I highly recommend that you do, you can run this command:

cli.config.appName("Your App Name Here");

Which will change the output of cli.log("Your log here"); to

[ Your App Name Here: Log ] Your log here
cli.config.hideName();

Which will change the output of cli.log("Your log here"); to

[ Log ] Your log here
cli.config.showName();

Which will change the output of cli.log("Your log here"); back to

[ Your App Name Here: Log ] Your log here

Want to get crazy and change the default words that are used in console messages? Being a generous guy, I am going to let you do that as well.

cli.config.set({
  messages : {
    log : "LOGGY LOG!",
    error : "You fucked up.",
    success : "Shit went right!",
    warning : "WATCH YO ASS FOO!",
    ok : "Shit went right!"
  }
});

Now, running a basic cli.log("Your log message here"); command (assuming you already changed your application name) will output:

[ Your App Name Here: LOGGY LOG! ] Your log message here

Note: The lowercase functions are regular text, the UPPERCASE functions are the bolded versions

IMPORTANT: Unlike the standard calls, the direct $ color functions only accept a single string as an argument. No objects, no arrays, none of it. Just one single thing that you can put in the center of a string. Sorry.

cli.$.red("All this text will be red");
cli.$.MAGENTA("All this text will be bolded magenta");

Here's the full list of colors and their functions:

ColorLightBold/Bright
Redcli.$.red()cli.$.RED()
Greencli.$.green()cli.$.GREEN()
Yellocli.$.yellow()cli.$.YELLOW()
Bluecli.$.blue()cli.$.BLUE()
Magentacli.$.magenta()cli.$.MAGENTA()
Cyancli.$.cyan()cli.$.CYAN()
Whitecli.$.white()cli.$.WHITE()

All functions below assume that you have already required rex-shell as var cli = require('rex-shell');

FunctionParametersOutput ColorPurpose
cli()AnythingCyanStandard log message
cli.log()AnythingCyanStandard log message
cli.lg()AnythingCyanStandard log message
cli.okAnythingGreenSuccess message
cli.success()AnythingGreenSuccess message
cli.error()AnythingRedError message
cli.warn()AnythingYellowWarning message
cli.config.appName()String: New Name--Sets application name used in output
cli.config.set()Object: New Settings--Changes configuration object. See above!
cli.config.hideName()----Removes application name from future console output
cli.config.showName()----Shows application name in future console output
cli.$.red()String: MessageLight RedLog message without frills in one color
cli.$.RED()String: MessageBright/Bold RedLog message without frills in one color
cli.$.green()String: MessageLight GreenLog message without frills in one color
cli.$.GREEN()String: MessageBright/Bold GreenLog message without frills in one color
cli.$.yellow()String: MessageLight YellowLog message without frills in one color
cli.$.YELLOW()String: MessageBright/Bold YellowLog message without frills in one color
cli.$.blue()String: MessageLight BlueLog message without frills in one color
cli.$.BLUE()String: MessageBright/Bold BlueLog message without frills in one color
cli.$.magenta()String: MessageLight MagentaLog message without frills in one color
cli.$.MAGENTA()String: MessageBright/Bold MagentaLog message without frills in one color
cli.$.cyan()String: MessageLight CyanLog message without frills in one color
cli.$.CYAN()String: MessageBright/Bold CyanLog message without frills in one color
cli.$.white()String: MessageLight WhiteLog message without frills in one color
cli.$.WHITE()String: MessageBright/Bold WhiteLog message without frills in one color

Pierce Moore

Email : me@prex.io
Twitter : @kiapierce