diff options
Diffstat (limited to 'node_modules/slice-ansi')
-rwxr-xr-x | node_modules/slice-ansi/index.js | 80 | ||||
-rwxr-xr-x | node_modules/slice-ansi/license | 22 | ||||
-rw-r--r-- | node_modules/slice-ansi/package.json | 56 | ||||
-rwxr-xr-x | node_modules/slice-ansi/readme.md | 56 |
4 files changed, 214 insertions, 0 deletions
diff --git a/node_modules/slice-ansi/index.js b/node_modules/slice-ansi/index.js new file mode 100755 index 000000000..c65de4d4a --- /dev/null +++ b/node_modules/slice-ansi/index.js @@ -0,0 +1,80 @@ +'use strict'; + +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'; +} + +module.exports = function (str, begin, end) { + end = end || str.length; + var insideEscape = false; + var escapeCode; + var visible = 0; + var output = ''; + + for (var i = 0; i < str.length; i++) { + var leftEscape = false; + var x = str[i]; + + if (ESCAPES.indexOf(x) !== -1) { + insideEscape = true; + var code = /[0-9][^m]*/.exec(str.slice(i, i + 4)); + escapeCode = code === END_CODE ? null : code; + } else if (insideEscape && x === 'm') { + insideEscape = false; + leftEscape = true; + } + + if (!insideEscape && !leftEscape) { + ++visible; + } + + if (visible > begin && visible <= end) { + output += x; + } else if (visible === begin && escapeCode !== undefined && escapeCode !== END_CODE) { + output += wrapAnsi(escapeCode); + } else if (visible >= end) { + if (escapeCode !== undefined) { + output += wrapAnsi(ESCAPE_CODES[escapeCode] || END_CODE); + } + break; + } + } + + return output; +}; + diff --git a/node_modules/slice-ansi/license b/node_modules/slice-ansi/license new file mode 100755 index 000000000..3ecaf413e --- /dev/null +++ b/node_modules/slice-ansi/license @@ -0,0 +1,22 @@ +(The MIT License)
+
+Copyright (c) 2015 DC <threedeecee@gmail.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.
\ No newline at end of file diff --git a/node_modules/slice-ansi/package.json b/node_modules/slice-ansi/package.json new file mode 100644 index 000000000..70bc93162 --- /dev/null +++ b/node_modules/slice-ansi/package.json @@ -0,0 +1,56 @@ +{ + "name": "slice-ansi", + "version": "0.0.4", + "description": "Slice a string with ANSI escape codes", + "license": "MIT", + "repository": "chalk/slice-ansi", + "author": { + "name": "David Caccavella", + "email": "threedeecee@gmail.com" + }, + "maintainers": [ + "David Caccavella <threedeecee@gmail.com> (github.com/dthree)", + "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)", + "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)", + "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)" + ], + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "node test.js && xo" + }, + "files": [ + "index.js" + ], + "keywords": [ + "slice", + "string", + "ansi", + "styles", + "color", + "colour", + "colors", + "terminal", + "console", + "cli", + "tty", + "escape", + "formatting", + "rgb", + "256", + "shell", + "xterm", + "log", + "logging", + "command-line", + "text" + ], + "dependencies": {}, + "devDependencies": { + "ava": "^0.2.0", + "chalk": "^1.1.1", + "strip-ansi": "^3.0.0", + "xo": "*" + } +} diff --git a/node_modules/slice-ansi/readme.md b/node_modules/slice-ansi/readme.md new file mode 100755 index 000000000..31be6124d --- /dev/null +++ b/node_modules/slice-ansi/readme.md @@ -0,0 +1,56 @@ +# slice-ansi + +[](https://travis-ci.org/vorpaljs/slice-ansi) +[](https://github.com/sindresorhus/xo) + +> Slice a string with [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) + +## Install + +``` +$ npm install --save slice-ansi +``` + +## Usage + +```js +var chalk = require('chalk'); +var sliceAnsi = require('slice-ansi'); + +var input = 'The quick brown ' + chalk.red('fox jumped over ') + + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); + +console.log(sliceAnsi(input, 20, 30)); +``` + +## API + +### sliceAnsi(input, beginSlice[, endSlice]) + +#### input + +Type: `string` + +String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). + +#### beginSlice + +Type: `number` + +The zero-based index at which to begin the slice. + +#### endSlice + +Type: `number` + +Optional. The zero-based index at which to end the slice. + + +## Related + +- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right + + +## License + +MIT © [David Caccavella](https://githbu.com/dthree) |