Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Nicer defaults #48

Closed
wants to merge 2 commits into from

2 participants

@devinrhode2

Added colors.js for nicer console messages

Turned debugging off by default, can be turned back on with --debug
Made --no-restart-on exit default, can still pass in --no-restart-on error, or --keep-restarting to tell the server to continue to restart on exit.

Changed the default watch to the program.js file passed in, instead of the current directory. Perhaps we also want to include /node_modules, we'll find out either way.

These are fixes to my frustrations.

lib/supervisor.js
((6 lines not shown))
+ } else if (arg === "--no-restart-on" || arg === '-n') {
+
+ var restartArg = args.shift();
+ if (restartArg === 'exit') {
+ console.log('node-supervisor defaults to --no-restart-on exit. You can omit this option.'.yellow);
+ noRestartOn = 'exit'; //assure what was requested.
+ } else if (restartArg === 'error') {
+ noRestartOn = 'error';
+ } else {
+ console.log('Please pass either \'error\' or \'exit\' (`--no-restart-on exit` is the default though)'.red);
+ return '';
+ }
+
+ } else if (arg === "--keep-restarting" || arg === '-k') {
+ noRestartOn = null;
+ } else if (arg === "--no-restart-on-error" || arg === '-k') {

Accidentally carried over || arg === '-k', this should be deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@iangreenleaf
Collaborator

If it's not too much trouble, could you separate these into different pull requests? That way we can consider/discuss each of the ideas one at a time. Looks like you're new to git - you can use git add -p to stage only certain lines from a bunch of changes. git commit turns those staged changes into a commit, rinse and repeat.

I can tell you right now that I'll be hesitant to alter the --no-restart behavior. It would be a surprising change for anyone who's depending on supervisor to keep a process running despite occasional crashes.

And I almost certainly won't change the default --watch behavior. Most node apps split logic up amongst multiple files which are require'd by the main file. So if we aren't watching all of those, supervisor isn't much use.

@devinrhode2

I was also thinking about publishing this more basic version as a different npm, seems like that'd be easiest, no?

@iangreenleaf
Collaborator

I'm thinking that a solution to some of these problems may be to allow some sort of .supervisorconfig file, where users can store their preferred config options and have them automatically picked up by supervisor. Judging by what issues get raised, it seems like people use supervisor in 3 or 4 distinct ways, and I'm not sure that one set of defaults is ever going to satisfy everyone.

@devinrhode2

Hey did you ever do the .supervisorconfig thing? I actually just got this same idea for another cli tool.

@iangreenleaf
Collaborator

I haven't gotten around to it, but it still sounds like a good idea to me. I'd take a pull request, or else I may get to it eventually.

This was referenced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -0,0 +1 @@
+.DS_Store
View
93 README.md
@@ -9,50 +9,55 @@ clean up all the inter-module references, and without a whole new
## node-supervisor -?
- Node Supervisor is used to restart programs when they crash.
- It can also be used to restart programs when a *.js file changes.
-
- Usage:
- supervisor [options] <program>
- supervisor [options] -- <program> [args ...]
-
- Required:
- <program>
- The program to run.
-
- Options:
- -w|--watch <watchItems>
- A comma-delimited list of folders or js files to watch for changes.
- When a change to a js file occurs, reload the program
- Default is '.'
-
- -e|--extensions <extensions>
- Specific file extensions to watch in addition to defaults.
- Used when --watch option includes folders
- Default is 'node|js'
-
- -x|--exec <executable>
- The executable that runs the specified program.
- Default is 'node'
-
- -n|--no-restart-on error|exit
- Don't automatically restart the supervised program if it ends.
- Supervisor will wait for a change in the source files.
- If "error", an exit code of 0 will still restart.
- If "exit", no restart regardless of exit code.
-
- -h|--help|-?
- Display these usage instructions.
-
- -q|--quiet
- Suppress DEBUG messages
-
- Examples:
- supervisor myapp.js
- supervisor myapp.coffee
- supervisor -w scripts -e myext -x myrunner myapp
- supervisor -w lib,server.js,config.js server.js
- supervisor -- server.js -h host -p port
+ Node Supervisor is used to restart programs when they crash.
+ It can be used to restart programs when a *.js file changes.
+
+ Usage:
+ supervisor [options] <program>
+ supervisor [options] -- <program> [args ...]
+
+ Recommended:
+ supervisor server.js
+ Defaults: --no-restart-on error, watches only your <program.js> file be default.
+
+ Options:
+ --watch <list of files/folders>
+ A comma-seperated list of folders or js files to watch for changes.
+ When a change to a js file occurs, the server restarts
+ Defaults to watching your server.js file (whatever the file may be called). -w shortcut
+
+ --poll-interval <milliseconds>
+ How often to poll watched files for changes.
+ Defaults to 100 milliseconds (node default) -p shortcut
+
+ --extensions <file extensions>
+ Specific file extensions to watch in addition to defaults.
+ Used when --watch option includes folders
+ Default is 'node|js' -e shortcut
+
+ --exec <executable>
+ The executable that runs the specified program.
+ Default is 'node' -x shortcut
+
+ --no-restart-on-exit
+ Never automatically restart the server, regardless of exit code.
+ -n shortcut (don't forget exit)
+
+ --keep-restarting
+ Whenever the server dies, restart it. May result in the server infinitely restarting.
+
+ --help
+ Display these usage instructions. -h or -? shortcut
+
+ --debug
+ Show DEBUG messages. -d shortcut
+
+ Examples:
+ supervisor myapp.js
+ supervisor myapp.coffee
+ supervisor -w scripts -e myext -x myrunner myapp
+ supervisor -- server.js -h host -p port
+ supervisor -w server.js --no-restart-on error server.js
## Simple Install
View
131 lib/supervisor.js
@@ -3,20 +3,22 @@ var fs = require("fs");
var spawn = require("child_process").spawn;
var fileExtensionPattern;
var startChildProcess;
-var noRestartOn = null;
-var debug = true;
+var noRestartOn = 'exit';
+var debug = false;
+
+require("colors");
exports.run = run;
function run (args) {
var arg, next, watch, program, programArgs, extensions, executor, poll_interval;
while (arg = args.shift()) {
- if (arg === "--help" || arg === "-h" || arg === "-?") {
+ if (arg === "--help" || arg === "-h" || arg === "-?" || arg === '-help') {
return help();
+ } else if (arg === "--debug" || arg === "-d") {
+ debug = true;
} else if (arg === "--quiet" || arg === "-q") {
- debug = false;
- util.debug = function(){};
- util.puts = function(){};
+ debug = false; //assure debugging off. This arg basically doesn't do anything.
} else if (arg === "--watch" || arg === "-w") {
watch = args.shift();
} else if (arg === "--poll-interval" || arg === "-p") {
@@ -25,8 +27,23 @@ function run (args) {
extensions = args.shift();
} else if (arg === "--exec" || arg === "-x") {
executor = args.shift();
- } else if (arg === "--no-restart-on" || arg === "-n") {
- noRestartOn = args.shift();
+ } else if (arg === "--no-restart-on" || arg === '-n') {
+
+ var restartArg = args.shift();
+ if (restartArg === 'exit') {
+ console.log('node-supervisor defaults to --no-restart-on exit. You can omit this option.'.yellow);
+ noRestartOn = 'exit'; //assure what was requested.
+ } else if (restartArg === 'error') {
+ noRestartOn = 'error';
+ } else {
+ console.log('Please pass either \'error\' or \'exit\' (`--no-restart-on exit` is the default though)'.red);
+ return '';
+ }
+
+ } else if (arg === "--keep-restarting" || arg === '-k') {
+ noRestartOn = null;
+ } else if (arg === "--no-restart-on-error") {
+ noRestartOn = 'error';
} else if (arg === "--") {
// Remaining args are: program [args, ...]
program = args.shift();
@@ -37,11 +54,12 @@ function run (args) {
program = arg;
}
}
+
if (!program) {
return help();
}
if (!watch) {
- watch = ".";
+ watch = program;
}
if (!poll_interval) {
poll_interval = 100;
@@ -63,13 +81,14 @@ function run (args) {
executor = (programExt === "coffee") ? "coffee" : "node";
}
- util.puts("")
- util.debug("Running node-supervisor with");
- util.debug(" program '" + program + "'");
- util.debug(" --watch '" + watch + "'");
- util.debug(" --extensions '" + extensions + "'");
- util.debug(" --exec '" + executor + "'");
- util.puts("");
+ if (debug) {
+ util.puts("");
+ util.puts(" program '" + program + "'");
+ util.puts(" --watch '" + watch + "'");
+ util.puts(" --extensions '" + extensions + "'");
+ util.puts(" --exec '" + executor + "'");
+ util.puts("");
+ }
// store the call to startProgramm in startChildProcess
// in order to call it later
@@ -81,15 +100,16 @@ function run (args) {
var watchItems = watch.split(',');
watchItems.forEach(function (watchItem) {
+ util.puts("Watching " + watchItem + " for changes.");
if (!watchItem.match(/^\/.*/)) { // watch is not an absolute path
// convert watch item to absolute path
watchItem = process.cwd() + '/' + watchItem;
}
- util.debug("Watching directory '" + watchItem + "' for changes.");
findAllWatchFiles(watchItem, function(f) {
watchGivenFile( f, poll_interval );
});
});
+ util.puts("Node will restart on any changes.".green);
};
function print (m, n) { util.print(m+(!n?"\n":"")); return print; }
@@ -98,68 +118,79 @@ function help () {
print
("")
("Node Supervisor is used to restart programs when they crash.")
- ("It can also be used to restart programs when a *.js file changes.")
+ ("It can be used to restart programs when a *.js file changes.")
("")
("Usage:")
(" supervisor [options] <program>")
(" supervisor [options] -- <program> [args ...]")
("")
- ("Required:")
- (" <program>")
- (" The program to run.")
+ ("Recommended usage:".green.underline)
+ (" supervisor server.js".green.bold)
+ (" Defaults: --no-restart-on exit, watches only your <program.js>.")
("")
("Options:")
- (" -w|--watch <watchItems>")
- (" A comma-delimited list of folders or js files to watch for changes.")
- (" When a change to a js file occurs, reload the program")
- (" Default is '.'")
+ (" --watch <list of files/folders>")
+ (" A comma-seperated list of folders or js files to watch for changes.")
+ (" When a change to a js file occurs, the server restarts")
+ (" Defaults to watching your server.js file (whatever the file may be called). -w shortcut")
("")
- (" -p|--poll-interval <milliseconds>")
+ (" --poll-interval <milliseconds>")
(" How often to poll watched files for changes.")
- (" Defaults to Node default.")
+ (" Defaults to 100 milliseconds (node default) -p shortcut")
("")
- (" -e|--extensions <extensions>")
+ (" --extensions <file extensions>")
(" Specific file extensions to watch in addition to defaults.")
(" Used when --watch option includes folders")
- (" Default is 'node|js'")
+ (" Default is 'node|js' -e shortcut")
("")
- (" -x|--exec <executable>")
+ (" --exec <executable>")
(" The executable that runs the specified program.")
- (" Default is 'node'")
+ (" Default is 'node' -x shortcut")
+ ("")
+ (" --no-restart-on-exit")
+ (" Never automatically restart the server, regardless of exit code.")
+ (" -n shortcut (don't forget exit)")
("")
- (" -n|--no-restart-on error|exit")
- (" Don't automatically restart the supervised program if it ends.")
- (" Supervisor will wait for a change in the source files.")
- (" If \"error\", an exit code of 0 will still restart.")
- (" If \"exit\", no restart regardless of exit code.")
+ (" --keep-restarting")
+ (" Whenever the server dies, restart it. May result in the server infinitely restarting.")
("")
- (" -h|--help|-?")
- (" Display these usage instructions.")
+ (" --help")
+ (" Display these usage instructions. -h or -? shortcut")
("")
- (" -q|--quiet")
- (" Suppress DEBUG messages")
+ (" --debug")
+ (" Show DEBUG messages. -d shortcut")
("")
("Examples:")
- (" supervisor myapp.js")
+ (" supervisor myapp.js".green)
(" supervisor myapp.coffee")
(" supervisor -w scripts -e myext -x myrunner myapp")
(" supervisor -- server.js -h host -p port")
+ (" supervisor -w server.js --no-restart-on error server.js")
("");
};
function startProgram (prog, exec, args) {
- if (args)
- util.debug("Starting child process with '" + exec + " " + prog + " " + args + "'");
- else
- util.debug("Starting child process with '" + exec + " " + prog + "'");
+
+ if (debug) {
+ if (args)
+ util.puts("Starting child process with '" + exec + " " + prog + " " + args + "'");
+ else
+ util.puts("Starting child process with '" + exec + " " + prog + "'");
+ }
+
var spawnme = args ? [prog].concat(args) : [prog];
crash_queued = false;
var child = exports.child = spawn(exec, spawnme);
- child.stdout.addListener("data", function (chunk) { chunk && util.print(chunk); });
- child.stderr.addListener("data", function (chunk) { chunk && util.debug(chunk); });
+ child.stdout.addListener("data", function (chunk) {
+ chunk && util.print(chunk);
+ });
+ child.stderr.addListener("data", function (chunk) {
+ chunk && util.puts(chunk);
+ });
child.addListener("exit", function (code) {
if (!crash_queued) {
- util.debug("Program " + prog + " exited with code " + code + "\n");
+ util.puts(prog + " exited with code " + code);
+ util.puts("Try fixing the problem, save, and see if this error reoccurs\n".yellow);
exports.child = null;
if (noRestartOn == "exit" || noRestartOn == "error" && code !== 0) return;
}
@@ -177,10 +208,10 @@ function crash () {
var child = exports.child;
setTimeout(function() {
if (child) {
- util.debug("crashing child");
+ util.puts("crashing child");
process.kill(child.pid);
} else {
- util.debug("restarting child");
+ util.puts("restarting child");
startChildProcess();
}
}, 50);
View
22 node_modules/colors/MIT-LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2010
+
+Marak Squires
+Alexis Sellier (cloudhead)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
77 node_modules/colors/ReadMe.md
@@ -0,0 +1,77 @@
+# colors.js - get color and style in your node.js console ( and browser ) like what
+
+<img src="http://i.imgur.com/goJdO.png" border = "0"/>
+
+
+## Installation
+
+ npm install colors
+
+## colors and styles!
+
+- bold
+- italic
+- underline
+- inverse
+- yellow
+- cyan
+- white
+- magenta
+- green
+- red
+- grey
+- blue
+- rainbow
+- zebra
+- random
+
+## Usage
+
+``` js
+var colors = require('./colors');
+
+console.log('hello'.green); // outputs green text
+console.log('i like cake and pies'.underline.red) // outputs red underlined text
+console.log('inverse the color'.inverse); // inverses the color
+console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
+```
+
+# Creating Custom themes
+
+```js
+
+var require('colors');
+
+colors.setTheme({
+ silly: 'rainbow',
+ input: 'grey',
+ verbose: 'cyan',
+ prompt: 'grey',
+ info: 'green',
+ data: 'grey',
+ help: 'cyan',
+ warn: 'yellow',
+ debug: 'blue',
+ error: 'red'
+});
+
+// outputs red text
+console.log("this is an error".error);
+
+// outputs yellow text
+console.log("this is a warning".warn);
+```
+
+
+### Contributors
+
+Marak (Marak Squires)
+Alexis Sellier (cloudhead)
+mmalecki (Maciej Małecki)
+nicoreed (Nico Reed)
+morganrallen (Morgan Allen)
+JustinCampbell (Justin Campbell)
+ded (Dustin Diaz)
+
+
+#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)
View
269 node_modules/colors/colors.js
@@ -0,0 +1,269 @@
+/*
+colors.js
+
+Copyright (c) 2010
+
+Marak Squires
+Alexis Sellier (cloudhead)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+*/
+
+var isHeadless = false;
+
+if (typeof module !== 'undefined') {
+ isHeadless = true;
+}
+
+if (!isHeadless) {
+ var exports = {};
+ var module = {};
+ var colors = exports;
+ exports.mode = "browser";
+} else {
+ exports.mode = "console";
+}
+
+//
+// Prototypes the string object to have additional method calls that add terminal colors
+//
+var addProperty = function (color, func) {
+ var allowOverride = ['bold'];
+ exports[color] = function(str) {
+ return func.apply(str);
+ };
+ String.prototype.__defineGetter__(color, func);
+}
+
+//
+// Iterate through all default styles and colors
+//
+
+var x = ['bold', 'underline', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
+x.forEach(function (style) {
+
+ // __defineGetter__ at the least works in more browsers
+ // http://robertnyman.com/javascript/javascript-getters-setters.html
+ // Object.defineProperty only works in Chrome
+ addProperty(style, function () {
+ return stylize(this, style);
+ });
+});
+
+function sequencer(map) {
+ return function () {
+ if (!isHeadless) {
+ return this.replace(/( )/, '$1');
+ }
+ var exploded = this.split("");
+ var i = 0;
+ exploded = exploded.map(map);
+ return exploded.join("");
+ }
+}
+
+var rainbowMap = (function () {
+ var rainbowColors = ['red','yellow','green','blue','magenta']; //RoY G BiV
+ return function (letter, i, exploded) {
+ if (letter == " ") {
+ return letter;
+ } else {
+ return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
+ }
+ }
+})();
+
+exports.addSequencer = function (name, map) {
+ addProperty(name, sequencer(map));
+}
+
+exports.addSequencer('rainbow', rainbowMap);
+exports.addSequencer('zebra', function (letter, i, exploded) {
+ return i % 2 === 0 ? letter : letter.inverse;
+});
+
+exports.setTheme = function (theme) {
+ Object.keys(theme).forEach(function(prop){
+ addProperty(prop, function(){
+ return exports[theme[prop]](this);
+ });
+ });
+}
+
+function stylize(str, style) {
+
+ if (exports.mode == 'console') {
+ var styles = {
+ //styles
+ 'bold' : ['\033[1m', '\033[22m'],
+ 'italic' : ['\033[3m', '\033[23m'],
+ 'underline' : ['\033[4m', '\033[24m'],
+ 'inverse' : ['\033[7m', '\033[27m'],
+ //grayscale
+ 'white' : ['\033[37m', '\033[39m'],
+ 'grey' : ['\033[90m', '\033[39m'],
+ 'black' : ['\033[30m', '\033[39m'],
+ //colors
+ 'blue' : ['\033[34m', '\033[39m'],
+ 'cyan' : ['\033[36m', '\033[39m'],
+ 'green' : ['\033[32m', '\033[39m'],
+ 'magenta' : ['\033[35m', '\033[39m'],
+ 'red' : ['\033[31m', '\033[39m'],
+ 'yellow' : ['\033[33m', '\033[39m']
+ };
+ } else if (exports.mode == 'browser') {
+ var styles = {
+ //styles
+ 'bold' : ['<b>', '</b>'],
+ 'italic' : ['<i>', '</i>'],
+ 'underline' : ['<u>', '</u>'],
+ 'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
+ //grayscale
+ 'white' : ['<span style="color:white;">', '</span>'],
+ 'grey' : ['<span style="color:grey;">', '</span>'],
+ 'black' : ['<span style="color:black;">', '</span>'],
+ //colors
+ 'blue' : ['<span style="color:blue;">', '</span>'],
+ 'cyan' : ['<span style="color:cyan;">', '</span>'],
+ 'green' : ['<span style="color:green;">', '</span>'],
+ 'magenta' : ['<span style="color:magenta;">', '</span>'],
+ 'red' : ['<span style="color:red;">', '</span>'],
+ 'yellow' : ['<span style="color:yellow;">', '</span>']
+ };
+ } else if (exports.mode == 'none') {
+ return str;
+ } else {
+ console.log('unsupported mode, try "browser", "console" or "none"');
+ }
+ return styles[style][0] + str + styles[style][1];
+};
+
+// don't summon zalgo
+addProperty('zalgo', function () {
+ return zalgo(this);
+});
+
+// please no
+function zalgo(text, options) {
+ var soul = {
+ "up" : [
+ '̍','̎','̄','̅',
+ '̿','̑','̆','̐',
+ '͒','͗','͑','̇',
+ '̈','̊','͂','̓',
+ '̈','͊','͋','͌',
+ '̃','̂','̌','͐',
+ '̀','́','̋','̏',
+ '̒','̓','̔','̽',
+ '̉','ͣ','ͤ','ͥ',
+ 'ͦ','ͧ','ͨ','ͩ',
+ 'ͪ','ͫ','ͬ','ͭ',
+ 'ͮ','ͯ','̾','͛',
+ '͆','̚'
+ ],
+ "down" : [
+ '̖','̗','̘','̙',
+ '̜','̝','̞','̟',
+ '̠','̤','̥','̦',
+ '̩','̪','̫','̬',
+ '̭','̮','̯','̰',
+ '̱','̲','̳','̹',
+ '̺','̻','̼','ͅ',
+ '͇','͈','͉','͍',
+ '͎','͓','͔','͕',
+ '͖','͙','͚','̣'
+ ],
+ "mid" : [
+ '̕','̛','̀','́',
+ '͘','̡','̢','̧',
+ '̨','̴','̵','̶',
+ '͜','͝','͞',
+ '͟','͠','͢','̸',
+ '̷','͡',' ҉'
+ ]
+ },
+ all = [].concat(soul.up, soul.down, soul.mid),
+ zalgo = {};
+
+ function randomNumber(range) {
+ r = Math.floor(Math.random()*range);
+ return r;
+ };
+
+ function is_char(character) {
+ var bool = false;
+ all.filter(function(i){
+ bool = (i == character);
+ });
+ return bool;
+ }
+
+ function heComes(text, options){
+ result = '';
+ options = options || {};
+ options["up"] = options["up"] || true;
+ options["mid"] = options["mid"] || true;
+ options["down"] = options["down"] || true;
+ options["size"] = options["size"] || "maxi";
+ var counts;
+ text = text.split('');
+ for(var l in text){
+ if(is_char(l)) { continue; }
+ result = result + text[l];
+
+ counts = {"up" : 0, "down" : 0, "mid" : 0};
+
+ switch(options.size) {
+ case 'mini':
+ counts.up = randomNumber(8);
+ counts.min= randomNumber(2);
+ counts.down = randomNumber(8);
+ break;
+ case 'maxi':
+ counts.up = randomNumber(16) + 3;
+ counts.min = randomNumber(4) + 1;
+ counts.down = randomNumber(64) + 3;
+ break;
+ default:
+ counts.up = randomNumber(8) + 1;
+ counts.mid = randomNumber(6) / 2;
+ counts.down= randomNumber(8) + 1;
+ break;
+ }
+
+ var arr = ["up", "mid", "down"];
+ for(var d in arr){
+ var index = arr[d];
+ for (var i = 0 ; i <= counts[index]; i++)
+ {
+ if(options[index]) {
+ result = result + soul[index][randomNumber(soul[index].length)];
+ }
+ }
+ }
+ }
+ return result;
+ };
+ return heComes(text);
+}
+
+addProperty('stripColors', function() {
+ return ("" + this).replace(/\u001b\[\d+m/g,'');
+});
View
74 node_modules/colors/example.html
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML>
+<html lang="en-us">
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>Colors Example</title>
+ <script src="colors.js"></script>
+ </head>
+ <body>
+ <script>
+
+ var test = colors.red("hopefully colorless output");
+
+ document.write('Rainbows are fun!'.rainbow + '<br/>');
+ document.write('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
+ document.write('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
+ //document.write('zalgo time!'.zalgo);
+ document.write(test.stripColors);
+ document.write("a".grey + " b".black);
+
+ document.write("Zebras are so fun!".zebra);
+
+ document.write(colors.rainbow('Rainbows are fun!'));
+ document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
+ document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
+ //document.write(colors.zalgo('zalgo time!'));
+ document.write(colors.stripColors(test));
+ document.write(colors.grey("a") + colors.black(" b"));
+
+ colors.addSequencer("america", function(letter, i, exploded) {
+ if(letter === " ") return letter;
+ switch(i%3) {
+ case 0: return letter.red;
+ case 1: return letter.white;
+ case 2: return letter.blue;
+ }
+ });
+
+ colors.addSequencer("random", (function() {
+ var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
+
+ return function(letter, i, exploded) {
+ return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
+ };
+ })());
+
+ document.write("AMERICA! F--K YEAH!".america);
+ document.write("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
+
+ //
+ // Custom themes
+ //
+
+ colors.setTheme({
+ silly: 'rainbow',
+ input: 'grey',
+ verbose: 'cyan',
+ prompt: 'grey',
+ info: 'green',
+ data: 'grey',
+ help: 'cyan',
+ warn: 'yellow',
+ debug: 'blue',
+ error: 'red'
+ });
+
+ // outputs red text
+ document.write("this is an error".error);
+
+ // outputs yellow text
+ document.write("this is a warning".warn);
+
+ </script>
+ </body>
+</html>
View
65 node_modules/colors/example.js
@@ -0,0 +1,65 @@
+var colors = require('./colors');
+
+//colors.mode = "browser";
+
+var test = colors.red("hopefully colorless output");
+console.log('Rainbows are fun!'.rainbow);
+console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
+console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
+//console.log('zalgo time!'.zalgo);
+console.log(test.stripColors);
+console.log("a".grey + " b".black);
+
+console.log("Zebras are so fun!".zebra);
+
+console.log(colors.rainbow('Rainbows are fun!'));
+console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
+console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
+//console.log(colors.zalgo('zalgo time!'));
+console.log(colors.stripColors(test));
+console.log(colors.grey("a") + colors.black(" b"));
+
+colors.addSequencer("america", function(letter, i, exploded) {
+ if(letter === " ") return letter;
+ switch(i%3) {
+ case 0: return letter.red;
+ case 1: return letter.white;
+ case 2: return letter.blue;
+ }
+});
+
+colors.addSequencer("random", (function() {
+ var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
+
+ return function(letter, i, exploded) {
+ return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
+ };
+})());
+
+console.log("AMERICA! F--K YEAH!".america);
+console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
+
+//
+// Custom themes
+//
+
+colors.setTheme({
+ silly: 'rainbow',
+ input: 'grey',
+ verbose: 'cyan',
+ prompt: 'grey',
+ info: 'green',
+ data: 'grey',
+ help: 'cyan',
+ warn: 'yellow',
+ debug: 'blue',
+ error: 'red'
+});
+
+// outputs red text
+console.log("this is an error".error);
+
+// outputs yellow text
+console.log("this is a warning".warn);
+
+
View
29 node_modules/colors/package.json
@@ -0,0 +1,29 @@
+{
+ "name": "colors",
+ "description": "get colors in your node.js console like what",
+ "version": "0.6.0-1",
+ "author": {
+ "name": "Marak Squires"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Marak/colors.js.git"
+ },
+ "engines": {
+ "node": ">=0.1.90"
+ },
+ "main": "colors",
+ "_npmUser": {
+ "name": "devinrhode2",
+ "email": "devinrhode2@gmail.com"
+ },
+ "_id": "colors@0.6.0-1",
+ "dependencies": {},
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "_engineSupported": true,
+ "_npmVersion": "1.1.4",
+ "_nodeVersion": "v0.6.12",
+ "_defaultsLoaded": true,
+ "_from": "colors"
+}
View
65 node_modules/colors/test.js
@@ -0,0 +1,65 @@
+var assert = require('assert'),
+ colors = require('./colors');
+
+//
+// This is a pretty nice example on how tests shouldn't be written. However,
+// it's more about API stability than about really testing it (although it's
+// a pretty complete test suite).
+//
+
+var s = 'string';
+
+function a(s, code) {
+ return '\033[' + code.toString() + 'm' + s + '\033[39m';
+}
+
+function aE(s, color, code) {
+ assert.equal(s[color], a(s, code));
+ assert.equal(colors[color](s), a(s, code));
+ assert.equal(s[color], colors[color](s));
+ assert.equal(s[color].stripColors, s);
+ assert.equal(s[color].stripColors, colors.stripColors(s));
+}
+
+function h(s, color) {
+ return '<span style="color:' + color + ';">' + s + '</span>';
+ // that's pretty dumb approach to testing it
+}
+
+var stylesColors = ['white', 'grey', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
+var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
+
+colors.mode = 'console';
+assert.equal(s.bold, '\033[1m' + s + '\033[22m');
+assert.equal(s.italic, '\033[3m' + s + '\033[23m');
+assert.equal(s.underline, '\033[4m' + s + '\033[24m');
+assert.equal(s.inverse, '\033[7m' + s + '\033[27m');
+assert.ok(s.rainbow);
+aE(s, 'white', 37);
+aE(s, 'grey', 90);
+aE(s, 'black', 30);
+aE(s, 'blue', 34);
+aE(s, 'cyan', 36);
+aE(s, 'green', 32);
+aE(s, 'magenta', 35);
+aE(s, 'red', 31);
+aE(s, 'yellow', 33);
+assert.equal(s, 'string');
+
+colors.mode = 'browser';
+assert.equal(s.bold, '<b>' + s + '</b>');
+assert.equal(s.italic, '<i>' + s + '</i>');
+assert.equal(s.underline, '<u>' + s + '</u>');
+assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
+assert.ok(s.rainbow);
+stylesColors.forEach(function (color) {
+ assert.equal(s[color], h(s, color));
+ assert.equal(colors[color](s), h(s, color));
+});
+
+colors.mode = 'none';
+stylesAll.forEach(function (style) {
+ assert.equal(s[style], s);
+ assert.equal(colors[style](s), s);
+});
+
Something went wrong with that request. Please try again.