CLI Diagram
Draw needlessly complex diagrams in the console.
Install
npm install cli-diagram
Getting started
const Diagram = require('cli-diagram');
const myDiagram = new Diagram()
.box(`Amazing`)
.line(1)
.box(`Isn't it?`);
console.log(myDiagram.draw());
βββββββββββββββ βββββββββββββββββ
β β β β
β Amazing ββββββ Isn't it? β
β β β β
βββββββββββββββ βββββββββββββββββ
More examples in this test file;
Elements
Diagrams are build from elements. There is a variety of elements available to mix and match.
Box
Draw an outlined box with some string contents. Content can be multiline. Boxes are flexible enough to contain other diagrams allowing you to create complex nested structures.
.box('Hello, box!')
.box(content, options)
βββββββββββββββββββ
β β
β Hello, box! β
β β
βββββββββββββββββββ
Options
size {integer}
: The padding of the box.
color {string}
: The color of the box including the outline and contents.
Line
Draw one or more lines to link elements. Lines spread out to take advantage of the available height.
.line(3)
.line(count, options)
ββββ
ββββ
ββββ
Labels
You can add labels to lines.
.line(['Hello, line!', null, 'Hi there'])
.line([label, label, ...])
βββ€Hello, arrow!βββ
βββββββββββββββββββ
βββ€Hi there βββ
Options
size {integer}
: The width of the lines.
color {string}
: The color of the lines.
Arrow
Draw one or more arrows to link elements. Arrows spread out to take advantage of the available height.
.arrow(['<--', '-->', '<->'])
.arrow([arrow, arrow, ...], options)
ββββ
ββββΆ
ββββΆ
Styles
There are multiple styles of arrows available. You can mix and match any of the inputs from the first two columns in the table below.
.arrow(['left', '--x', 'o-o'])
ββββ
βββX
OββO
Input text | Input symbolic | Result |
---|---|---|
'left' |
'<--' |
ββββ |
'right' |
'-->' |
ββββΆ |
'both' |
'<->' |
ββββΆ |
'broken-left' |
'x--' |
Xβββ |
'broken-right' |
'--x' |
βββX |
'broken-both' |
'x-x' |
XββX |
'round-left' |
'o--' |
Oβββ |
'round-right' |
'--o' |
βββO |
'round-both' |
'o-o' |
OββO |
Labels
You can add labels to arrows.
.arrow(['<--:Hello, arrow!', '<--', '-->:Hi there'])
.arrow([arrow, arrow, ...])
βββ€Hello, arrow!βββ
βββββββββββββββββββ
βββ€Hi there βββΆ
Options
size {integer}
: The width of the arrows.
color {string}
: The color of the arrows.
Space
Add some space between elements.
.space(2)
.space(width)
Container
A borderless box with some string contents and no padding. Content can be multiline. Containers are flexible enough to contain other diagrams allowing you to create complex nested structures.
.container('Hello, container!')
.container(content, options)
Hello, container!
Options
color {string}
: The color of the containers contents.
verticalAlign {'top'|'middle'|'bottom'}
: Vertical alignment of the string contents when there is height to spare.
.box('Vertical alignment option')
.container('Aligned to bottom', {verticalAlign: 'bottom'})
βββββββββββββββββββββββββββββ
β β
β Vertical align option β
β β
βββββββββββββββββββββββββββββAligned to bottom
Contributing
Contributors are always welcome! I don't care if you are a beginner or an expert, all help is welcome.
Testing cli-diagram
First, clone the repository and install the dependencies. Then run the test script:
npm test
Sometimes things are just that simple.