pax_global_header 0000666 0000000 0000000 00000000064 14221323132 0014503 g ustar 00root root 0000000 0000000 52 comment=4dbbd6787425d74a9654c8708fc54ac5db1ea348
cli-color-2.0.2/ 0000775 0000000 0000000 00000000000 14221323132 0013367 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/.editorconfig 0000664 0000000 0000000 00000000456 14221323132 0016051 0 ustar 00root root 0000000 0000000 # EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
[*.{md,yml}]
indent_size = 2
indent_style = space
[*.md]
trim_trailing_whitespace = false
cli-color-2.0.2/.github/ 0000775 0000000 0000000 00000000000 14221323132 0014727 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/.github/FUNDING.yml 0000664 0000000 0000000 00000000052 14221323132 0016541 0 ustar 00root root 0000000 0000000 github: medikoo
tidelift: "npm/cli-color"
cli-color-2.0.2/.github/workflows/ 0000775 0000000 0000000 00000000000 14221323132 0016764 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/.github/workflows/integrate.yml 0000664 0000000 0000000 00000000375 14221323132 0021476 0 ustar 00root root 0000000 0000000 # main only
name: Integrate
on:
push:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/tad-integrate.yml@main
secrets:
USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
cli-color-2.0.2/.github/workflows/publish.yml 0000664 0000000 0000000 00000000476 14221323132 0021164 0 ustar 00root root 0000000 0000000 # Version tags only
name: Publish
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/tad-publish.yml@main
secrets:
USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
cli-color-2.0.2/.github/workflows/validate.yml 0000664 0000000 0000000 00000000274 14221323132 0021303 0 ustar 00root root 0000000 0000000 # PR's only
name: Validate
on:
pull_request:
branches: [main]
env:
FORCE_COLOR: 1
jobs:
_:
uses: medikoo/github-actions-workflows/.github/workflows/tad-validate.yml@main
cli-color-2.0.2/.gitignore 0000664 0000000 0000000 00000000106 14221323132 0015354 0 ustar 00root root 0000000 0000000 /.nyc_output
/coverage
/node_modules
npm-debug.log
/package-lock.json
cli-color-2.0.2/.npmignore 0000664 0000000 0000000 00000000076 14221323132 0015371 0 ustar 00root root 0000000 0000000 /.editorconfig
/.github
/commitlint.config.js
/examples
/test
cli-color-2.0.2/CHANGELOG.md 0000664 0000000 0000000 00000003361 14221323132 0015203 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [2.0.2](https://github.com/medikoo/cli-color/compare/v2.0.1...v2.0.2) (2022-03-31)
### Bug Fixes
- Ensure to use widely supported ANSI codes for line move ([6838339](https://github.com/medikoo/cli-color/commit/6838339ae80d36e77c291645c6de891928197933))
### [2.0.1](https://github.com/medikoo/cli-color/compare/v2.0.0...v2.0.1) (2021-10-15)
### Maintenance Improvements
- Drop `ansi-regex` dependency due to security issues ([#38](https://github.com/medikoo/cli-color/issues/38)) ([9072cda](https://github.com/medikoo/cli-color/commit/9072cda305181dcc64d657d4de95a813db6dbdf3)) ([Jorge Cabot](https://github.com/jcabot21))
## [2.0.0](https://github.com/medikoo/cli-color/compare/v1.4.0...v2.0.0) (2019-10-09)
### Features
- Support NO_COLOR standard ([8f2a4eb](https://github.com/medikoo/cli-color/commit/8f2a4eb))
### BREAKING CHANGES
- ANSI color codes won't be generated for output, when NO_COLOR env var is set
# [1.4.0](https://github.com/medikoo/cli-color/compare/v1.3.0...v1.4.0) (2018-10-23)
### Features
- introduce move top, bottom, lineBegin and lineEnd instructions ([ad53db1](https://github.com/medikoo/cli-color/commit/ad53db1))
# [1.3.0](https://github.com/medikoo/cli-color/compare/v1.2.0...v1.3.0) (2018-08-20)
### Bug Fixes
- downgrade ansi-regex to not break support for old Node.js versions ([c4f765f](https://github.com/medikoo/cli-color/commit/c4f765f))
### Features
- **colums:** support multine cells ([585fc59](https://github.com/medikoo/cli-color/commit/585fc59))
## Old changelog
See `CHANGES`
cli-color-2.0.2/CHANGES 0000664 0000000 0000000 00000006605 14221323132 0014371 0 ustar 00root root 0000000 0000000 -- For new changelog see CHANGELOG.md
v1.2.0 -- 2017.02.22
* Improve `columns`:
* ANSI formatting instructions are not counted in calculation of column width
* Support custom 'align' per column
* Improve documentation, document `colums` utility
v1.1.0 -- 2015.10.13
* Add clc.slice and clc.getStrippedLength (thanks @StreetStrider)
* Add examples folder (thanks @ralphtheninja)
v1.0.0 -- 2015.04.22
* General modularization and files reorganization. From now on each utility is placed in individual
module, and can be required directly without others. Alternatively all modules are provided on
index module
* Support style nesting (thanks @rentalhost)
* Rename `trim` to `strip`
* Improve `strip` (previously `trim`) regex by relying on ansi-regex package
* Improve resolution of window size
* Add `columns` utility
* Add `art` utility (thanks @rentalhost)
* Add visual test (thanks @rentalhost)
* Drop support for v0.8 node
* Update lint configuration
v0.3.3 -- 2015.03.20
* Fix throbber tests
* Fix spelling of LICENSE
* Improve documentation
* Configure lint scripts
v0.3.2 -- 2014.04.27
* Fix errorneous dependency version in package.json
v0.3.1 -- 2014.04.27
* Update package.json to use latest 'tad' engine (fixes tests evaluation)
v0.3.0 -- 2014.04.27
* Move out all main modules from lib folder
* Improve `throbber` utility, so it no longer relies on `clock/lib/interval` interface
and it's easier to use on its own
* Update internals to use latest versions of dependencies
* Remove Makefile (it's cross environement package)
v0.2.3 -- 2013.09.16
Add `blink`
v0.2.2 -- 2013.02.20
* Fix trim, so it trims all kind of ANSI sequence codes correctly
* Do not rely on getWindowSize (it may not be available at all)
* Fix some xterm colors references in documentation
* Add Missing MIT licence
v0.2.1 -- 2012.10.05
Maintanance (Use v0.2 of memoizee)
v0.2.0 -- 2012.09.19
Major refactor of internal algorithm, addition of new functionalities
Changes:
* Bright variants are now set as individual colors (not as additional
characteristics as it was in 0.1.x). We should do: clc.redBright instead of
clc.red.bright
* Removed 'gray' color, clc.blackBright has same effect and should be used
instead
New functionalities:
* Already prepared configurations can now be extended directly, e.g.:
var error = clc.red;
var majorError = error.bold;
* 256 xTerm color support via xterm(n) and bgXterm(n) functions
* Move around functions: clc.move, clc.moveTo, clc.bol, clc.up, clc.down, clc.right and clc.left
* clc.reset - Outputs string that clears the terminal
* clc.beep
* clc.width & clc.height - Terminal characteristics properties
v0.1.7 -- 2012.06.13
* Update up to v0.8 branch of es5-extre
* package.json now in npm friendly format
v0.1.6 -- 2012.01.22
* Update dependencies to latest versions
* Travis CI support
* More reliable tests for throbber
v0.1.5 -- 2011.12.12
* Cleared npm warning for misnamed property in package.json
v0.1.4 -- 2011.10.05
* Added bright color variants
v0.1.3 -- 2011.08.08
* Added TAD test suite to devDependencies, configured test commands.
Tests can be run with 'make test' or 'npm test'
v0.1.2 -- 2011.08.08
* trim - for removing ANSI formatting from string
* throbber - displays throbber with preconfigured interval
* Compatibility with es5-ext v0.6
* Test with TAD
v0.1.1 -- 2011.07.12
* Better documentation
v0.1.0 -- 2011.07.11
* Initial version
cli-color-2.0.2/LICENSE 0000664 0000000 0000000 00000001405 14221323132 0014374 0 ustar 00root root 0000000 0000000 ISC License
Copyright (c) 2012-2022, Mariusz Nowak, @medikoo, medikoo.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
cli-color-2.0.2/README.md 0000664 0000000 0000000 00000106552 14221323132 0014657 0 ustar 00root root 0000000 0000000 [![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]
# cli-color
## Yet another colors and formatting for the console solution
Colors, formatting and other goodies for the console. This package won't mess with built-ins and provides neat way to predefine formatting patterns, see below.
## Installation
$ npm install cli-color
## Usage
Usage:
```javascript
var clc = require("cli-color");
```
Output colored text:
```javascript
console.log(clc.red("Text in red"));
```
Styles can be mixed:
```javascript
console.log(clc.red.bgWhite.underline("Underlined red text on white background."));
```
Styled text can be mixed with unstyled:
```javascript
console.log(clc.red("red") + " plain " + clc.blue("blue"));
```
Styled text can be nested:
```javascript
console.log(clc.red("red " + clc.blue("blue") + " red"));
```
**Best way is to predefine needed stylings and then use it**:
```javascript
var error = clc.red.bold;
var warn = clc.yellow;
var notice = clc.blue;
console.log(error("Error!"));
console.log(warn("Warning"));
console.log(notice("Notice"));
```
_Note: No colors or styles are output when [`NO_COLOR` env var](https://no-color.org/) is set_
Supported are all ANSI colors and styles:
#### Styles
Styles will display correctly if font used in your console supports them.
- bold
- italic
- underline
- blink
- inverse
- strike
#### Colors
Foreground | Background | |
black | bgBlack |  |
red | bgRed |  |
green | bgGreen |  |
yellow | bgYellow |  |
blue | bgBlue |  |
magenta | bgMagenta |  |
cyan | bgCyan |  |
white | bgWhite |  |
##### Bright variants
Foreground | Background | |
blackBright | bgBlackBright |  |
redBright | bgRedBright |  |
greenBright | bgGreenBright |  |
yellowBright | bgYellowBright |  |
blueBright | bgBlueBright |  |
magentaBright | bgMagentaBright |  |
cyanBright | bgCyanBright |  |
whiteBright | bgWhiteBright |  |
##### xTerm colors (256 colors table)
**Not supported on Windows and some terminals**. However if used in not supported environment, the closest color from basic (16 colors) palette is chosen.
Usage:
```javascript
var msg = clc.xterm(202).bgXterm(236);
console.log(msg("Orange text on dark gray background"));
```
Color table:
0 |  |
1 |  |
2 |  |
3 |  |
4 |  |
5 |  |
6 |  |
7 |  |
8 |  |
9 |  |
10 |  |
11 |  |
12 |  |
13 |  |
14 |  |
15 |  |
16 |  |
17 |  |
18 |  |
19 |  |
20 |  |
21 |  |
22 |  |
23 |  |
24 |  |
25 |  |
26 |  |
27 |  |
28 |  |
29 |  |
30 |  |
31 |  |
32 |  |
33 |  |
34 |  |
35 |  |
36 |  |
37 |  |
38 |  |
39 |  |
40 |  |
41 |  |
42 |  |
43 |  |
44 |  |
45 |  |
46 |  |
47 |  |
48 |  |
49 |  |
50 |  |
51 |  |
52 |  |
53 |  |
54 |  |
55 |  |
56 |  |
57 |  |
58 |  |
59 |  |
60 |  |
61 |  |
62 |  |
63 |  |
64 |  |
65 |  |
66 |  |
67 |  |
68 |  |
69 |  |
70 |  |
71 |  |
72 |  |
73 |  |
74 |  |
75 |  |
76 |  |
77 |  |
78 |  |
79 |  |
80 |  |
81 |  |
82 |  |
83 |  |
84 |  |
85 |  |
86 |  |
87 |  |
88 |  |
89 |  |
90 |  |
91 |  |
92 |  |
93 |  |
94 |  |
95 |  |
96 |  |
97 |  |
98 |  |
99 |  |
100 |  |
101 |  |
102 |  |
103 |  |
104 |  |
105 |  |
106 |  |
107 |  |
108 |  |
109 |  |
110 |  |
111 |  |
112 |  |
113 |  |
114 |  |
115 |  |
116 |  |
117 |  |
118 |  |
119 |  |
120 |  |
121 |  |
122 |  |
123 |  |
124 |  |
125 |  |
126 |  |
127 |  |
128 |  |
129 |  |
130 |  |
131 |  |
132 |  |
133 |  |
134 |  |
135 |  |
136 |  |
137 |  |
138 |  |
139 |  |
140 |  |
141 |  |
142 |  |
143 |  |
144 |  |
145 |  |
146 |  |
147 |  |
148 |  |
149 |  |
150 |  |
151 |  |
152 |  |
153 |  |
154 |  |
155 |  |
156 |  |
157 |  |
158 |  |
159 |  |
160 |  |
161 |  |
162 |  |
163 |  |
164 |  |
165 |  |
166 |  |
167 |  |
168 |  |
169 |  |
170 |  |
171 |  |
172 |  |
173 |  |
174 |  |
175 |  |
176 |  |
177 |  |
178 |  |
179 |  |
180 |  |
181 |  |
182 |  |
183 |  |
184 |  |
185 |  |
186 |  |
187 |  |
188 |  |
189 |  |
190 |  |
191 |  |
192 |  |
193 |  |
194 |  |
195 |  |
196 |  |
197 |  |
198 |  |
199 |  |
200 |  |
201 |  |
202 |  |
203 |  |
204 |  |
205 |  |
206 |  |
207 |  |
208 |  |
209 |  |
210 |  |
211 |  |
212 |  |
213 |  |
214 |  |
215 |  |
216 |  |
217 |  |
218 |  |
219 |  |
220 |  |
221 |  |
222 |  |
223 |  |
224 |  |
225 |  |
226 |  |
227 |  |
228 |  |
229 |  |
230 |  |
231 |  |
232 |  |
233 |  |
234 |  |
235 |  |
236 |  |
237 |  |
238 |  |
239 |  |
240 |  |
241 |  |
242 |  |
243 |  |
244 |  |
245 |  |
246 |  |
247 |  |
248 |  |
249 |  |
250 |  |
251 |  |
252 |  |
253 |  |
254 |  |
255 |  |
#### Reset
Terminal can be cleared with `clc.reset`
```javascript
process.stdout.write(clc.reset);
```
#### Erase
##### clc.erase.screen
Entire screen
```javascript
process.stdout.write(clc.erase.screen);
```
##### clc.erase.screenLeft
Left portion of a screen
```javascript
process.stdout.write(clc.erase.screenLeft);
```
##### clc.erase.screenRight
Right portion of a screen
```javascript
process.stdout.write(clc.erase.screenRight);
```
##### clc.erase.line
Current line
```javascript
process.stdout.write(clc.erase.line);
```
##### clc.erase.lineRight
Right portion of current line
```javascript
process.stdout.write(clc.erase.lineRight);
```
##### clc.erase.lineLeft
Left portion of current line
```javascript
process.stdout.write(clc.erase.lineLeft);
```
#### Move around functions
##### clc.move(x, y)
Move cursor _x_ columns and _y_ rows away. Values can be positive or negative, e.g.:
```javascript
process.stdout.write(clc.move(-2, -2)); // Move cursors two columns and two rows back
```
##### clc.move.to(x, y)
Absolute move. Sets cursor position at _x_ column and _y_ row
```javascript
process.stdout.write(clc.move.to(0, 0)); // Move cursor to first row and first column in terminal window
```
##### clc.move.up(n)
Move cursor up _n_ rows
```javascript
process.stdout.write(clc.move.up(2));
```
##### clc.move.down(n)
Move cursor down _n_ rows
```javascript
process.stdout.write(clc.move.down(2));
```
##### clc.move.right(n)
Move cursor right _n_ columns
```javascript
process.stdout.write(clc.move.right(2));
```
##### clc.move.left(n)
Move cursor left _n_ columns
```javascript
process.stdout.write(clc.move.left(2));
```
##### clc.move.lines(n)
Move cursor `n` lines forward if `n` is positive, otherwise `n` lines backward, and place it at line beginning
```javascript
process.stdout.write(clc.move.lines(2));
```
##### clc.move.top
Move cursor to top of a screen
```javascript
process.stdout.write(clc.move.top);
```
##### clc.move.bottom
Move cursor to bottom of a screen
```javascript
process.stdout.write(clc.move.bottom);
```
##### clc.move.lineBegin
Move cursor to begin of a line
```javascript
process.stdout.write(clc.move.lineBegin);
```
##### clc.move.lineEnd
Move cursor to end of a line
```javascript
process.stdout.write(clc.move.lineEnd);
```
#### Terminal characteristics
##### clc.windowSize.width
Returns terminal width
##### clc.windowSize.height
Returns terminal height
### Additional functionalities
#### clc.slice(str[, begin[, end]])
Slice provided string with preservation of eventual ANSI formatting
```javascript
var clc = require("cli-color");
var str = clc.bold("foo") + "bar" + clc.red("elo");
var sliced = clc.slice(str, 1, 7); // Same as: clc.bold('oo') + 'bar' + clc.red('e')
```
#### clc.strip(formatedText)
Strips ANSI formatted string to plain text
```javascript
var ansiStrip = require("cli-color/strip");
var plain = ansiStrip(formatted);
```
#### clc.getStrippedLength(str)
Get actual length of ANSI-formatted string
```javascript
var clc = require("cli-color");
var str = clc.bold("foo") + "bar" + clc.red("elo");
clc.getStrippedLength(str); // 9
```
#### clc.art(text, styleConf)
Create a text-graphical art. Within `styleConf`, string replacements needs to be defined, which are then used to convert `text` to styled graphical text.
```javascript
var text = ".........\n" + ". Hello .\n" + ".........\n";
var style = { ".": clc.yellowBright("X") };
process.stdout.write(clc.art(text, style));
```
#### clc.columns(data[, options])
Outputs aligned table of columns.
`data` is expected to be an array (or other iterable structure) of rows, where each row is also an array (or other iterable structure) of content to display.
Supported `options`:
- `sep`: Custom colums separator (defaults to `|`)
- `columns`: Per column customizations, as e.g. `[{ align: 'right' }, null, { align: 'left' }]`:
- `align`: Possible options: `'left'`, `'right` (efaults to `'left'`)
```javascript
var clc = require("cli-color");
process.stdout.write(
clc.columns([
[clc.bold("First Name"), clc.bold("Last Name"), clc.bold("Age")],
["John", "Doe", 34],
["Martha", "Smith", 20],
["Jan", "Kowalski", 30]
])
);
/* Outputs:
First Name | Last Name | Age
John | Doe | 34
Martha | Smith | 20
Jan | Kowalski | 30
*/
```
##### throbber(write, interval[, format])
Writes throbber string to _write_ function at given _interval_. Optionally throbber output can be formatted with given _format_ function
```javascript
var setupThrobber = require("cli-color/throbber");
var throbber = setupThrobber(function (str) { process.stdout.write(str); }, 200);
throbber.start();
// at any time you can stop/start throbber
throbber.stop();
```
## Tests
$ npm test
## Security contact information
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
## Contributors
- [@rentalhost](https://github.com/rentalhost) (David Rodrigues)
- Help with support for nested styles. Introduction of `clc.art` module, and significant improvements to tests coverage
- [@StreetStrider](https://github.com/StreetStrider)
- Implementation of sophistcated `clc.slice` functionality, and introduction of `clc.getStrippedLength` utility
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/cli-color/branches/master/shields_badge.svg
[nix-build-url]: https://semaphoreci.com/medikoo-org/cli-color
[win-build-image]: https://ci.appveyor.com/api/projects/status/mnd4catkeu181ll5?svg=true
[win-build-url]: https://ci.appveyor.com/project/medikoo/cli-color
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
[npm-image]: https://img.shields.io/npm/v/cli-color.svg
[npm-url]: https://www.npmjs.com/package/cli-color
---
[build-image]: https://github.com/medikoo/cli-color/workflows/Integrate/badge.svg
[build-url]: https://github.com/medikoo/cli-color/actions?query=workflow%3AIntegrate
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/cli-color.svg
[cov-url]: https://codecov.io/gh/medikoo/cli-color
[npm-image]: https://img.shields.io/npm/v/cli-color.svg
[npm-url]: https://www.npmjs.com/package/cli-color
cli-color-2.0.2/art.js 0000664 0000000 0000000 00000000610 14221323132 0014510 0 ustar 00root root 0000000 0000000 "use strict";
var object = require("es5-ext/object/valid-object")
, stringifiable = require("es5-ext/object/validate-stringifiable-value")
, forOf = require("es6-iterator/for-of");
module.exports = function (text, style) {
var result = "";
text = stringifiable(text);
object(style);
forOf(text, function (char) { result += style[char] || char; });
return result;
};
cli-color-2.0.2/bare.js 0000664 0000000 0000000 00000005273 14221323132 0014645 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("d")
, assign = require("es5-ext/object/assign")
, forEach = require("es5-ext/object/for-each")
, map = require("es5-ext/object/map")
, primitiveSet = require("es5-ext/object/primitive-set")
, setPrototypeOf = require("es5-ext/object/set-prototype-of")
, memoize = require("memoizee")
, memoizeMethods = require("memoizee/methods")
, sgr = require("./lib/sgr")
, supportsColor = require("./lib/supports-color");
var mods = sgr.mods
, join = Array.prototype.join
, defineProperty = Object.defineProperty
, max = Math.max
, min = Math.min
, variantModes = primitiveSet("_fg", "_bg")
, xtermMatch = process.platform === "win32" ? require("./lib/xterm-match") : null;
var getFn;
// Some use cli-color as: console.log(clc.red('Error!'));
// Which is inefficient as on each call it configures new clc object
// with memoization we reuse once created object
var memoized = memoize(function (scope, mod) {
return defineProperty(getFn(), "_cliColorData", d(assign({}, scope._cliColorData, mod)));
});
var proto = Object.create(
Function.prototype,
assign(
map(mods, function (mod) {
return d.gs(function () { return memoized(this, mod); });
}),
memoizeMethods({
// xterm (255) color
xterm: d(function (code) {
code = isNaN(code) ? 255 : min(max(code, 0), 255);
return defineProperty(
getFn(), "_cliColorData",
d(
assign({}, this._cliColorData, {
_fg: [xtermMatch ? xtermMatch[code] : "38;5;" + code, 39]
})
)
);
}),
bgXterm: d(function (code) {
code = isNaN(code) ? 255 : min(max(code, 0), 255);
return defineProperty(
getFn(), "_cliColorData",
d(
assign({}, this._cliColorData, {
_bg: [xtermMatch ? xtermMatch[code] + 10 : "48;5;" + code, 49]
})
)
);
})
})
)
);
var getEndRe = memoize(function (code) { return new RegExp("\x1b\\[" + code + "m", "g"); }, {
primitive: true
});
getFn = function () {
return setPrototypeOf(
function self(/* …msg*/) {
var start = ""
, end = ""
, msg = join.call(arguments, " ")
, conf = self._cliColorData
, hasAnsi = sgr.hasCSI(msg);
forEach(
conf,
function (mod, key) {
end = sgr(mod[1]) + end;
start += sgr(mod[0]);
if (hasAnsi) {
msg = msg.replace(getEndRe(mod[1]), variantModes[key] ? sgr(mod[0]) : "");
}
},
null,
true
);
if (!supportsColor.isColorSupported()) return msg;
return start + msg + end;
},
proto
);
};
module.exports = Object.defineProperties(getFn(), {
xtermSupported: d(!xtermMatch),
_cliColorData: d("", {})
});
cli-color-2.0.2/beep.js 0000664 0000000 0000000 00000000050 14221323132 0014633 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = "\x07";
cli-color-2.0.2/bin/ 0000775 0000000 0000000 00000000000 14221323132 0014137 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/bin/generate-color-images 0000775 0000000 0000000 00000001063 14221323132 0020236 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
'use strict';
var uniq = require('es5-ext/array/#/uniq')
, deferred = require('deferred')
, resolve = require('path').resolve
, gm = require('gm')
, colors = require('../lib/_xterm-colors');
gm.prototype.pThumb = deferred.gate(deferred.promisify(gm.prototype.thumb), 50);
deferred.map(uniq.call(colors), function (color) {
return gm('ROSE:').fill('#' + color).drawRectangle(0, 0, 100, 100)
.pThumb(1, 1, resolve(__dirname, color + '.png'), 80).aside(function () {
console.log('Done: ' + color);
});
}).done();
cli-color-2.0.2/columns.js 0000664 0000000 0000000 00000003572 14221323132 0015414 0 ustar 00root root 0000000 0000000 "use strict";
var generate = require("es5-ext/array/generate")
, from = require("es5-ext/array/from")
, iterable = require("es5-ext/iterable/validate-object")
, isValue = require("es5-ext/object/is-value")
, stringifiable = require("es5-ext/object/validate-stringifiable")
, repeat = require("es5-ext/string/#/repeat")
, getStrippedLength = require("./get-stripped-length");
var push = Array.prototype.push;
module.exports = function (inputRows /*, options*/) {
var options = Object(arguments[1])
, colsMeta = []
, colsOptions = options.columns || []
, rows = [];
from(iterable(inputRows), function (row) {
var rowRows = [[]];
from(iterable(row), function (cellStr, columnIndex) {
var cellRows = stringifiable(cellStr).split("\n");
while (cellRows.length > rowRows.length) rowRows.push(generate(columnIndex, ""));
cellRows.forEach(function (cellRow, rowRowIndex) {
rowRows[rowRowIndex][columnIndex] = cellRow;
});
});
push.apply(rows, rowRows);
});
return (
rows
.map(function (row) {
return from(iterable(row), function (str, index) {
var col = colsMeta[index], strLength;
if (!col) col = colsMeta[index] = { width: 0 };
str = stringifiable(str);
strLength = getStrippedLength(str);
if (strLength > col.width) col.width = strLength;
return { str: str, length: strLength };
});
})
.map(function (row) {
return row
.map(function (item, index) {
var pad, align = "left", colOptions = colsOptions && colsOptions[index];
align = colOptions && colOptions.align === "right" ? "right" : "left";
pad = repeat.call(" ", colsMeta[index].width - item.length);
if (align === "left") return item.str + pad;
return pad + item.str;
})
.join(isValue(options.sep) ? options.sep : " | ");
})
.join("\n") + "\n"
);
};
cli-color-2.0.2/commitlint.config.js 0000664 0000000 0000000 00000001236 14221323132 0017352 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = {
rules: {
"body-leading-blank": [2, "always"],
"body-max-line-length": [2, "always", 72],
"footer-leading-blank": [2, "always"],
"footer-max-line-length": [2, "always", 72],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "start-case"],
"scope-enum": [2, "always", [""]],
"subject-case": [2, "always", "sentence-case"],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [
2, "always",
["build", "chore", "ci", "docs", "feat", "fix", "perf", "refactor", "style", "test"]
]
}
};
cli-color-2.0.2/erase.js 0000664 0000000 0000000 00000000246 14221323132 0015026 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = {
screen: "\x1b[2J",
screenLeft: "\x1b[1J",
screenRight: "\x1b[J",
line: "\x1b[2K",
lineLeft: "\x1b[1K",
lineRight: "\x1b[K"
};
cli-color-2.0.2/examples/ 0000775 0000000 0000000 00000000000 14221323132 0015205 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/examples/art.js 0000664 0000000 0000000 00000000263 14221323132 0016332 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
var text = ".........\n. Hello .\n.........\n";
var style = { ".": clc.yellowBright("X") };
process.stdout.write(clc.art(text, style));
cli-color-2.0.2/examples/basic.js 0000664 0000000 0000000 00000001271 14221323132 0016625 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
console.log("Output colored text:");
console.log(clc.red("Text in red"));
console.log("Styles can be mixed:");
console.log(clc.red.bgWhite.underline("Underlined red text on white background."));
console.log("Styled text can be mixed with unstyled:");
console.log(clc.red("red") + " plain " + clc.blue("blue"));
console.log("Styled text can be nested:");
console.log(clc.red("red " + clc.blue("blue") + " red"));
console.log("Best way is to predefine needed stylings and then use it:");
var error = clc.red.bold;
var warn = clc.yellow;
var notice = clc.blue;
console.log(error("Error!"));
console.log(warn("Warning"));
console.log(notice("Notice"));
cli-color-2.0.2/examples/erase.js 0000664 0000000 0000000 00000001124 14221323132 0016640 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
console.log("Erasing screen ..");
setTimeout(function () {
process.stdout.write(clc.erase.screen);
console.log("This a line of text that should not be cleared");
process.stdout.write("This line will be cleared but cursor will be here ->");
setTimeout(function () {
process.stdout.write(clc.erase.line);
process.stdout.write("\nMoving cursor backwards and deleting (from here): to the right");
setTimeout(function () {
process.stdout.write(clc.move(-13, 0));
process.stdout.write(clc.erase.lineRight);
}, 2000);
}, 2000);
}, 2000);
cli-color-2.0.2/examples/styles.js 0000664 0000000 0000000 00000000506 14221323132 0017067 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
console.log(clc.bold("Bold text"));
console.log(clc.italic("Italic text"));
console.log(clc.underline("Underlined text"));
console.log(clc.blink("Blinking text (might not work for your font)"));
console.log(clc.inverse("Inverse text"));
console.log(clc.strike("Strikethrough text"));
cli-color-2.0.2/examples/throbber.js 0000664 0000000 0000000 00000000441 14221323132 0017351 0 ustar 00root root 0000000 0000000 "use strict";
var setupThrobber = require("../throbber");
var throbber = setupThrobber(function (str) { process.stdout.write(str); }, 200);
process.stdout.write("Throbbing for 3 seconds here -> ");
throbber.start();
setTimeout(function () {
console.log();
throbber.stop();
}, 3000);
cli-color-2.0.2/examples/xterm.js 0000664 0000000 0000000 00000000212 14221323132 0016675 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
var msg = clc.xterm(202).bgXterm(236);
console.log(msg("Orange text on dark gray background"));
cli-color-2.0.2/get-stripped-length.js 0000664 0000000 0000000 00000000245 14221323132 0017614 0 ustar 00root root 0000000 0000000 "use strict";
/*
* get actual length of ANSI-formatted string
*/
var strip = require("./strip");
module.exports = function (str) { return strip(str).length; };
cli-color-2.0.2/index.js 0000664 0000000 0000000 00000000743 14221323132 0015040 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("d");
module.exports = Object.defineProperties(require("./bare"), {
windowSize: d(require("./window-size")),
erase: d(require("./erase")),
move: d(require("./move")),
beep: d(require("./beep")),
columns: d(require("./columns")),
strip: d(require("./strip")),
getStrippedLength: d(require("./get-stripped-length")),
slice: d(require("./slice")),
throbber: d(require("./throbber")),
reset: d(require("./reset")),
art: d(require("./art"))
});
cli-color-2.0.2/lib/ 0000775 0000000 0000000 00000000000 14221323132 0014135 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/lib/sgr.js 0000664 0000000 0000000 00000004763 14221323132 0015300 0 ustar 00root root 0000000 0000000 "use strict";
/* CSI - control sequence introducer */
/* SGR - set graphic rendition */
var assign = require("es5-ext/object/assign")
, includes = require("es5-ext/string/#/contains")
, forOwn = require("es5-ext/object/for-each")
, onlyKey = require("es5-ext/object/first-key")
, forEachRight = require("es5-ext/array/#/for-each-right")
, uniq = require("es5-ext/array/#/uniq.js");
var CSI = "\x1b[";
var sgr = function (code) { return CSI + code + "m"; };
sgr.CSI = CSI;
var mods = assign(
{
// Style
bold: { _bold: [1, 22] },
italic: { _italic: [3, 23] },
underline: { _underline: [4, 24] },
blink: { _blink: [5, 25] },
inverse: { _inverse: [7, 27] },
strike: { _strike: [9, 29] }
// Color
},
["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"].reduce(function (
obj,
color,
index
) {
// foreground
obj[color] = { _fg: [30 + index, 39] };
obj[color + "Bright"] = { _fg: [90 + index, 39] };
// background
obj["bg" + color[0].toUpperCase() + color.slice(1)] = { _bg: [40 + index, 49] };
obj["bg" + color[0].toUpperCase() + color.slice(1) + "Bright"] = { _bg: [100 + index, 49] };
return obj;
}, {})
);
sgr.mods = mods;
sgr.openers = {};
sgr.closers = {};
forOwn(mods, function (mod) {
var modPair = mod[onlyKey(mod)];
sgr.openers[modPair[0]] = modPair;
sgr.closers[modPair[1]] = modPair;
});
sgr.openStyle = function (openedMods, code) { openedMods.push(sgr.openers[code]); };
sgr.closeStyle = function (openedMods, code) {
forEachRight.call(openedMods, function (modPair, index) {
if (modPair[1] === code) {
openedMods.splice(index, 1);
}
});
};
/* prepend openers */
sgr.prepend = function (currentMods) {
return currentMods.map(function (modPair) { return sgr(modPair[0]); });
};
/* complete non-closed openers with corresponding closers */
sgr.complete = function (openedMods, closerCodes) {
closerCodes.forEach(function (code) { sgr.closeStyle(openedMods, code); });
// mods must be closed from the last opened to first opened
openedMods = openedMods.reverse();
openedMods = openedMods.map(function (modPair) { return modPair[1]; });
// one closer can close many openers (31, 32 -> 39)
openedMods = uniq.call(openedMods);
return openedMods.map(sgr);
};
var hasCSI = function (str) { return includes.call(str, CSI); };
sgr.hasCSI = hasCSI;
var extractCode = function (csi) {
var code = csi.slice(2, -1);
code = Number(code);
return code;
};
sgr.extractCode = extractCode;
module.exports = sgr;
cli-color-2.0.2/lib/supports-color.js 0000664 0000000 0000000 00000001225 14221323132 0017506 0 ustar 00root root 0000000 0000000 "use strict";
// store whether supports-color mode is enabled or not.
var state = null;
// force supports-color mode
var enableColor = function () { state = true; };
// disable supports-color mode
var disableColor = function () { state = false; };
// use the NO_COLOR environment variable (default)
var autoDetectSupport = function () { state = null; };
// determine whether supports-color mode is enabled.
var isColorSupported = function () { return state === null ? !process.env.NO_COLOR : state; };
module.exports = {
enableColor: enableColor,
disableColor: disableColor,
autoDetectSupport: autoDetectSupport,
isColorSupported: isColorSupported
};
cli-color-2.0.2/lib/xterm-colors.js 0000664 0000000 0000000 00000005101 14221323132 0017126 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = [
"000000", "800000", "008000", "808000", "000080", "800080", "008080", "c0c0c0", "808080",
"ff0000", "00ff00", "ffff00", "0000ff", "ff00ff", "00ffff", "ffffff", "000000", "00005f",
"000087", "0000af", "0000d7", "0000ff", "005f00", "005f5f", "005f87", "005faf", "005fd7",
"005fff", "008700", "00875f", "008787", "0087af", "0087d7", "0087ff", "00af00", "00af5f",
"00af87", "00afaf", "00afd7", "00afff", "00d700", "00d75f", "00d787", "00d7af", "00d7d7",
"00d7ff", "00ff00", "00ff5f", "00ff87", "00ffaf", "00ffd7", "00ffff", "5f0000", "5f005f",
"5f0087", "5f00af", "5f00d7", "5f00ff", "5f5f00", "5f5f5f", "5f5f87", "5f5faf", "5f5fd7",
"5f5fff", "5f8700", "5f875f", "5f8787", "5f87af", "5f87d7", "5f87ff", "5faf00", "5faf5f",
"5faf87", "5fafaf", "5fafd7", "5fafff", "5fd700", "5fd75f", "5fd787", "5fd7af", "5fd7d7",
"5fd7ff", "5fff00", "5fff5f", "5fff87", "5fffaf", "5fffd7", "5fffff", "870000", "87005f",
"870087", "8700af", "8700d7", "8700ff", "875f00", "875f5f", "875f87", "875faf", "875fd7",
"875fff", "878700", "87875f", "878787", "8787af", "8787d7", "8787ff", "87af00", "87af5f",
"87af87", "87afaf", "87afd7", "87afff", "87d700", "87d75f", "87d787", "87d7af", "87d7d7",
"87d7ff", "87ff00", "87ff5f", "87ff87", "87ffaf", "87ffd7", "87ffff", "af0000", "af005f",
"af0087", "af00af", "af00d7", "af00ff", "af5f00", "af5f5f", "af5f87", "af5faf", "af5fd7",
"af5fff", "af8700", "af875f", "af8787", "af87af", "af87d7", "af87ff", "afaf00", "afaf5f",
"afaf87", "afafaf", "afafd7", "afafff", "afd700", "afd75f", "afd787", "afd7af", "afd7d7",
"afd7ff", "afff00", "afff5f", "afff87", "afffaf", "afffd7", "afffff", "d70000", "d7005f",
"d70087", "d700af", "d700d7", "d700ff", "d75f00", "d75f5f", "d75f87", "d75faf", "d75fd7",
"d75fff", "d78700", "d7875f", "d78787", "d787af", "d787d7", "d787ff", "d7af00", "d7af5f",
"d7af87", "d7afaf", "d7afd7", "d7afff", "d7d700", "d7d75f", "d7d787", "d7d7af", "d7d7d7",
"d7d7ff", "d7ff00", "d7ff5f", "d7ff87", "d7ffaf", "d7ffd7", "d7ffff", "ff0000", "ff005f",
"ff0087", "ff00af", "ff00d7", "ff00ff", "ff5f00", "ff5f5f", "ff5f87", "ff5faf", "ff5fd7",
"ff5fff", "ff8700", "ff875f", "ff8787", "ff87af", "ff87d7", "ff87ff", "ffaf00", "ffaf5f",
"ffaf87", "ffafaf", "ffafd7", "ffafff", "ffd700", "ffd75f", "ffd787", "ffd7af", "ffd7d7",
"ffd7ff", "ffff00", "ffff5f", "ffff87", "ffffaf", "ffffd7", "ffffff", "080808", "121212",
"1c1c1c", "262626", "303030", "3a3a3a", "444444", "4e4e4e", "585858", "626262", "6c6c6c",
"767676", "808080", "8a8a8a", "949494", "9e9e9e", "a8a8a8", "b2b2b2", "bcbcbc", "c6c6c6",
"d0d0d0", "dadada", "e4e4e4", "eeeeee"
];
cli-color-2.0.2/lib/xterm-match.js 0000664 0000000 0000000 00000001654 14221323132 0016732 0 ustar 00root root 0000000 0000000 "use strict";
var push = Array.prototype.push
, reduce = Array.prototype.reduce
, abs = Math.abs
, colors
, match
, result
, i;
colors = require("./xterm-colors").map(function (color) {
return {
r: parseInt(color.slice(0, 2), 16),
g: parseInt(color.slice(2, 4), 16),
b: parseInt(color.slice(4), 16)
};
});
match = colors.slice(0, 16);
module.exports = result = [];
i = 0;
while (i < 8) {
result.push(30 + i++);
}
i = 0;
while (i < 8) {
result.push(90 + i++);
}
push.apply(
result,
colors.slice(16).map(function (data) {
var index, diff = Infinity;
match.every(function (innerMatch, currentIndex) {
var ndiff = reduce.call(
"rgb",
function (currentDiff, channel) {
currentDiff += abs(innerMatch[channel] - data[channel]);
return currentDiff;
},
0
);
if (ndiff < diff) {
index = currentIndex;
diff = ndiff;
}
return ndiff;
});
return result[index];
})
);
cli-color-2.0.2/move.js 0000664 0000000 0000000 00000002076 14221323132 0014700 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("d")
, trunc = require("es5-ext/math/trunc");
var up, down, right, left, abs = Math.abs, floor = Math.floor, max = Math.max;
var getMove = function (control) {
return function (num) {
num = isNaN(num) ? 0 : max(floor(num), 0);
return num ? "\x1b[" + num + control : "";
};
};
module.exports = Object.defineProperties(
function (x, y) {
x = isNaN(x) ? 0 : floor(x);
y = isNaN(y) ? 0 : floor(y);
return (x > 0 ? right(x) : left(-x)) + (y > 0 ? down(y) : up(-y));
},
{
up: d((up = getMove("A"))),
down: d((down = getMove("B"))),
right: d((right = getMove("C"))),
left: d((left = getMove("D"))),
to: d(function (x, y) {
x = isNaN(x) ? 1 : max(floor(x), 0) + 1;
y = isNaN(y) ? 1 : max(floor(y), 0) + 1;
return "\x1b[" + y + ";" + x + "H";
}),
lines: d(function (n) {
var dir;
n = trunc(n) || 0;
dir = n >= 0 ? "B" : "A";
n = floor(abs(n));
return "\x1b[" + n + dir + "\x1b[1G";
}),
top: d("\x1b[5000F"),
bottom: d("\x1b[5000B"),
lineBegin: d("\x1b[5000D"),
lineEnd: d("\x1b[5000C")
}
);
cli-color-2.0.2/package.json 0000664 0000000 0000000 00000004564 14221323132 0015666 0 ustar 00root root 0000000 0000000 {
"name": "cli-color",
"version": "2.0.2",
"description": "Colors, formatting and other tools for the console",
"author": "Mariusz Nowak (http://www.medikoo.com/)",
"keywords": [
"ansi",
"color",
"console",
"terminal",
"cli",
"shell",
"log",
"logging",
"xterm"
],
"repository": {
"type": "git",
"url": "git://github.com/medikoo/cli-color.git"
},
"dependencies": {
"d": "^1.0.1",
"es5-ext": "^0.10.59",
"es6-iterator": "^2.0.3",
"memoizee": "^0.4.15",
"timers-ext": "^0.1.7"
},
"devDependencies": {
"eslint": "^8.12.0",
"eslint-config-medikoo": "^4.1.2",
"git-list-updated": "^1.2.1",
"github-release-from-cc-changelog": "^2.2.1",
"husky": "^4.3.8",
"lint-staged": "^11.2.6",
"nyc": "^15.1.0",
"prettier-elastic": "^2.2.1",
"tad": "^3.1.0"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"eslintConfig": {
"extends": "medikoo/node/es5",
"root": true,
"rules": {
"id-length": "off"
},
"overrides": [
{
"files": "examples/**",
"rules": {
"no-console": "off"
}
}
]
},
"prettier": {
"printWidth": 100,
"tabWidth": 4,
"overrides": [
{
"files": [
"*.md",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
},
"nyc": {
"all": true,
"exclude": [
".github",
"coverage/**",
"examples",
"test/**",
"*.config.js"
],
"reporter": [
"lcov",
"html",
"text-summary"
]
},
"scripts": {
"coverage": "nyc npm test",
"lint": "eslint --ignore-path=.gitignore .",
"lint:updated": "pipe-git-updated --ext=js -- eslint --ignore-pattern '!*'",
"prepare-release": "standard-version && prettier --write CHANGELOG.md",
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettier-check:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
"prettify:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
"test": "tad"
},
"engines": {
"node": ">=0.10"
},
"license": "ISC"
}
cli-color-2.0.2/regex-ansi.js 0000664 0000000 0000000 00000000657 14221323132 0015777 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function () {
// Borrowed from ansi-regex package
// https://github.com/chalk/ansi-regex/blob/a28b8e7ee67aa9996ba44bf123f0436eea62d285/index.js
return new RegExp(
"[\\u001B\\u009B][[\\]()#;?]" +
"*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]" +
"+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" +
"|" +
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
"g"
);
};
cli-color-2.0.2/reset.js 0000664 0000000 0000000 00000000064 14221323132 0015047 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = "\x1b[2J\x1b[0;0H";
cli-color-2.0.2/slice.js 0000664 0000000 0000000 00000006376 14221323132 0015040 0 ustar 00root root 0000000 0000000 /* eslint max-lines: "off" */
"use strict";
var reAnsi = require("./regex-ansi")
, stringifiable = require("es5-ext/object/validate-stringifiable-value")
, length = require("./get-stripped-length")
, sgr = require("./lib/sgr")
, max = Math.max;
var Token = function (token) { this.token = token; };
var tokenize = function (str) {
var match = reAnsi().exec(str);
if (!match) {
return [str];
}
var index = match.index, head, prehead, tail;
if (index === 0) {
head = match[0];
tail = str.slice(head.length);
return [new Token(head)].concat(tokenize(tail));
}
prehead = str.slice(0, index);
head = match[0];
tail = str.slice(index + head.length);
return [prehead, new Token(head)].concat(tokenize(tail));
};
var isChunkInSlice = function (chunk, index, begin, end) {
var endIndex = chunk.length + index;
if (begin > endIndex) return false;
if (end < index) return false;
return true;
};
// eslint-disable-next-line max-lines-per-function
var sliceSeq = function (seq, begin, end) {
var sliced = seq.reduce(
function (state, chunk) {
var index = state.index;
if (chunk instanceof Token) {
var code = sgr.extractCode(chunk.token);
if (index <= begin) {
if (code in sgr.openers) {
sgr.openStyle(state.preOpeners, code);
}
if (code in sgr.closers) {
sgr.closeStyle(state.preOpeners, code);
}
} else if (index < end) {
if (code in sgr.openers) {
sgr.openStyle(state.inOpeners, code);
state.seq.push(chunk);
} else if (code in sgr.closers) {
state.inClosers.push(code);
state.seq.push(chunk);
}
}
} else {
var nextChunk = "";
if (isChunkInSlice(chunk, index, begin, end)) {
var relBegin = Math.max(begin - index, 0)
, relEnd = Math.min(end - index, chunk.length);
nextChunk = chunk.slice(relBegin, relEnd);
}
state.seq.push(nextChunk);
state.index = index + chunk.length;
}
return state;
},
{
index: 0,
seq: [],
// preOpeners -> [ mod ]
// preOpeners must be prepended to the slice if they wasn't closed til the end of it
// preOpeners must be closed if they wasn't closed til the end of the slice
preOpeners: [],
// inOpeners -> [ mod ]
// inOpeners already in the slice and must not be prepended to the slice
// inOpeners must be closed if they wasn't closed til the end of the slice
inOpeners: [], // opener CSI inside slice
// inClosers -> [ code ]
// closer CSIs for determining which pre/in-Openers must be closed
inClosers: []
}
);
sliced.seq = [].concat(
sgr.prepend(sliced.preOpeners), sliced.seq,
sgr.complete([].concat(sliced.preOpeners, sliced.inOpeners), sliced.inClosers)
);
return sliced.seq;
};
module.exports = function (str /*, begin, end*/) {
var seq, begin = Number(arguments[1]), end = Number(arguments[2]), len;
str = stringifiable(str);
len = length(str);
if (isNaN(begin)) {
begin = 0;
}
if (isNaN(end)) {
end = len;
}
if (begin < 0) {
begin = max(len + begin, 0);
}
if (end < 0) {
end = max(len + end, 0);
}
seq = tokenize(str);
seq = sliceSeq(seq, begin, end);
return seq
.map(function (chunk) {
if (chunk instanceof Token) {
return chunk.token;
}
return chunk;
})
.join("");
};
cli-color-2.0.2/strip.js 0000664 0000000 0000000 00000000371 14221323132 0015067 0 ustar 00root root 0000000 0000000 // Strip ANSI formatting from string
"use strict";
var stringifiable = require("es5-ext/object/validate-stringifiable")
, r = require("./regex-ansi")();
module.exports = function (str) { return stringifiable(str).replace(r, ""); };
cli-color-2.0.2/test/ 0000775 0000000 0000000 00000000000 14221323132 0014346 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/test/__playground/ 0000775 0000000 0000000 00000000000 14221323132 0017030 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/test/__playground/throbber.formatted.js 0000775 0000000 0000000 00000000457 14221323132 0023172 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
"use strict";
var setupThrobber = require("../../throbber")
, format = require("../../index").red
, throbber = setupThrobber(process.stdout.write.bind(process.stdout), 200, format);
process.stdout.write("START");
throbber.start();
setTimeout(throbber.stop, 1100);
cli-color-2.0.2/test/__playground/throbber.js 0000775 0000000 0000000 00000000370 14221323132 0021200 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
"use strict";
var setupThrobber = require("../../throbber")
, throbber = setupThrobber(process.stdout.write.bind(process.stdout), 200);
process.stdout.write("START");
throbber.start();
setTimeout(throbber.stop, 1100);
cli-color-2.0.2/test/_lib/ 0000775 0000000 0000000 00000000000 14221323132 0015253 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/test/_lib/supports-color-wrapper.js 0000664 0000000 0000000 00000000516 14221323132 0022304 0 ustar 00root root 0000000 0000000 "use strict";
var supportsColor = require("../../lib/supports-color");
// a wrapper function which automatically forces color mode to enabled during the tests.
module.exports = function (fn) {
return function (t, a) {
supportsColor.enableColor();
try { return fn(t, a); }
finally { supportsColor.autoDetectSupport(); }
};
};
cli-color-2.0.2/test/art.js 0000664 0000000 0000000 00000001303 14221323132 0015467 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
var wrapper = require("./_lib/supports-color-wrapper");
module.exports = wrapper(function (t, a) {
a(
t("ooo", { o: clc.yellow("x") }), "\x1b[33mx\x1b[39m\x1b[33mx\x1b[39m\x1b[33mx\x1b[39m",
"Basic art"
);
a(t("oyo", { o: clc.yellow("x") }), "\x1b[33mx\x1b[39my\x1b[33mx\x1b[39m", "Free text art");
a(t("o o", { o: clc.yellow("x") }), "\x1b[33mx\x1b[39m \x1b[33mx\x1b[39m", "Spaced art");
a(
t("<=>", { "<": clc.yellow("<"), ">": clc.yellow(">") }),
"\x1b[33m<\x1b[39m=\x1b[33m>\x1b[39m", "Symbol art"
);
a(t("o\no", { o: clc.yellow("x") }), "\x1b[33mx\x1b[39m\n\x1b[33mx\x1b[39m", "Multiline art");
a(t("ooo", {}), "ooo", "Only text art");
});
cli-color-2.0.2/test/bare.js 0000664 0000000 0000000 00000033367 14221323132 0015631 0 ustar 00root root 0000000 0000000 "use strict";
var supportsColor = require("../lib/supports-color");
var wrapper = require("./_lib/supports-color-wrapper");
module.exports = wrapper(function (t, a) {
var x, y;
a(t("test"), "test", "Plain");
a(
t("test", "foo", 3, { toString: function () { return "bar"; } }), "test foo 3 bar",
"Plain: Many args"
);
a(t.red("foo"), "\x1b[31mfoo\x1b[39m", "Foreground");
a(t.red("foo", "bar", 3), "\x1b[31mfoo bar 3\x1b[39m", "Foreground: Many args");
a(t.red.yellow("foo", "bar", 3), "\x1b[33mfoo bar 3\x1b[39m", "Foreground: Overriden");
a(t.bgRed("foo", "bar"), "\x1b[41mfoo bar\x1b[49m", "Background");
a(t.bgRed.bgYellow("foo", "bar", 3), "\x1b[43mfoo bar 3\x1b[49m", "Background: Overriden");
a(
t.blue.bgYellow("foo", "bar"), "\x1b[43m\x1b[34mfoo bar\x1b[39m\x1b[49m",
"Foreground & Background"
);
a(
t.blue.bgYellow.red.bgMagenta("foo", "bar"), "\x1b[45m\x1b[31mfoo bar\x1b[39m\x1b[49m",
"Foreground & Background: Overriden"
);
a(t.bold("foo", "bar"), "\x1b[1mfoo bar\x1b[22m", "Format");
a(t.blink("foobar"), "\x1b[5mfoobar\x1b[25m", "Format: blink");
a(
t.bold.blue("foo", "bar", 3), "\x1b[1m\x1b[34mfoo bar 3\x1b[39m\x1b[22m",
"Foreground & Format"
);
a(t.redBright("foo", "bar"), "\x1b[91mfoo bar\x1b[39m", "Bright");
a(t.bgRedBright("foo", 3), "\x1b[101mfoo 3\x1b[49m", "Bright background");
a(
t.blueBright.bgYellowBright.red.bgMagenta("foo", "bar"),
"\x1b[45m\x1b[31mfoo bar\x1b[39m\x1b[49m", "Foreground & Background: Bright: Overriden"
);
a(t.red.blue("foo"), "\x1b[34mfoo\x1b[39m", "Prioritize the Last Color: Blue");
a(t.blue.red("foo"), "\x1b[31mfoo\x1b[39m", "Prioritize the Last Color: Red");
a(t.bgRed.bgBlue("foo"), "\x1b[44mfoo\x1b[49m", "Prioritize the Last Background Color: Blue");
a(t.bgBlue.bgRed("foo"), "\x1b[41mfoo\x1b[49m", "Prioritize the Last Background Color: Red");
a(
t.bgRed.red.bgBlue.blue("foo"), "\x1b[44m\x1b[34mfoo\x1b[39m\x1b[49m",
"Prioritize the Last Mixed Style: Blue"
);
a(
t.bgBlue.blue.bgRed.red("foo"), "\x1b[41m\x1b[31mfoo\x1b[39m\x1b[49m",
"Prioritize the Last Mixed Style: Red"
);
a(
t.bgRed.blue.bgBlue.red("foo"), "\x1b[44m\x1b[31mfoo\x1b[39m\x1b[49m",
"Prioritize the Last Mixed Style: BG Blue and Red"
);
a(
t.bgBlue.red.bgRed.blue("foo"), "\x1b[41m\x1b[34mfoo\x1b[39m\x1b[49m",
"Prioritize the Last Mixed Style: BG Red and Blue"
);
a(
t.bold("bold " + t.whiteBright("whiteBright ") + "bold"),
"\x1b[1mbold \x1b[97mwhiteBright \x1b[39mbold\x1b[22m", "Nested Format: Bold Type 1"
);
a(
t.white("white " + t.bold("bold ") + "white"),
"\x1b[37mwhite \x1b[1mbold \x1b[22mwhite\x1b[39m", "Nested Format: Bold Type 2"
);
a(
t.italic("italic " + t.whiteBright("whiteBright ") + "italic"),
"\x1b[3mitalic \x1b[97mwhiteBright \x1b[39mitalic\x1b[23m", "Nested Format: Italic"
);
a(
t.white("white " + t.italic("italic ") + "white"),
"\x1b[37mwhite \x1b[3mitalic \x1b[23mwhite\x1b[39m", "Nested Format: Italic Type 2"
);
a(
t.underline("underline " + t.whiteBright("whiteBright ") + "underline"),
"\x1b[4munderline \x1b[97mwhiteBright \x1b[39munderline\x1b[24m", "Nested Format: Underline"
);
a(
t.white("white " + t.underline("underline ") + "white"),
"\x1b[37mwhite \x1b[4munderline \x1b[24mwhite\x1b[39m", "Nested Format: Underline Type 2"
);
a(
t.blink("blink " + t.whiteBright("whiteBright ") + "blink"),
"\x1b[5mblink \x1b[97mwhiteBright \x1b[39mblink\x1b[25m", "Nested Format: Blink"
);
a(
t.white("white " + t.blink("blink ") + "white"),
"\x1b[37mwhite \x1b[5mblink \x1b[25mwhite\x1b[39m", "Nested Format: Blink Type 2"
);
a(
t.inverse("inverse " + t.whiteBright("whiteBright ") + "inverse"),
"\x1b[7minverse \x1b[97mwhiteBright \x1b[39minverse\x1b[27m", "Nested Format: Inverse"
);
a(
t.white("white " + t.inverse("inverse ") + "white"),
"\x1b[37mwhite \x1b[7minverse \x1b[27mwhite\x1b[39m", "Nested Format: Inverse Type 2"
);
a(
t.strike("strike " + t.whiteBright("whiteBright ") + "strike"),
"\x1b[9mstrike \x1b[97mwhiteBright \x1b[39mstrike\x1b[29m", "Nested Format: Strike"
);
a(
t.white("white " + t.strike("strike ") + "white"),
"\x1b[37mwhite \x1b[9mstrike \x1b[29mwhite\x1b[39m", "Nested Format: Strike Type 2"
);
a(
t.red("red " + t.blue("blue ")), "\x1b[31mred \x1b[34mblue \x1b[31m\x1b[39m",
"Nested Foreground: Two Levels Type 1"
);
a(
t.red(t.blue("blue ") + "red"), "\x1b[31m\x1b[34mblue \x1b[31mred\x1b[39m",
"Nested Foreground: Two Levels Type 2"
);
a(
t.red("red " + t.blue("blue ") + "red"), "\x1b[31mred \x1b[34mblue \x1b[31mred\x1b[39m",
"Nested Foreground: Two Levels Type 3"
);
a(
t.red("red " + t.blue("blue " + t.green("green ")) + "red"),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[34m\x1b[31mred\x1b[39m",
"Nested Foreground: Three Levels Type 1"
);
a(
t.red("red " + t.blue("blue " + t.green("green ") + "blue ") + "red"),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[34mblue \x1b[31mred\x1b[39m",
"Nested Foreground: Three Levels Type 2"
);
a(
t.red("red " + t.blue("blue " + t.green("green ")) + t.green("green ") + "red"),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[34m" +
"\x1b[31m\x1b[32mgreen \x1b[31mred\x1b[39m",
"Nested Foreground: Three Levels Type 3"
);
a(
t.red("red " + t.blue("blue " + t.green("green ") + t.yellow("yellow ")) + "red"),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[34m" +
"\x1b[33myellow \x1b[34m\x1b[31mred\x1b[39m",
"Nested Foreground: Three Levels Type 4"
);
a(
t.red("red " + t.blue("blue " + t.green("green ") + "blue " + t.yellow("yellow ")) + "red"),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[34mblue \x1b[33myellow " +
"\x1b[34m\x1b[31mred\x1b[39m",
"Nested Foreground: Three Levels Type 5"
);
a(
t.red(
"red " + t.blue("blue " + t.green("green " + t.yellow("yellow ") + "green ")) + "red"
),
"\x1b[31mred \x1b[34mblue \x1b[32mgreen \x1b[33myellow \x1b[32mgreen " +
"\x1b[34m\x1b[31mred\x1b[39m",
"Nested Foreground: Four Levels"
);
a(
t.red("\x1bAred"), "\x1b[31m\x1bAred\x1b[39m",
"Nested Foreground: Trap Type 1 - Not a Style Before"
);
a(
t.red("red\x1bA"), "\x1b[31mred\x1bA\x1b[39m",
"Nested Foreground: Trap Type 2 - Not a Style After"
);
a(
t.red("\x1bAred\x1bA"), "\x1b[31m\x1bAred\x1bA\x1b[39m",
"Nested Foreground: Trap Type 3 - Not a Style Around"
);
a(
t.red("\x1b34m\x1b39m"), "\x1b[31m\x1b34m\x1b39m\x1b[39m",
"Nested Foreground: Trap Type 4 - Not a Valid Style"
);
a(
t.red("\x1b[34m\x1b[39m"), "\x1b[31m\x1b[34m\x1b[31m\x1b[39m",
"Nested Foreground: Trap Type 5 - No Message Style"
);
a(
t.red("\x1b[34m\x1b[39m\x1b[34mblue\x1b[39m"),
"\x1b[31m\x1b[34m\x1b[31m\x1b[34mblue\x1b[31m\x1b[39m",
"Nested Foreground: Trap Type 6 - No Message Style Before"
);
a(
t.red("\x1b[34mblue\x1b[39m\x1b[34m\x1b[39m"),
"\x1b[31m\x1b[34mblue\x1b[31m\x1b[34m\x1b[31m\x1b[39m",
"Nested Foreground: Trap Type 7 - No Message Style After"
);
a(
t.red("\x1b[34m\x1b[39m\x1b[34mblue\x1b[39m\x1b[34m\x1b[39m"),
"\x1b[31m\x1b[34m\x1b[31m\x1b[34mblue\x1b[31m\x1b[34m\x1b[31m\x1b[39m",
"Nested Foreground: Trap Type 8 - No Message Style Around"
);
a(
t.bgRed("red " + t.bgBlue("blue ")), "\x1b[41mred \x1b[44mblue \x1b[41m\x1b[49m",
"Nested Background: Two Levels Type 1"
);
a(
t.bgRed(t.bgBlue("blue ") + "red"), "\x1b[41m\x1b[44mblue \x1b[41mred\x1b[49m",
"Nested Background: Two Levels Type 2"
);
a(
t.bgRed("red " + t.bgBlue("blue ") + "red"), "\x1b[41mred \x1b[44mblue \x1b[41mred\x1b[49m",
"Nested Background: Two Levels Type 3"
);
a(
t.bgRed("red " + t.bgBlue("blue " + t.bgGreen("green ")) + "red"),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[44m\x1b[41mred\x1b[49m",
"Nested Background: Three Levels Type 1"
);
a(
t.bgRed("red " + t.bgBlue("blue " + t.bgGreen("green ") + "blue ") + "red"),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[44mblue \x1b[41mred\x1b[49m",
"Nested Background: Three Levels Type 2"
);
a(
t.bgRed("red " + t.bgBlue("blue " + t.bgGreen("green ")) + t.bgGreen("green ") + "red"),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[44m" +
"\x1b[41m\x1b[42mgreen \x1b[41mred\x1b[49m",
"Nested Background: Three Levels Type 3"
);
a(
t.bgRed("red " + t.bgBlue("blue " + t.bgGreen("green ") + t.bgYellow("yellow ")) + "red"),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[44m" +
"\x1b[43myellow \x1b[44m\x1b[41mred\x1b[49m",
"Nested Background: Three Levels Type 4"
);
a(
t.bgRed(
"red " +
t.bgBlue("blue " + t.bgGreen("green ") + "blue " + t.bgYellow("yellow ")) +
"red"
),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[44mblue \x1b[43myellow " +
"\x1b[44m\x1b[41mred\x1b[49m",
"Nested Background: Three Levels Type 5"
);
a(
t.bgRed(
"red " +
t.bgBlue("blue " + t.bgGreen("green " + t.bgYellow("yellow ") + "green ")) +
"red"
),
"\x1b[41mred \x1b[44mblue \x1b[42mgreen \x1b[43myellow \x1b[42mgreen " +
"\x1b[44m\x1b[41mred\x1b[49m",
"Nested Background: Four Levels"
);
a(
t.bgRed("\x1bAred"), "\x1b[41m\x1bAred\x1b[49m",
"Nested Background: Trap Type 1 - Not a Style Before"
);
a(
t.bgRed("red\x1bA"), "\x1b[41mred\x1bA\x1b[49m",
"Nested Background: Trap Type 2 - Not a Style After"
);
a(
t.bgRed("\x1bAred\x1bA"), "\x1b[41m\x1bAred\x1bA\x1b[49m",
"Nested Background: Trap Type 3 - Not a Style Around"
);
a(
t.bgRed("\x1b44m\x1b39m"), "\x1b[41m\x1b44m\x1b39m\x1b[49m",
"Nested Background: Trap Type 4 - Not a Valid Style"
);
a(
t.bgRed("\x1b[44m\x1b[49m"), "\x1b[41m\x1b[44m\x1b[41m\x1b[49m",
"Nested Background: Trap Type 5 - No Message Style"
);
a(
t.bgRed("\x1b[44m\x1b[49m\x1b[44mblue\x1b[49m"),
"\x1b[41m\x1b[44m\x1b[41m\x1b[44mblue\x1b[41m\x1b[49m",
"Nested Background: Trap Type 6 - No Message Style Before"
);
a(
t.bgRed("\x1b[44mblue\x1b[49m\x1b[44m\x1b[49m"),
"\x1b[41m\x1b[44mblue\x1b[41m\x1b[44m\x1b[41m\x1b[49m",
"Nested Background: Trap Type 7 - No Message Style After"
);
a(
t.bgRed("\x1b[44m\x1b[49m\x1b[44mblue\x1b[49m\x1b[44m\x1b[49m"),
"\x1b[41m\x1b[44m\x1b[41m\x1b[44mblue\x1b[41m\x1b[44m\x1b[41m\x1b[49m",
"Nested Background: Trap Type 8 - No Message Style Around"
);
a(
t.red("red " + t.bgBlue("blue ")), "\x1b[31mred \x1b[44mblue \x1b[49m\x1b[39m",
"Nested Foreground and Background: Two Levels Type 1"
);
a(
t.red("red " + t.bgBlue("blue ") + t.white("white")),
"\x1b[31mred \x1b[44mblue \x1b[49m\x1b[37mwhite\x1b[31m\x1b[39m",
"Nested Foreground and Background: Two Levels Type 2"
);
a(
t.red("red " + t.bgBlue("blue ") + "red"), "\x1b[31mred \x1b[44mblue \x1b[49mred\x1b[39m",
"Nested Foreground and Background: Two Levels Type 3"
);
a(
t.bgBlue("blue " + t.bgRed("red " + t.whiteBright("white ") + "red ") + "blue"),
"\x1b[44mblue \x1b[41mred \x1b[97mwhite \x1b[39mred \x1b[44mblue\x1b[49m",
"Nested Foreground and Background: Two Levels Type 3"
);
a(
t.red.bgWhite("white " + t.bgBlue("blue")),
"\x1b[47m\x1b[31mwhite \x1b[44mblue\x1b[47m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Mixed Type 1"
);
a(
t.red.bgWhite("white " + t.blue("blue")),
"\x1b[47m\x1b[31mwhite \x1b[34mblue\x1b[31m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Mixed Type 2"
);
a(
t.red.bgWhite("white " + t.blue("blue ") + "white"),
"\x1b[47m\x1b[31mwhite \x1b[34mblue \x1b[31mwhite\x1b[39m\x1b[49m",
"Nested Foreground and Background: Mixed Type 3"
);
a(
t.red.bgWhite("\x1bAred"), "\x1b[47m\x1b[31m\x1bAred\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 1 - Not a Style Before"
);
a(
t.red.bgWhite("red\x1bA"), "\x1b[47m\x1b[31mred\x1bA\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 2 - Not a Style After"
);
a(
t.red.bgWhite("\x1bAred\x1bA"), "\x1b[47m\x1b[31m\x1bAred\x1bA\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 3 - Not a Style Around"
);
a(
t.red.bgWhite("\x1b34m\x1b39m"), "\x1b[47m\x1b[31m\x1b34m\x1b39m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 4 - Not a Valid Style"
);
a(
t.red.bgWhite("\x1b[34m\x1b[39m"), "\x1b[47m\x1b[31m\x1b[34m\x1b[31m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 5 - No Message Style"
);
a(
t.red.bgWhite("\x1b[44m\x1b[49m"), "\x1b[47m\x1b[31m\x1b[44m\x1b[47m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 6 - No Message Style"
);
a(
t.red.bgWhite("\x1b[44m\x1b[49m\x1b[44mblue\x1b[49m"),
"\x1b[47m\x1b[31m\x1b[44m\x1b[47m\x1b[44mblue\x1b[47m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 7 - No Message Style Before"
);
a(
t.red.bgWhite("\x1b[44mblue\x1b[49m\x1b[44m\x1b[49m"),
"\x1b[47m\x1b[31m\x1b[44mblue\x1b[47m\x1b[44m\x1b[47m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 8 - No Message Style After"
);
a(
t.red.bgWhite("\x1b[44m\x1b[49m\x1b[44mblue\x1b[49m\x1b[44m\x1b[49m"),
"\x1b[47m\x1b[31m\x1b[44m\x1b[47m\x1b[44mblue\x1b[47m\x1b[44m\x1b[47m\x1b[39m\x1b[49m",
"Nested Foreground and Background: Trap Type 9 - No Message Style Around"
);
x = t.red;
y = x.bold;
a(
x("foo", "red") + " " + y("foo", "boldred"),
"\x1b[31mfoo red\x1b[39m \x1b[1m\x1b[31mfoo boldred\x1b[39m\x1b[22m", "Detached extension"
);
if (t.xtermSupported) {
a(
t.xterm(12).bgXterm(67)("foo", "xterm"),
"\x1b[48;5;67m\x1b[38;5;12mfoo xterm\x1b[39m\x1b[49m", "Xterm"
);
a(
t.redBright.bgBlueBright.xterm(12).bgXterm(67)("foo", "xterm"),
"\x1b[48;5;67m\x1b[38;5;12mfoo xterm\x1b[39m\x1b[49m", "Xterm: Override & Bright"
);
a(
t.xterm(12).bgXterm(67).redBright.bgMagentaBright("foo", "xterm"),
"\x1b[105m\x1b[91mfoo xterm\x1b[39m\x1b[49m", "Xterm: Override & Bright #2"
);
} else {
a(
t.xterm(12).bgXterm(67)("foo", "xterm"), "\x1b[100m\x1b[94mfoo xterm\x1b[39m\x1b[49m",
"Xterm"
);
}
supportsColor.disableColor();
a(t.red("foo"), "foo", "Foreground with NO_COLOR");
a(t.bgRed("foo", "bar"), "foo bar", "Background with NO_COLOR");
a(t.blue.bgYellow("foo", "bar"), "foo bar", "Foreground & Background with NO_COLOR");
});
cli-color-2.0.2/test/beep.js 0000664 0000000 0000000 00000000103 14221323132 0015611 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) { a(t, "\x07"); };
cli-color-2.0.2/test/columns.js 0000664 0000000 0000000 00000002042 14221323132 0016362 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(t([]), "\n", "Empty #1");
a(t([[], [], []]), "\n\n\n", "Empty #2");
a(t([["A", "BC", "DEF"]]), "A | BC | DEF\n", "Header Only");
a(
t([
["A", "BC", "DEF"], [1, 23, 456]
]),
"A | BC | DEF\n1 | 23 | 456\n",
"Small items"
);
a(
t([
["A", "BC", "DEF"], [12, 234, 4567]
]),
"A | BC | DEF \n12 | 234 | 4567\n",
"Large items"
);
a(
t([
["A", "BC", "DEF"], [1234, 23456, 456789]
]),
"A | BC | DEF \n1234 | 23456 | 456789\n",
"Very large items"
);
a(t([["A"], [1], [23], [456]]), "A \n1 \n23 \n456\n", "Single column");
a(t([["ID"], [1], [1, 23], [1, 23, 456]]), "ID\n1 \n1 | 23\n1 | 23 | 456\n", "Force columns");
a(
t([
["ONE", "TWO", "THREE"], ["ON", "DWA\nTRZY", "DWA\nTRZY\nCZTERY"], ["HOPLA", "B", "C"]
]),
"ONE | TWO | THREE \nON | DWA | DWA \n | TRZY | TRZY \n" +
" | | CZTERY\nHOPLA | B | C \n",
"Rows"
);
a(t([["ID"], ["", ""], [123, 123]]), "ID \n | \n123 | 123\n", "Empty cells");
};
cli-color-2.0.2/test/erase.js 0000664 0000000 0000000 00000000145 14221323132 0016003 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(t.screen, "\x1b[2J");
a(t.line, "\x1b[2K");
};
cli-color-2.0.2/test/get-stripped-length.js 0000664 0000000 0000000 00000001134 14221323132 0020571 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
var length = t;
a(typeof length, "function");
a(length("ABC"), 3, "Works on plain string");
a(length("\x1b[31mABC\x1b[39m"), 3, "Works on formatted string");
a(length("\x1b[31mABC\x1b[39mDE"), 5, "Works on partially formatted string");
a(length("\x1b[31mABC\x1b[39mDE"), 5, "Works on formatted string by couple of styles");
a(length("\x1b[31mABC\x1b[3mDE\x1b[23m\x1b[39m"), 5, "Works on nested formatted string");
a(
length("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m"), 9,
"Works on nested formatted string with overlapping styles"
);
};
cli-color-2.0.2/test/index.js 0000664 0000000 0000000 00000000521 14221323132 0016011 0 ustar 00root root 0000000 0000000 "use strict";
var bareTests = require("./bare");
module.exports = function (t, a) {
bareTests(t, a);
a(typeof t.windowSize.width, "number", "Width");
a(t.move.up(34), "\x1b[34A", "Up: Positive");
a(t.move(2, 35), "\x1b[2C\x1b[35B", "Move: two positives");
a(t.erase.screen, "\x1b[2J", "Erase");
a(t.beep, "\x07", "Beep");
};
cli-color-2.0.2/test/lib/ 0000775 0000000 0000000 00000000000 14221323132 0015114 5 ustar 00root root 0000000 0000000 cli-color-2.0.2/test/lib/sgr.js 0000664 0000000 0000000 00000001221 14221323132 0016241 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (sgr, a) {
a(sgr(31), "\x1b[31m", "sgr creates set graphic rendition CSIs #1");
a(sgr(39), "\x1b[39m", "sgr creates set graphic rendition CSIs #2");
a(sgr.hasCSI("\x1b[31mA\x1b[39m"), true, "sgr.hasCSI detecs CSIs in string #1");
a(sgr.hasCSI("\x1b[31m"), true, "sgr.hasCSI detecs CSIs in string #2");
a(sgr.hasCSI("[31m"), false, "sgr.hasCSI detecs CSIs in string #3");
a(sgr.hasCSI("A"), false, "sgr.hasCSI detecs CSIs in string #4");
a(sgr.extractCode("\x1b[31m"), 31, "sgr.extractCode extract numeric code of CSI");
a(sgr.extractCode("\x1b[39m"), 39, "sgr.extractCode extract numeric code of CSI");
};
cli-color-2.0.2/test/lib/supports-color.js 0000664 0000000 0000000 00000000606 14221323132 0020467 0 ustar 00root root 0000000 0000000 "use strict";
var wrapper = require("../_lib/supports-color-wrapper");
module.exports = wrapper(function (t, a) {
t.enableColor();
a(t.isColorSupported(), true, "Enable color support NO_COLOR");
t.disableColor();
a(t.isColorSupported(), false, "Disable color support NO_COLOR");
t.autoDetectSupport();
a(t.isColorSupported(), !process.env.NO_COLOR, "use NO_COLOR env variable");
});
cli-color-2.0.2/test/lib/xterm-colors.js 0000664 0000000 0000000 00000000304 14221323132 0020105 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
var re = /^[0-9a-f]{6}$/;
a(t.length, 256, "Length");
t.forEach(function (data, index) { a(re.test(data), true, "In range #" + index); });
};
cli-color-2.0.2/test/lib/xterm-match.js 0000664 0000000 0000000 00000000326 14221323132 0017704 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(t.length, 256, "Length");
t.forEach(function (data, index) {
a((data >= 30 && data <= 37) || (data >= 90 && data <= 97), true, "In range #" + index);
});
};
cli-color-2.0.2/test/move.js 0000664 0000000 0000000 00000002512 14221323132 0015652 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(t.up(), "", "Up: No argument");
a(t.up({}), "", "Up: Not a number");
a(t.up(-34), "", "Up: Negative");
a(t.up(34), "\x1b[34A", "Up: Positive");
a(t.down(), "", "Down: No argument");
a(t.down({}), "", "Down: Not a number");
a(t.down(-34), "", "Down: Negative");
a(t.down(34), "\x1b[34B", "Down: Positive");
a(t.right(), "", "Right: No argument");
a(t.right({}), "", "Right: Not a number");
a(t.right(-34), "", "Right: Negative");
a(t.right(34), "\x1b[34C", "Right: Positive");
a(t.left(), "", "Left: No argument");
a(t.left({}), "", "Left: Not a number");
a(t.left(-34), "", "Left: Negative");
a(t.left(34), "\x1b[34D", "Left: Positive");
a(t(), "", "Move: No arguments");
a(t({}, {}), "", "Move: Bad arguments");
a(t({}, 12), "\x1b[12B", "Move: One direction");
a(t(0, -12), "\x1b[12A", "Move: One negative direction");
a(t(-42, -2), "\x1b[42D\x1b[2A", "Move: two negatives");
a(t(2, 35), "\x1b[2C\x1b[35B", "Move: two positives");
a(t.to(), "\x1b[1;1H", "MoveTo: No arguments");
a(t.to({}, {}), "\x1b[1;1H", "MoveTo: Bad arguments");
a(t.to({}, 12), "\x1b[13;1H", "MoveTo: One direction");
a(t.to(2, -12), "\x1b[1;3H", "MoveTo: One negative direction");
a(t.to(-42, -2), "\x1b[1;1H", "MoveTo: two negatives");
a(t.to(2, 35), "\x1b[36;3H", "MoveTo: two positives");
};
cli-color-2.0.2/test/regex-ansi.js 0000664 0000000 0000000 00000000301 14221323132 0016740 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
var regex = t;
a(typeof regex, "function");
var instance = regex();
a(instance instanceof RegExp, true);
a(instance.global, true);
};
cli-color-2.0.2/test/reset.js 0000664 0000000 0000000 00000000114 14221323132 0016022 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) { a(typeof t, "string"); };
cli-color-2.0.2/test/slice.js 0000664 0000000 0000000 00000011130 14221323132 0015777 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
var slice = t;
a(typeof slice, "function");
a(slice("ABCDE", 1), "BCDE", "Works on plain string");
a(slice("ABCDE", -1), "E", "Works on plain string");
a(slice("ABCDE", 1, 3), "BC", "Works on plain string");
a(slice("ABCDE", -3, -1), "CD", "Works on plain string");
a(
slice("\x1b[31mABCDE\x1b[39m", 1), "\x1b[31mBCDE\x1b[39m",
"Works on whole single forecolor-styled string"
);
a(
slice("\x1b[31mABCDE\x1b[39m", -1), "\x1b[31mE\x1b[39m",
"Works on whole single forecolor-styled string"
);
a(
slice("\x1b[31mABCDE\x1b[39m", 1, 3), "\x1b[31mBC\x1b[39m",
"Works on whole single forecolor-styled string"
);
a(
slice("\x1b[31mABCDE\x1b[39m", -3, -1), "\x1b[31mCD\x1b[39m",
"Works on whole single forecolor-styled string"
);
a(
slice("\x1b[41mABCDE\x1b[49m", 1), "\x1b[41mBCDE\x1b[49m",
"Works on whole single backcolor-styled string"
);
a(
slice("\x1b[41mABCDE\x1b[49m", -1), "\x1b[41mE\x1b[49m",
"Works on whole single backcolor-styled string"
);
a(
slice("\x1b[41mABCDE\x1b[49m", 1, 3), "\x1b[41mBC\x1b[49m",
"Works on whole single backcolor-styled string"
);
a(
slice("\x1b[41mABCDE\x1b[49m", -3, -1), "\x1b[41mCD\x1b[49m",
"Works on whole single backcolor-styled string"
);
a(
slice("ABC\x1b[31mDEF\x1b[39m", 0, 5), "ABC\x1b[31mDE\x1b[39m",
"Save styles when chopping part of the forecolor-styled string"
);
a(
slice("ABC\x1b[31mDEF\x1b[39m", 1, 4), "BC\x1b[31mD\x1b[39m",
"Save styles when chopping part of the forecolor-styled string"
);
a(
slice("ABC\x1b[31mDEF\x1b[39m", 1, 6), "BC\x1b[31mDEF\x1b[39m",
"Save styles when chopping part of the forecolor-styled string"
);
a(
slice("ABC\x1b[31mDEF\x1b[39m", -5, -1), "BC\x1b[31mDE\x1b[39m",
"Save styles when chopping part of the forecolor-styled string"
);
a(
slice("ABC\x1b[41mDEF\x1b[49m", 0, 5), "ABC\x1b[41mDE\x1b[49m",
"Save styles when chopping part of the backcolor-styled string"
);
a(
slice("ABC\x1b[41mDEF\x1b[49m", 1, 4), "BC\x1b[41mD\x1b[49m",
"Save styles when chopping part of the backcolor-styled string"
);
a(
slice("ABC\x1b[41mDEF\x1b[49m", 1, 6), "BC\x1b[41mDEF\x1b[49m",
"Save styles when chopping part of the backcolor-styled string"
);
a(
slice("ABC\x1b[41mDEF\x1b[49m", -5, -1), "BC\x1b[41mDE\x1b[49m",
"Save styles when chopping part of the backcolor-styled string"
);
a(
slice("\x1b[1mAAA\x1b[31mBBB\x1b[39mAAA\x1b[22m", 0, 5),
"\x1b[1mAAA\x1b[31mBB\x1b[39m\x1b[22m", "Works with nested styles #1"
);
a(
slice("\x1b[1mAAA\x1b[31mBBB\x1b[39mAAA\x1b[22m", 2, 7),
"\x1b[1mA\x1b[31mBBB\x1b[39mA\x1b[22m", "Works with nested styles #2"
);
a(
slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", 0, 5),
"\x1b[3mAAA\x1b[41mBB\x1b[49m\x1b[23m", "Works with nested styles #3"
);
a(
slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", 2, 7),
"\x1b[3mA\x1b[41mBBB\x1b[49mA\x1b[23m", "Works with nested styles #4"
);
a(
slice("\x1b[3mAAA\x1b[41mBBB\x1b[49mAAA\x1b[23m", -8, -1),
"\x1b[3mAA\x1b[41mBBB\x1b[49mAA\x1b[23m", "Works with nested styles #5"
);
a(
slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", 0, 5), "\x1b[31mAAA\x1b[32mBB\x1b[39m",
"Works with nested overlapping styles #1"
);
a(
slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", 2, 7),
"\x1b[31mA\x1b[32mBBB\x1b[31mA\x1b[39m", "Works with nested overlapping styles #2"
);
a(
slice("\x1b[31mAAA\x1b[32mBBB\x1b[31mAAA\x1b[39m", -8, -1),
"\x1b[31mAA\x1b[32mBBB\x1b[31mAA\x1b[39m", "Works with nested overlapping styles #3"
);
/* CSI at the edge of slice */
a(slice("ABC\x1b[31mDEF\x1b[39m", 3), "\x1b[31mDEF\x1b[39m", "Does not corrupt start CSI");
a(slice("\x1b[41mABC\x1b[49mDEF", 0, 3), "\x1b[41mABC\x1b[49m", "Does not corrupt end CSI");
/* CSI-reducing tests */
a(slice("ABC\x1b[31mDEF\x1b[39m", 0, 3), "ABC", "Does not mixin CSI to plain string");
a(slice("ABCD\x1b[31mEF\x1b[39m", 0, 3), "ABC", "Does not mixin CSI to plain string");
a(slice("\x1b[41mABC\x1b[49mDEF", 3), "DEF", "Does not mixin CSI to plain string");
a(slice("\x1b[41mAB\x1b[49mCDEF", 3), "DEF", "Does not mixin CSI to plain string");
a(
slice("A\x1b[31mBBB\x1b[39mD\x1b[32mE\x1b[39m", 2, 3), "\x1b[31mB\x1b[39m",
"Does slice with surrounding styles"
);
a(
slice("A\x1b[31mBBB\x1b[39mD\x1b[32mE\x1b[39m", 0, 5), "A\x1b[31mBBB\x1b[39mD",
"Does slice with inner styles"
);
a(
slice("A\x1b[31mBBB\x1b[39m\x1b[2J\x1b[0;0H", 0, 4), "A\x1b[31mBBB\x1b[39m",
"Remove reset CSI"
);
// 'A' + clc.red('BBB') + clc.erase.screen + clc.move.to(0, 0)
a(
slice("A\u001b[31mBBB\u001b[39m\u001b[2J\u001b[1;1H", 0, 4), "A\x1b[31mBBB\x1b[39m",
"Remove control CSIs"
);
};
cli-color-2.0.2/test/strip.js 0000664 0000000 0000000 00000007275 14221323132 0016060 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("../");
module.exports = function (t, a) {
var x = clc.red, y = x.bold;
a(t("test"), "test", "Plain");
a(t("\x1bA"), "", "Simple Command Type 1");
a(t("\x9bA"), "", "Simple Command Type 2");
a(t("\x1b[0A"), "", "Single Command");
a(t("\x1b[0;A"), "", "Single Separated Command");
a(t("\x1b[0;0A"), "", "Two Commands");
a(t("\x1b[0;0;A"), "", "Two Separated Commands");
// Base on index tests.
a(t(clc.red("foo")), "foo", "Foreground");
a(t(clc.red("foo", "bar", 3)), "foo bar 3", "Foreground: Many args");
a(t(clc.red.yellow("foo", "bar", 3)), "foo bar 3", "Foreground: Overriden");
a(t(clc.bgRed("foo", "bar")), "foo bar", "Background");
a(t(clc.bgRed.bgYellow("foo", "bar", 3)), "foo bar 3", "Background: Overriden");
a(t(clc.blue.bgYellow("foo", "bar")), "foo bar", "Foreground & Background");
a(
t(clc.blue.bgYellow.red.bgMagenta("foo", "bar")), "foo bar",
"Foreground & Background: Overriden"
);
a(t(clc.bold("foo", "bar")), "foo bar", "Format");
a(t(clc.blink("foobar")), "foobar", "Format: blink");
a(t(clc.bold.blue("foo", "bar", 3)), "foo bar 3", "Foreground & Format");
a(t(clc.redBright("foo", "bar")), "foo bar", "Bright");
a(t(clc.bgRedBright("foo", 3)), "foo 3", "Bright background");
a(
t(clc.blueBright.bgYellowBright.red.bgMagenta("foo", "bar")), "foo bar",
"Foreground & Background: Bright: Overriden"
);
a(t(clc.red.blue("foo")), "foo", "Prioritize the Last Color: Blue");
a(t(clc.blue.red("foo")), "foo", "Prioritize the Last Color: Red");
a(t(clc.bgRed.bgBlue("foo")), "foo", "Prioritize the Last Background Color: Blue");
a(t(clc.bgBlue.bgRed("foo")), "foo", "Prioritize the Last Background Color: Red");
a(t(clc.bgRed.red.bgBlue.blue("foo")), "foo", "Prioritize the Last Mixed Style: Blue");
a(t(clc.bgBlue.blue.bgRed.red("foo")), "foo", "Prioritize the Last Mixed Style: Red");
a(
t(clc.bgRed.blue.bgBlue.red("foo")), "foo",
"Prioritize the Last Mixed Style: BG Blue and Red"
);
a(
t(clc.bgBlue.red.bgRed.blue("foo")), "foo",
"Prioritize the Last Mixed Style: BG Red and Blue"
);
a(t(x("foo", "red") + " " + y("foo", "boldred")), "foo red foo boldred", "Detached extension");
a(t(clc.erase.screen).replace(/\n/g, ""), "", "Reset");
a(t(clc.move.up()), "", "Up: No argument");
a(t(clc.move.up({})), "", "Up: Not a number");
a(t(clc.move.up(-34)), "", "Up: Negative");
a(t(clc.move.up(34)), "", "Up: Positive");
a(t(clc.move.down()), "", "Down: No argument");
a(t(clc.move.down({})), "", "Down: Not a number");
a(t(clc.move.down(-34)), "", "Down: Negative");
a(t(clc.move.down(34)), "", "Down: Positive");
a(t(clc.move.right()), "", "Right: No argument");
a(t(clc.move.right({})), "", "Right: Not a number");
a(t(clc.move.right(-34)), "", "Right: Negative");
a(t(clc.move.right(34)), "", "Right: Positive");
a(t(clc.move.left()), "", "Left: No argument");
a(t(clc.move.left({})), "", "Left: Not a number");
a(t(clc.move.left(-34)), "", "Left: Negative");
a(t(clc.move.left(34)), "", "Left: Positive");
a(t(clc.move()), "", "Move: No arguments");
a(t(clc.move({}, {})), "", "Move: Bad arguments");
a(t(clc.move({}, 12)), "", "Move: One direction");
a(t(clc.move(0, -12)), "", "Move: One negative direction");
a(t(clc.move(-42, -2)), "", "Move: two negatives");
a(t(clc.move(2, 35)), "", "Move: two positives");
a(t(clc.move.to()), "", "MoveTo: No arguments");
a(t(clc.move.to({}, {})), "", "MoveTo: Bad arguments");
a(t(clc.move.to({}, 12)), "", "MoveTo: One direction");
a(t(clc.move.to(2, -12)), "", "MoveTo: One negative direction");
a(t(clc.move.to(-42, -2)), "", "MoveTo: two negatives");
a(t(clc.move.to(2, 35)), "", "MoveTo: two positives");
a(t(clc.beep), clc.beep, "Beep");
a(t("test"), "test", "Plain");
};
cli-color-2.0.2/test/throbber.js 0000664 0000000 0000000 00000002507 14221323132 0016517 0 ustar 00root root 0000000 0000000 "use strict";
var startsWith = require("es5-ext/string/#/starts-with")
, spawn = require("child_process").spawn
, resolve = require("path").resolve;
var pg = resolve(__dirname, "__playground");
module.exports = {
"": function (a, d) {
var t = spawn("node", [resolve(pg, "throbber.js")]), out = [], err = "";
t.stdout.on("data", function (data) { out.push(data); });
t.stderr.on("data", function (data) { err += data; });
t.on("exit", function () {
a.ok(out.length > 4, "Interval");
a(startsWith.call(out.join(""), "START-\b\\\b|\b/\b-\b"), true, "Output");
a(err, "", "No stderr output");
d();
});
},
"Formatted": function (a, d) {
var t = spawn("node", [resolve(pg, "throbber.formatted.js")]), out = [], err = "";
t.stdout.on("data", function (data) { out.push(data); });
t.stderr.on("data", function (data) { err += data; });
t.on("exit", function () {
a.ok(out.length > 4, "Interval");
var isNoColor = Boolean(process.env.NO_COLOR);
if (isNoColor) {
a(startsWith.call(out.join(""), "START"), true, "Output");
} else {
a(
startsWith.call(
out.join(""),
"START\x1b[31m-\x1b[39m\x1b[31m\b\\\x1b" +
"[39m\x1b[31m\b|\x1b[39m\x1b[31m\b/\x1b[39m\x1b[31m\b-\x1b[39m"
),
true, "Output"
);
}
a(err, "", "No stderr output");
d();
});
}
};
cli-color-2.0.2/test/visual.js 0000664 0000000 0000000 00000005131 14221323132 0016207 0 ustar 00root root 0000000 0000000 "use strict";
var clc = require("./");
var colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"];
// Write some message.
var w = function (message) { process.stdout.write(message); };
// Print colors.
var printColors = function (title, style) {
var j = colors.length, color, colorText, tint, i;
w(" > " + clc.whiteBright(title) + " ");
for (i = 0; i < j; i++) {
tint = clc;
color = colors[i];
colorText = color.toUpperCase();
if (style === "foreground") {
tint = tint[color];
if (color === "black") {
tint = tint.bgBlackBright;
}
}
if (style === "foregroundBright") {
tint = tint[color + "Bright"];
}
if (style === "background") {
tint = tint["bg" + color.slice(0, 1).toUpperCase() + color.slice(1)];
if (color === "white") {
tint = tint.whiteBright;
}
}
if (style === "backgroundBright") {
tint = tint["bg" + color.slice(0, 1).toUpperCase() + color.slice(1) + "Bright"];
}
w(tint(colorText) + " ");
}
w("\n");
};
// Smile test.
w(clc.reset);
w("\n SMILE TEST\n\n");
// Yellow face.
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
w(clc(" "));
w(clc.bgYellowBright(" "));
w(clc("\n"));
// Move blue eyes.
w(clc.move(7, -5));
w(clc.blueBright.bgYellowBright("O"));
w(clc.move(1, 0));
w(clc.blueBright.bgYellowBright("O"));
// Red nose.
w(clc.move.to(8, 5));
w(clc.redBright.bgYellowBright("\u25A0"));
// Red mouth.
w(clc.move.down(2));
w(clc.move.left(2));
w(clc.red.bgYellowBright("\u2588\u2584\u2588"));
// Move back.
w(clc.move.to(0, 9));
// Colors test.
w("\n COLORS TESTS\n");
printColors("FOREGROUNDS (DEFAULT)", "foreground");
printColors("FOREGROUNDS (BRIGHT) ", "foregroundBright");
printColors("BACKGROUNDS (DEFAULT)", "background");
printColors("BACKGROUNDS (BRIGHT) ", "backgroundBright");
// // Art test.
w("\n ART TESTS\n\n");
w(
clc.art("\t.01111111112.\n\t.3.........3.\n\t.3.........3.\n\t.41111111115.\n", {
"0": clc.bgBlue.yellowBright("\u2554"),
"1": clc.bgBlue.yellowBright("\u2550"),
"2": clc.bgBlue.yellowBright("\u2557"),
"3": clc.bgBlue.yellowBright("\u2551"),
"4": clc.bgBlue.yellowBright("\u255A"),
"5": clc.bgBlue.yellowBright("\u255D"),
".": clc.bgBlue(" ")
})
);
w(clc.move(11, -3));
w(clc.bgBlue.whiteBright("Hello"));
w(clc.move(-3, 1));
w(clc.bgBlue.whiteBright("World"));
w(clc.move(0, 2));
w("\n");
cli-color-2.0.2/test/window-size.js 0000664 0000000 0000000 00000000266 14221323132 0017167 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = function (t, a) {
a(typeof t.width, "number", "Width");
a(typeof t.height, "number", "Height");
a(t.width >= 0, true);
a(t.height >= 0, true);
};
cli-color-2.0.2/throbber.js 0000664 0000000 0000000 00000002543 14221323132 0015540 0 ustar 00root root 0000000 0000000 "use strict";
var compose = require("es5-ext/function/#/compose")
, callable = require("es5-ext/object/valid-callable")
, d = require("d")
, validTimeout = require("timers-ext/valid-timeout");
var chars = "-\\|/", l = chars.length, ThrobberIterator;
ThrobberIterator = function () {
// no setup needed
};
Object.defineProperties(ThrobberIterator.prototype, {
index: d(-1),
running: d(false),
next: d(function () {
var str = this.running ? "\u0008" : "";
if (!this.running) this.running = true;
return str + chars[(this.index = (this.index + 1) % l)];
}),
reset: d(function () {
if (!this.running) return "";
this.index = -1;
this.running = false;
return "\u0008";
})
});
module.exports = exports = function (write, interval /*, format*/) {
var format = arguments[2], token, iterator = new ThrobberIterator();
callable(write);
interval = validTimeout(interval);
if (format !== undefined) write = compose.call(write, callable(format));
return {
start: function () {
if (token) return;
token = setInterval(function () { write(iterator.next()); }, interval);
},
restart: function () {
this.stop();
this.start();
},
stop: function () {
if (!token) return;
clearInterval(token);
token = null;
write(iterator.reset());
}
};
};
Object.defineProperty(exports, "Iterator", d(ThrobberIterator));
cli-color-2.0.2/window-size.js 0000664 0000000 0000000 00000000334 14221323132 0016204 0 ustar 00root root 0000000 0000000 "use strict";
var d = require("d");
Object.defineProperties(exports, {
width: d.gs("ce", function () { return process.stdout.columns || 0; }),
height: d.gs("ce", function () { return process.stdout.rows || 0; })
});