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) {
* Prints something to stdout.
*
* @param String text A string to echo to stdout
* @param String style An optional style name
* @param Number pad An optional pad value
* @return Casper
*/
Casper.prototype.echo = function echo(text, style) {
var message = style ? this.colorizer.colorize(text, style) : text;
Casper.prototype.echo = function echo(text, style, pad) {
var message = style ? this.colorizer.colorize(text, style, pad) : text;
console.log(this.filter('echo.message', message) || message);
return this;
};
......
......@@ -61,9 +61,9 @@ var Colorizer = function() {
* @params String styleName
* @return String
*/
this.colorize = function colorize(text, styleName) {
this.colorize = function colorize(text, styleName, pad) {
if (styleName in styles) {
return this.format(text, styles[styleName]);
return this.format(text, styles[styleName], pad);
}
return text;
};
......@@ -75,7 +75,7 @@ var Colorizer = function() {
* @param Object style
* @return String
*/
this.format = function format(text, style) {
this.format = function format(text, style, pad) {
if (typeof style !== "object") {
return text;
}
......@@ -91,6 +91,10 @@ var Colorizer = function() {
codes.push(options[option]);
}
}
// pad
if (typeof pad === "number" && text.length < pad) {
text += new Array(pad - text.length + 1).join(' ');
}
return "\033[" + codes.join(';') + 'm' + text + "\033[0m";
};
};
......