aboutsummaryrefslogtreecommitdiff
path: root/node_modules/wrap-ansi
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/wrap-ansi
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
downloadwallet-core-de98e0b232509d5f40c135d540a70e415272ff85.tar.xz
node_modules
Diffstat (limited to 'node_modules/wrap-ansi')
-rwxr-xr-xnode_modules/wrap-ansi/index.js168
-rw-r--r--node_modules/wrap-ansi/license21
-rw-r--r--node_modules/wrap-ansi/package.json68
-rw-r--r--node_modules/wrap-ansi/readme.md73
4 files changed, 330 insertions, 0 deletions
diff --git a/node_modules/wrap-ansi/index.js b/node_modules/wrap-ansi/index.js
new file mode 100755
index 000000000..ff625435f
--- /dev/null
+++ b/node_modules/wrap-ansi/index.js
@@ -0,0 +1,168 @@
+'use strict';
+var stringWidth = require('string-width');
+var stripAnsi = require('strip-ansi');
+
+var ESCAPES = [
+ '\u001b',
+ '\u009b'
+];
+
+var END_CODE = 39;
+
+var ESCAPE_CODES = {
+ 0: 0,
+ 1: 22,
+ 2: 22,
+ 3: 23,
+ 4: 24,
+ 7: 27,
+ 8: 28,
+ 9: 29,
+ 30: 39,
+ 31: 39,
+ 32: 39,
+ 33: 39,
+ 34: 39,
+ 35: 39,
+ 36: 39,
+ 37: 39,
+ 90: 39,
+ 40: 49,
+ 41: 49,
+ 42: 49,
+ 43: 49,
+ 44: 49,
+ 45: 49,
+ 46: 49,
+ 47: 49
+};
+
+function wrapAnsi(code) {
+ return ESCAPES[0] + '[' + code + 'm';
+}
+
+// calculate the length of words split on ' ', ignoring
+// the extra characters added by ansi escape codes.
+function wordLengths(str) {
+ return str.split(' ').map(function (s) {
+ return stringWidth(s);
+ });
+}
+
+// wrap a long word across multiple rows.
+// ansi escape codes do not count towards length.
+function wrapWord(rows, word, cols) {
+ var insideEscape = false;
+ var visible = stripAnsi(rows[rows.length - 1]).length;
+
+ for (var i = 0; i < word.length; i++) {
+ var x = word[i];
+
+ rows[rows.length - 1] += x;
+
+ if (ESCAPES.indexOf(x) !== -1) {
+ insideEscape = true;
+ } else if (insideEscape && x === 'm') {
+ insideEscape = false;
+ continue;
+ }
+
+ if (insideEscape) {
+ continue;
+ }
+
+ visible++;
+
+ if (visible >= cols && i < word.length - 1) {
+ rows.push('');
+ visible = 0;
+ }
+ }
+
+ // it's possible that the last row we copy over is only
+ // ansi escape characters, handle this edge-case.
+ if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
+ rows[rows.length - 2] += rows.pop();
+ }
+}
+
+// the wrap-ansi module can be invoked
+// in either 'hard' or 'soft' wrap mode.
+//
+// 'hard' will never allow a string to take up more
+// than cols characters.
+//
+// 'soft' allows long words to expand past the column length.
+function exec(str, cols, opts) {
+ var options = opts || {};
+
+ var pre = '';
+ var ret = '';
+ var escapeCode;
+
+ var lengths = wordLengths(str);
+ var words = str.split(' ');
+ var rows = [''];
+
+ for (var i = 0, word; (word = words[i]) !== undefined; i++) {
+ var rowLength = stringWidth(rows[rows.length - 1]);
+
+ if (rowLength) {
+ rows[rows.length - 1] += ' ';
+ rowLength++;
+ }
+
+ // in 'hard' wrap mode, the length of a line is
+ // never allowed to extend past 'cols'.
+ if (lengths[i] > cols && options.hard) {
+ if (rowLength) {
+ rows.push('');
+ }
+ wrapWord(rows, word, cols);
+ continue;
+ }
+
+ if (rowLength + lengths[i] > cols && rowLength > 0) {
+ if (options.wordWrap === false && rowLength < cols) {
+ wrapWord(rows, word, cols);
+ continue;
+ }
+
+ rows.push('');
+ }
+
+ rows[rows.length - 1] += word;
+ }
+
+ pre = rows.map(function (r) {
+ return r.trim();
+ }).join('\n');
+
+ for (var j = 0; j < pre.length; j++) {
+ var y = pre[j];
+
+ ret += y;
+
+ if (ESCAPES.indexOf(y) !== -1) {
+ var code = parseFloat(/[0-9][^m]*/.exec(pre.slice(j, j + 4)));
+ escapeCode = code === END_CODE ? null : code;
+ }
+
+ if (escapeCode && ESCAPE_CODES[escapeCode]) {
+ if (pre[j + 1] === '\n') {
+ ret += wrapAnsi(ESCAPE_CODES[escapeCode]);
+ } else if (y === '\n') {
+ ret += wrapAnsi(escapeCode);
+ }
+ }
+ }
+
+ return ret;
+}
+
+// for each line break, invoke the method separately.
+module.exports = function (str, cols, opts) {
+ return String(str).split('\n').map(function (substr) {
+ return exec(substr, cols, opts);
+ }).join('\n');
+};
diff --git a/node_modules/wrap-ansi/license b/node_modules/wrap-ansi/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/wrap-ansi/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+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.
diff --git a/node_modules/wrap-ansi/package.json b/node_modules/wrap-ansi/package.json
new file mode 100644
index 000000000..35754d433
--- /dev/null
+++ b/node_modules/wrap-ansi/package.json
@@ -0,0 +1,68 @@
+{
+ "name": "wrap-ansi",
+ "version": "2.1.0",
+ "description": "Wordwrap a string with ANSI escape codes",
+ "license": "MIT",
+ "repository": "chalk/wrap-ansi",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "maintainers": [
+ "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
+ "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
+ "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)",
+ "Benjamin Coe <ben@npmjs.com> (github.com/bcoe)"
+ ],
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "xo && nyc ava",
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "wrap",
+ "break",
+ "wordwrap",
+ "wordbreak",
+ "linewrap",
+ "ansi",
+ "styles",
+ "color",
+ "colour",
+ "colors",
+ "terminal",
+ "console",
+ "cli",
+ "string",
+ "tty",
+ "escape",
+ "formatting",
+ "rgb",
+ "256",
+ "shell",
+ "xterm",
+ "log",
+ "logging",
+ "command-line",
+ "text"
+ ],
+ "dependencies": {
+ "string-width": "^1.0.1",
+ "strip-ansi": "^3.0.1"
+ },
+ "devDependencies": {
+ "ava": "^0.16.0",
+ "chalk": "^1.1.0",
+ "coveralls": "^2.11.4",
+ "has-ansi": "^2.0.0",
+ "nyc": "^6.2.1",
+ "strip-ansi": "^3.0.0",
+ "xo": "*"
+ }
+}
diff --git a/node_modules/wrap-ansi/readme.md b/node_modules/wrap-ansi/readme.md
new file mode 100644
index 000000000..59fc96bda
--- /dev/null
+++ b/node_modules/wrap-ansi/readme.md
@@ -0,0 +1,73 @@
+# 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)
+
+
+## Install
+
+```
+$ npm install --save wrap-ansi
+```
+
+
+## Usage
+
+```js
+const chalk = require('chalk');
+const wrapAnsi = require('wrap-ansi');
+
+const input = 'The quick brown ' + chalk.red('fox jumped over ') +
+ 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
+
+console.log(wrapAnsi(input, 20));
+```
+
+<img width="331" src="screenshot.png">
+
+
+## API
+
+### wrapAnsi(input, columns, [options])
+
+Wrap words to the specified column width.
+
+#### input
+
+Type: `string`
+
+String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
+
+#### columns
+
+Type: `number`
+
+Number of columns to wrap the text to.
+
+#### options
+
+##### 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](https://sindresorhus.com)