Permalink
Browse files

DRY-up test

  • Loading branch information...
1 parent 91e4459 commit d8ab9b664675b3035fdf519e07aa6f37b00caf8c @mgutz committed Jan 28, 2012
Showing with 40 additions and 35 deletions.
  1. +7 −4 README.md
  2. +1 −3 docs/colors.html
  3. +9 −6 docs/index.html
  4. +1 −3 lib/colors.js
  5. +22 −19 test/colorsTest.js
View
@@ -7,7 +7,6 @@
General usage
var color = require("mgutz-colors").color;
-
console.log(color("red on black", "red:black"));
Style format is `color+attributes:bgColor+attributes`
@@ -19,12 +18,16 @@ Style format is `color+attributes:bgColor+attributes`
"red:white" // red on white
"red+b:white+h" // red bold on white high-intensity
-More flexible way to require it
+ colors: black, white, red, yellow, green, cyan, blue, magenta
+
+ attributes: b=bold, h=high intensity, u=underline
+
+Flexible way to require
var colors = require("mgutz-colors"),
color = colors.color;
-Be lazy
+Be lazy and define color functions
var bc = colors.fn("black:cyan");
console.log(bc("this is black text on cyan"));
@@ -34,7 +37,7 @@ Turn off colors easily
colors.plain = true;
console.log(bc("this is plain now"));
-See all color combinations in your terminal
+Output all color combinations in terminal
npm test
View
@@ -40,9 +40,7 @@
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">color</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">color</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span> <span class="nx">style</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">exports</span><span class="p">.</span><span class="nx">plain</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">return</span> <span class="nx">s</span><span class="p">;</span>
- <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">exports</span><span class="p">.</span><span class="nx">plain</span><span class="p">)</span> <span class="k">return</span> <span class="nx">s</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">colors</span> <span class="o">=</span> <span class="p">{</span>
<span class="nx">black</span><span class="o">:</span> <span class="mi">0</span><span class="p">,</span>
View
@@ -7,7 +7,6 @@
<p>General usage</p>
<pre><code>var color = require("mgutz-colors").color;
-
console.log(color("red on black", "red:black"));</code></pre>
<p>Style format is <code>color+attributes:bgColor+attributes</code></p>
@@ -17,14 +16,18 @@
"red+u" // red underline
"red+bh" // red bold high-intensity
"red:white" // red on white
-"red+b:white+h" // red bold on white high-intensity</code></pre>
+"red+b:white+h" // red bold on white high-intensity
+
+colors: black, white, red, yellow, green, cyan, blue, magenta
+
+attributes: b=bold, h=high intensity, u=underline</code></pre>
-<p>More flexible way to require it</p>
+<p>Flexible way to require</p>
<pre><code>var colors = require("mgutz-colors"),
color = colors.color;</code></pre>
-<p>Be lazy</p>
+<p>Be lazy and define color functions</p>
<pre><code>var bc = colors.fn("black:cyan");
console.log(bc("this is black text on cyan"));</code></pre>
@@ -34,15 +37,15 @@
<pre><code>colors.plain = true;
console.log(bc("this is plain now"));</code></pre>
-<p>See all color combinations in your terminal</p>
+<p>Output all color combinations in terminal</p>
<pre><code>npm test</code></pre>
<h2>License</h2>
<p>(The MIT License)</p>
-<p>Copyright (c) 2012 Mario Gutierrez <a href="&#x6D;&#97;&#x69;lt&#111;:&#x6D;&#97;&#114;&#x69;&#x6F;&#64;&#x6D;g&#117;&#x74;&#122;&#46;&#x63;&#111;&#109;">&#x6D;&#97;&#114;&#x69;&#x6F;&#64;&#x6D;g&#117;&#x74;&#122;&#46;&#x63;&#111;&#109;</a></p>
+<p>Copyright (c) 2012 Mario Gutierrez <a href="&#x6D;a&#105;&#108;t&#x6F;:&#x6D;a&#x72;&#105;&#111;&#x40;&#x6D;&#x67;&#x75;&#116;&#x7A;&#x2E;&#99;&#111;&#109;">&#x6D;a&#x72;&#105;&#111;&#x40;&#x6D;&#x67;&#x75;&#116;&#x7A;&#x2E;&#99;&#111;&#109;</a></p>
<p>Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
@@ -40,9 +40,7 @@ exports.plain = false;
*
*/
var color = exports.color = function(s, style) {
- if (exports.plain) {
- return s;
- }
+ if (exports.plain) return s;
var colors = {
black: 0,
View
@@ -29,28 +29,31 @@ function padColor(s, styles) {
return buffer;
}
-
-var attr, s, s2, bg;
-for (var b = 0; b < bgColors.length; b++) {
- for (var c = 0; c < colors.length; c++) {
- fg = colors[c];
- bg = bgColors[b];
- console.log(padColor(fg, [''+bg, '+b'+bg, '+bh'+bg, '+u'+bg, '+uh'+bg]));
- console.log(padColor(fg, [''+bg+'+h', '+b'+bg+'+h', '+bh'+bg+'+h', '+u'+bg+'+h', '+uh'+bg+'+h']));
+function run() {
+ var attr, s, s2, bg;
+ for (var b = 0; b < bgColors.length; b++) {
+ for (var c = 0; c < colors.length; c++) {
+ fg = colors[c];
+ bg = bgColors[b];
+ console.log(padColor(fg, [''+bg, '+b'+bg, '+bh'+bg, '+u'+bg, '+uh'+bg]));
+ console.log(padColor(fg, [''+bg+'+h', '+b'+bg+'+h', '+bh'+bg+'+h', '+u'+bg+'+h', '+uh'+bg+'+h']));
+ }
+ // only need 1 pass to see if plain option is working
+ if (Colors.plain) return;
}
}
-Colors.plain = true;
-for (var b = 0; b < bgColors.length; b++) {
- for (var c = 0; c < colors.length; c++) {
- fg = colors[c];
- bg = bgColors[b];
- console.log(padColor(fg, [''+bg, '+b'+bg, '+bh'+bg, '+u'+bg, '+uh'+bg]));
- console.log(padColor(fg, [''+bg+'+h', '+b'+bg+'+h', '+bh'+bg+'+h', '+u'+bg+'+h', '+uh'+bg+'+h']));
- }
-}
+console.log("Color.fn");
+console.log("===============================================================================");
+var redBold = Colors.fn('red+b:white');
+console.log(redBold('testing color function, should be red bold on white'));
+console.log("\nColors.plain == true");
+console.log("===============================================================================");
+Colors.plain = true;
+run();
+console.log("\nColors");
+console.log("===============================================================================");
Colors.plain = false;
-var redBold = Colors.fn('red+b:white');
-console.log(redBold('red bold'));
+run();

0 comments on commit d8ab9b6

Please sign in to comment.