This is a Node.js toolkit for quickly building nice looking command line interfaces which can respond to changing terminal sizes. It also includes the following easy to use components:
- Progress Bars
October 8, 2014 - Adding Line.contents() for fetching the contents of a line as a string.
June 2, 2014 - Fixed a crash caused by inability to locate the required trim helper in the latest version of cli-color. (And locked down the version of the cli-color dependency to stop this from ever happening again.) Also removed lodash as a dependency in favor of vanilla JS, to keep installs faster and smaller than ever.
Creates an object for buffering a group of text lines and then outputting them. When printing lines using
LineBuffer it will crop off extra width and height so that the lines will fit into a specific space.
The following options can be passed in on creation of the
x- The X location of where to draw the lines in this buffer.
y- The Y location of where the draw the lines.
width- How wide the buffer is in columns. Any lines longer than this will be cropped. You can specify either an integer value or
'console'in order to let the width of the console determine the width of the
height- How high the buffer is in rows. You can either pass in an integer value or
'console'to let the height on the console determine the height of the
scroll- Where the user is scrolled to in the buffer
height()- Return the height of the
LineBuffer, in case you specified it as
width()- Return the width of the
LineBuffer, in case you specified it as
addLine(Line)- Put a
Lineobject into the
fill()- If you don't have enough lines in the buffer this will fill the rest of the lines with empty space.
output()- Draw the
var CLI =clc = ;var Line = CLILineLineBuffer = CLILineBuffer;var outputBuffer =x: 0y: 0width: 'console'height: 'console';var message = outputBuffer;var blankLine = outputBuffer;var header = outputBuffer;var line;forvar l = 0; l < 20; l++line = outputBuffer;outputBuffer;
This chainable object can be used to generate a line of text with columns, padding, and fill. The parameter
outputBuffer can be provided to save the line of text into a
LineBuffer object for future outputting, or you can use
LineBuffer.addLine() to add a
Line object into a
Alternatively if you do not wish to make use of a
LineBuffer you can just use
Line.output() to output the
Line immediately rather than buffering it.
widthcharacters of blank space.
column(text, width, styles)- Output text within a column of the specified width. If the text is longer than
widthit will be truncated, otherwise extra padding will be added until it is
widthcharacters long. The
stylesvariable is a list of cli-color styles to apply to this column.
fill()- At the end of a line fill the rest of the columns to the right edge of the terminal with whitespace to erase any content there.
output()- Print the generated line of text to the console.
contents()- Return the contents of this line as a string.
var clui =clc =Line = cluiLine;var headers =;var line =;
Gauge(value, maxValue, gaugeWidth, dangerZone, suffix)
Draw a basic horizontal gauge to the screen.
value- The current value of the metric being displayed by this gauge
maxValue- The highest possible value of the metric being displayed
gaugeWidth- How many columns wide to draw the gauge
dangerZone- The point after which the value will be drawn in red because it is too high
suffix- A value to output after the gauge itself.
var os =clui = ;var Gauge = cluiGauge;var total = os;var free = os;var used = total - free;var human = Math + ' MB';console;
A simple command line sparkline that draws a series of values, and highlights the peak for the period. It also automatically outputs the current value and the peak value at the end of the sparkline.
values- An array of values to go into the sparkline
suffix- A suffix to use when drawing the current and max values at the end of sparkline
var Sparkline = Sparkline;var reqsPerSec = 101237129231091916181212;console;
length- The desired length of the progress bar in characters.
update(currentValue, maxValue)- Returns the progress bar min/max content to write to stdout. Allows for dynamic max values.
update(percent)- Returns the progress bar content as a percentage to write to stdout.
0.0 > value < 1.0.
var clui = ;var Progress = cluiProgress;var thisProgressBar = 20;console;// orvar thisPercentBar = 20;console;
statusText- The default status text to display while the spinner is spinning.
style- Array of graphical characters used to draw the spinner. By default, on Windows: ['|', '/', '-', ''], on other platforms: ['◜','◠','◝','◞','◡','◟']
start()- Show the spinner on the screen.
message(statusMessage)- Update the status message that follows the spinner.
stop()- Erase the spinner from the screen.
Note: The spinner is slightly different from other Clui controls in that it outputs directly to the screen, instead of just returning a string that you output yourself.
var CLI =Spinner = CLISpinner;var countdown = 'Exiting in 10 seconds... ' '⣾''⣽''⣻''⢿''⡿''⣟''⣯''⣷';countdownstart;var number = 10;;
Copyright (C) 2014 Nathan Peck (https://github.com/nathanpeck)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.