RenderKid
RenderKid allows you to use HTML and CSS to style your CLI output, making it easy to create a beautiful, readable, and consistent look for your nodejs tool.
Installation
Install with npm:
$ npm install renderkid
Usage
= require('renderkid')
RenderKid
= new RenderKid()
r
.style({
r"ul": {
: "block"
display: "2 0 2"
margin}
"li": {
: "block"
display: "1"
marginBottom}
"key": {
: "grey"
color: "1"
marginRight}
"value": {
: "bright-white"
color}
})
= r.render("
output <ul>
<li>
<key>Name:</key>
<value>RenderKid</value>
</li>
<li>
<key>Version:</key>
<value>0.2</value>
</li>
<li>
<key>Last Update:</key>
<value>Jan 2015</value>
</li>
</ul>
")
console.log(output)

Stylesheet properties
Display mode
Elements can have a display
of either
inline
, block
, or none
:
.style({
r"div": {
: "block"
display}
"span": {
: "inline" # default
display}
"hidden": {
: "none"
display}
})
= r.render("
output <div>This will fill one or more rows.</div>
<span>These</span> <span>will</span> <span>be</span> in the same <span>line.</span>
<hidden>This won't be displayed.</hidden>
")
console.log(output)

Margin
Margins work just like they do in browsers:
.style({
r"li": {
: "block"
display
: "1"
marginTop: "2"
marginRight: "3"
marginBottom: "4"
marginLeft
# or the shorthand version:
"margin": "1 2 3 4"
},
"highlight": {
: "inline"
display: "2"
marginLeft: "2"
marginRight}
})
.render("
r<ul>
<li>Item <highlgiht>1</highlight></li>
<li>Item <highlgiht>2</highlight></li>
<li>Item <highlgiht>3</highlight></li>
</ul>
")
Padding
See margins above. Paddings work the same way, only inward.
Width and Height
Block elements can have explicit width and height:
.style({
r"box": {
: "block"
display"width": "4"
"height": "2"
}
})
.render("<box>This is a box and some of its text will be truncated.</box>") r
Colors
You can set a custom color and background color for each element:
.style({
r"error": {
: "black"
color: "red"
background}
})
List of colors currently supported are black
,
red
, green
, yellow
,
blue
, magenta
, cyan
,
white
, grey
, bright-red
,
bright-green
, bright-yellow
,
bright-blue
, bright-magenta
,
bright-cyan
, bright-white
.
Bullet points
Block elements can have bullet points on their margins. Let’s start with an example:
.style({
r"li": {
# To add bullet points to an element, first you
# should make some room for the bullet point by
# giving your element some margin to the left:
: "4",
marginLeft
# Now we can add a bullet point to our margin:
: '"-"'
bullet}
})
# The four hyphens are there for visual reference
.render("
r----
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
----
")
And here is the result:
