Commit d2fd4491 d2fd449122f57b690f95d9d701a4aa110ac03f75 by Nicolas Perriault

added new 'pad' arg to colorizer.colorize()

1 parent 81d9342e
...@@ -353,10 +353,12 @@ Casper.prototype.each = function each(array, fn) { ...@@ -353,10 +353,12 @@ Casper.prototype.each = function each(array, fn) {
353 * Prints something to stdout. 353 * Prints something to stdout.
354 * 354 *
355 * @param String text A string to echo to stdout 355 * @param String text A string to echo to stdout
356 * @param String style An optional style name
357 * @param Number pad An optional pad value
356 * @return Casper 358 * @return Casper
357 */ 359 */
358 Casper.prototype.echo = function echo(text, style) { 360 Casper.prototype.echo = function echo(text, style, pad) {
359 var message = style ? this.colorizer.colorize(text, style) : text; 361 var message = style ? this.colorizer.colorize(text, style, pad) : text;
360 console.log(this.filter('echo.message', message) || message); 362 console.log(this.filter('echo.message', message) || message);
361 return this; 363 return this;
362 }; 364 };
......
...@@ -61,9 +61,9 @@ var Colorizer = function() { ...@@ -61,9 +61,9 @@ var Colorizer = function() {
61 * @params String styleName 61 * @params String styleName
62 * @return String 62 * @return String
63 */ 63 */
64 this.colorize = function colorize(text, styleName) { 64 this.colorize = function colorize(text, styleName, pad) {
65 if (styleName in styles) { 65 if (styleName in styles) {
66 return this.format(text, styles[styleName]); 66 return this.format(text, styles[styleName], pad);
67 } 67 }
68 return text; 68 return text;
69 }; 69 };
...@@ -75,7 +75,7 @@ var Colorizer = function() { ...@@ -75,7 +75,7 @@ var Colorizer = function() {
75 * @param Object style 75 * @param Object style
76 * @return String 76 * @return String
77 */ 77 */
78 this.format = function format(text, style) { 78 this.format = function format(text, style, pad) {
79 if (typeof style !== "object") { 79 if (typeof style !== "object") {
80 return text; 80 return text;
81 } 81 }
...@@ -91,6 +91,10 @@ var Colorizer = function() { ...@@ -91,6 +91,10 @@ var Colorizer = function() {
91 codes.push(options[option]); 91 codes.push(options[option]);
92 } 92 }
93 } 93 }
94 // pad
95 if (typeof pad === "number" && text.length < pad) {
96 text += new Array(pad - text.length + 1).join(' ');
97 }
94 return "\033[" + codes.join(';') + 'm' + text + "\033[0m"; 98 return "\033[" + codes.join(';') + 'm' + text + "\033[0m";
95 }; 99 };
96 }; 100 };
......