[Pkg-javascript-commits] [node-wrap-ansi] 01/04: New upstream version 2.1.0
Paolo Greppi
paolog-guest at moszumanska.debian.org
Wed May 3 08:32:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
paolog-guest pushed a commit to branch master
in repository node-wrap-ansi.
commit 3a901a051c125d8855c2a9983d1d61ccea3f564d
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date: Wed May 3 09:06:10 2017 +0200
New upstream version 2.1.0
---
.editorconfig | 3 --
.travis.yml | 7 ++--
index.js | 8 +++-
package.json | 13 +++---
readme.md | 18 +++++++--
test.js | 126 +++++++++++++++++++++++++++++-----------------------------
6 files changed, 93 insertions(+), 82 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 8f9d77e..98a761d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -10,6 +10,3 @@ insert_final_newline = true
[{package.json,*.yml}]
indent_style = space
indent_size = 2
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/.travis.yml b/.travis.yml
index 9d1ba36..be8a96a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
language: node_js
node_js:
- - 'stable'
- - '0.12'
- - '0.10'
-after_success: npm run coverage
+ - '4'
+ - 'node'
+after_success: npm run coveralls
diff --git a/index.js b/index.js
index f00fa92..ff62543 100755
--- a/index.js
+++ b/index.js
@@ -1,5 +1,6 @@
'use strict';
var stringWidth = require('string-width');
+var stripAnsi = require('strip-ansi');
var ESCAPES = [
'\u001b',
@@ -52,7 +53,7 @@ function wordLengths(str) {
// ansi escape codes do not count towards length.
function wrapWord(rows, word, cols) {
var insideEscape = false;
- var visible = rows[rows.length - 1].length;
+ var visible = stripAnsi(rows[rows.length - 1]).length;
for (var i = 0; i < word.length; i++) {
var x = word[i];
@@ -122,6 +123,11 @@ function exec(str, cols, opts) {
}
if (rowLength + lengths[i] > cols && rowLength > 0) {
+ if (options.wordWrap === false && rowLength < cols) {
+ wrapWord(rows, word, cols);
+ continue;
+ }
+
rows.push('');
}
diff --git a/package.json b/package.json
index 960ea2d..35754d4 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "wrap-ansi",
- "version": "2.0.0",
+ "version": "2.1.0",
"description": "Wordwrap a string with ANSI escape codes",
"license": "MIT",
"repository": "chalk/wrap-ansi",
@@ -19,8 +19,8 @@
"node": ">=0.10.0"
},
"scripts": {
- "test": "xo && nyc node test.js",
- "coverage": "nyc --reporter=text-lcov node test.js | coveralls"
+ "test": "xo && nyc ava",
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"files": [
"index.js"
@@ -53,14 +53,15 @@
"text"
],
"dependencies": {
- "string-width": "^1.0.1"
+ "string-width": "^1.0.1",
+ "strip-ansi": "^3.0.1"
},
"devDependencies": {
- "ava": "0.0.4",
+ "ava": "^0.16.0",
"chalk": "^1.1.0",
"coveralls": "^2.11.4",
"has-ansi": "^2.0.0",
- "nyc": "^3.2.2",
+ "nyc": "^6.2.1",
"strip-ansi": "^3.0.0",
"xo": "*"
}
diff --git a/readme.md b/readme.md
index f2e0a6a..59fc96b 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,4 @@
-# wrap-ansi [![Build Status](https://travis-ci.org/chalk/wrap-ansi.svg?branch=master)](https://travis-ci.org/chalk/wrap-ansi) [![Coverage Status](https://coveralls.io/repos/chalk/wrap-ansi/badge.svg?branch=master&service=github)](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
+# wrap-ansi [![Build Status](https://travis-ci.org/chalk/wrap-ansi.svg?branch=master)](https://travis-ci.org/chalk/wrap-ansi) [![Coverage Status](https://coveralls.io/repos/github/chalk/wrap-ansi/badge.svg?branch=master)](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
> Wordwrap a string with [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
@@ -43,21 +43,31 @@ Type: `number`
Number of columns to wrap the text to.
-#### options.hard
+#### options
-Type: `boolean`
+##### hard
+
+Type: `boolean`<br>
Default: `false`
By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width.
+##### wordWrap
+
+Type: `boolean`<br>
+Default: `true`
+
+By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
+
## Related
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
+- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
- [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures.
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
index f976a75..da07db3 100755
--- a/test.js
+++ b/test.js
@@ -1,96 +1,94 @@
-'use strict';
-var test = require('ava');
-var chalk = require('chalk');
-var hasAnsi = require('has-ansi');
-var stripAnsi = require('strip-ansi');
-var fn = require('./');
+import test from 'ava';
+import chalk from 'chalk';
+import hasAnsi from 'has-ansi';
+import stripAnsi from 'strip-ansi';
+import fn from './';
// when "hard" is false
-var fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
-var fixture2 = '12345678\n901234567890';
+const fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
+const fixture2 = '12345678\n901234567890';
+const fixture3 = '12345678\n901234567890 12345';
-test('wraps string at 20 characters', function (t) {
- var res20 = fn(fixture, 20);
+test('wraps string at 20 characters', t => {
+ const res20 = fn(fixture, 20);
- t.assert(res20 === 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
- t.assert(stripAnsi(res20).split('\n').every(function (x) {
- return x.length <= 20;
- }));
-
- t.end();
+ t.is(res20, 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
+ t.true(stripAnsi(res20).split('\n').every(x => x.length <= 20));
});
-test('wraps string at 30 characters', function (t) {
- var res30 = fn(fixture, 30);
+test('wraps string at 30 characters', t => {
+ const res30 = fn(fixture, 30);
- t.assert(res30 === 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
- t.assert(stripAnsi(res30).split('\n').every(function (x) {
+ t.is(res30, 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
+ t.true(stripAnsi(res30).split('\n').every(function (x) {
return x.length <= 30;
}));
-
- t.end();
});
-test('does not break strings longer than "cols" characters', function (t) {
- var res5 = fn(fixture, 5, {hard: false});
+test('does not break strings longer than "cols" characters', t => {
+ const res5 = fn(fixture, 5, {hard: false});
- t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
- t.assert(
- stripAnsi(res5).split('\n').filter(function (x) {
- return x.length > 5;
- }).length > 0
- );
-
- t.end();
+ t.is(res5, 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
+ t.true(stripAnsi(res5).split('\n').filter(x => x.length > 5).length > 0);
});
-test('handles colored string that wraps on to multiple lines', function (t) {
- var res = fn(chalk.green('hello world') + ' hey!', 5, {hard: false});
- var lines = res.split('\n');
- t.assert(hasAnsi(lines[0]));
- t.assert(hasAnsi(lines[1]));
- t.assert(hasAnsi(lines[2]) === false);
- t.end();
+test('handles colored string that wraps on to multiple lines', t => {
+ const res = fn(chalk.green('hello world') + ' hey!', 5, {hard: false});
+ const lines = res.split('\n');
+ t.true(hasAnsi(lines[0]));
+ t.true(hasAnsi(lines[1]));
+ t.false(hasAnsi(lines[2]));
});
-test('does not prepend newline if first string is greater than "cols"', function (t) {
- var res = fn(chalk.green('hello') + '-world', 5, {hard: false});
- t.assert(res.split('\n').length === 1);
- t.end();
+test('does not prepend newline if first string is greater than "cols"', t => {
+ const res = fn(chalk.green('hello') + '-world', 5, {hard: false});
+ t.is(res.split('\n').length, 1);
});
// when "hard" is true
-test('breaks strings longer than "cols" characters', function (t) {
- var res5 = fn(fixture, 5, {hard: true});
+test('breaks strings longer than "cols" characters', t => {
+ const res5 = fn(fixture, 5, {hard: true});
- t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
- t.assert(stripAnsi(res5).split('\n').every(function (x) {
- return x.length <= 5;
- }));
+ t.is(res5, 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
+ t.true(stripAnsi(res5).split('\n').every(x => x.length <= 5));
+});
- t.end();
+test('removes last row if it contained only ansi escape codes', t => {
+ const res = fn(chalk.green('helloworld'), 2, {hard: true});
+ t.true(stripAnsi(res).split('\n').every(x => x.length === 2));
});
-test('removes last row if it contained only ansi escape codes', function (t) {
- var res = fn(chalk.green('helloworld'), 2, {hard: true});
+test('does not prepend newline if first word is split', t => {
+ const res = fn(chalk.green('hello') + 'world', 5, {hard: true});
+ t.is(res.split('\n').length, 2);
+});
- t.assert(stripAnsi(res).split('\n').every(function (x) {
- return x.length === 2;
- }));
+test('takes into account line returns inside input', t => {
+ const res20 = fn(fixture2, 10, {hard: true});
+ t.is(res20, '12345678\n9012345678\n90');
+});
+
+test('word wrapping', t => {
+ const res = fn(fixture3, 15);
+ t.is(res, '12345678\n901234567890\n12345');
+});
+
+test('no word-wrapping', t => {
+ const res = fn(fixture3, 15, {wordWrap: false});
+ t.is(res, '12345678\n901234567890 12\n345');
- t.end();
+ const res2 = fn(fixture, 5, {wordWrap: false});
+ t.is(res2, 'The q\nuick\nbrown\n[31mfox j[39m\n[31mumped[39m\n[31mover[39m\n[31m[39mthe l\nazy [32md[39m\n[32mog an[39m\n[32md the[39m\n[32mn ran[39m\n[32maway[39m\n[32mwith[39m\n[32mthe u[39m\n[32mnicor[39m\n[32mn.[39m');
});
-test('does not prepend newline if first word is split', function (t) {
- var res = fn(chalk.green('hello') + 'world', 5, {hard: true});
- t.assert(res.split('\n').length === 2);
- t.end();
+// https://github.com/chalk/wrap-ansi/issues/10
+test.failing('supports fullwidth characters', t => {
+ t.is(fn('안녕하세', 4, {hard: true}), '안녕\n하세');
});
-test('takes into account line returns inside input', function (t) {
- var res20 = fn(fixture2, 10, {hard: true});
- t.assert(res20 === '12345678\n9012345678\n90');
- t.end();
+// https://github.com/chalk/wrap-ansi/issues/11
+test.failing('supports unicode surrogate pairs', t => {
+ t.is(fn('a\ud83c\ude00bc', 2, {hard: true}), 'a\n\ud83c\ude00\nbc');
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-wrap-ansi.git
More information about the Pkg-javascript-commits
mailing list