cliui
Advanced tools
Comparing version 1.3.0 to 1.4.0
21
index.js
@@ -61,12 +61,8 @@ var wrap = require('wordwrap'), | ||
if (_this.wrap) { | ||
for (var i = 0; i < wrapWidth; i++) { | ||
ts += col.charAt(i) || ' ' | ||
} | ||
} else { | ||
ts += col | ||
for (var i = 0; i < Math.max(wrapWidth, col.length); i++) { | ||
ts += col.charAt(i) || ' ' | ||
} | ||
// align the string within its column. | ||
if (row[c].align && row[c].align !== 'left') { | ||
if (row[c].align && row[c].align !== 'left' && _this.wrap) { | ||
ts = align[row[c].align](ts.trim() + '\n' + new Array(wrapWidth + 1).join(' ')) | ||
@@ -82,2 +78,5 @@ .split('\n')[0] | ||
}) | ||
// remove trailing whitespace. | ||
str = str.replace(/ +$/, '') | ||
}) | ||
@@ -105,3 +104,3 @@ | ||
// add top and bottom padding. | ||
if (col.padding && _this.wrap) { | ||
if (col.padding) { | ||
for (i = 0; i < (col.padding[top] || 0); i++) wrapped.unshift('') | ||
@@ -131,3 +130,4 @@ for (i = 0; i < (col.padding[bottom] || 0); i++) wrapped.push('') | ||
UI.prototype._columnWidths = function (row) { | ||
var widths = [], | ||
var _this = this, | ||
widths = [], | ||
unset = row.length, | ||
@@ -151,3 +151,4 @@ unsetWidth, | ||
widths.forEach(function (w, i) { | ||
if (w === undefined) widths[i] = Math.max(unsetWidth, _minWidth(row[i])) | ||
if (!_this.wrap) widths[i] = row[i].width || row[i].text.length | ||
else if (w === undefined) widths[i] = Math.max(unsetWidth, _minWidth(row[i])) | ||
}) | ||
@@ -154,0 +155,0 @@ |
{ | ||
"name": "cliui", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "easily create complex multi-column command-line-interfaces", | ||
@@ -37,3 +37,6 @@ "main": "index.js", | ||
"layout", | ||
"design" | ||
"design", | ||
"console", | ||
"wrap", | ||
"table" | ||
], | ||
@@ -50,3 +53,5 @@ "author": "Ben Coe <ben@npmjs.com>", | ||
"chai": "^2.2.0", | ||
"coveralls": "^2.11.2", | ||
"mocha": "^2.2.4", | ||
"mocha-lcov-reporter": "0.0.2", | ||
"mocoverage": "^1.0.0", | ||
@@ -53,0 +58,0 @@ "patched-blanket": "^1.0.1", |
# cliui | ||
[![Build Status](https://travis-ci.org/bcoe/cliui.png)](https://travis-ci.org/bcoe/cliui) | ||
[![Coverage Status](https://coveralls.io/repos/bcoe/cliui/badge.svg?branch=)](https://coveralls.io/r/bcoe/cliui?branch=) | ||
[![NPM version](https://img.shields.io/npm/v/cliui.svg)](https://www.npmjs.com/package/cliui) | ||
easily create complex multi-column command-line-interfaces. | ||
## Example | ||
```js | ||
@@ -35,1 +41,25 @@ var ui = require('cliui')({ | ||
``` | ||
## Methods | ||
```js | ||
cliui = require('cliui') | ||
``` | ||
### cliui({width: integer}) | ||
Specify the maximum width of the UI being generated. | ||
### cliui({wrap: boolean}) | ||
Enable or disable the wrapping of text in a column. | ||
### cliui.row(column, column, column) | ||
Create a row with any number of columns, a column | ||
can either be a string, or an object with the following | ||
options: | ||
* **width:** the width of a column. | ||
* **align:** alignment, `right` or `center`. | ||
* **padding:** `[top, right, bottom, left]`. |
@@ -41,6 +41,6 @@ /* global describe, it */ | ||
'i am a string i am a i am a third', | ||
'that should be second string that ', | ||
'wrapped string that should be ', | ||
' should be wrapped ', | ||
' wrapped ' | ||
'that should be second string that', | ||
'wrapped string that should be', | ||
' should be wrapped', | ||
' wrapped' | ||
] | ||
@@ -123,6 +123,6 @@ | ||
var expected = [ | ||
'i am a stringi am a secondi am a third ', | ||
' stringstring that ', | ||
' should be ', | ||
' wrapped ' | ||
'i am a stringi am a secondi am a third', | ||
' stringstring that', | ||
' should be', | ||
' wrapped' | ||
] | ||
@@ -146,5 +146,5 @@ | ||
var expected = [ | ||
'i am a string i am a second i am a third string ', | ||
' string that should be ', | ||
' wrapped ' | ||
'i am a string i am a second i am a third string', | ||
' string that should be', | ||
' wrapped' | ||
] | ||
@@ -170,6 +170,6 @@ | ||
var expected = [ | ||
' i have i have i have no ', | ||
' padding padding on padding ', | ||
' on my my right ', | ||
' left ' | ||
' i have i have i have no', | ||
' padding padding on padding', | ||
' on my my right', | ||
' left' | ||
] | ||
@@ -194,7 +194,7 @@ | ||
var expected = [ | ||
'i am a string i am a third ', | ||
' string that ', | ||
' i am a secondshould be ', | ||
' string wrapped ', | ||
' ' | ||
'i am a string i am a third', | ||
' string that', | ||
' i am a secondshould be', | ||
' string wrapped', | ||
'' | ||
] | ||
@@ -213,3 +213,3 @@ | ||
ui.row( | ||
'i am a string', | ||
{text: 'i am a string', padding: [0, 1, 0, 0]}, | ||
{text: 'i am a second string', padding: [0, 2, 0, 0]}, | ||
@@ -219,5 +219,5 @@ {text: 'i am a third string that should not be wrapped', padding: [0, 0, 0, 2]} | ||
ui.toString().should.equal('i am a stringi am a second string i am a third string that should not be wrapped') | ||
ui.toString().should.equal('i am a string i am a second string i am a third string that should not be wrapped') | ||
}) | ||
}) | ||
}) |
13726
8
65
8