GithubHelp home page GithubHelp logo

nguyenvantien2009 / cli-diagram Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lakitna/cli-diagram

0.0 0.0 0.0 1.05 MB

Draw needlessly complex diagrams in the console

Home Page: https://www.npmjs.com/package/cli-diagram

License: MIT License

JavaScript 100.00%

cli-diagram's Introduction

CLI Diagram

Draw needlessly complex diagrams in the console.

cli-diagram example

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.

cli-diagram's People

Contributors

geopic avatar lakitna avatar lakitnarabobank avatar rimian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.