Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
d2fd4491
...
d2fd449122f57b690f95d9d701a4aa110ac03f75
authored
2012-01-11 12:24:52 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added new 'pad' arg to colorizer.colorize()
1 parent
81d9342e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
modules/casper.js
modules/colorizer.js
modules/casper.js
View file @
d2fd449
...
...
@@ -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
;
};
...
...
modules/colorizer.js
View file @
d2fd449
...
...
@@ -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"
;
};
};
...
...
Please
register
or
sign in
to post a comment