@trayai/tray-sync-cli 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/env.js +15 -8
- package/dist/commands/promote.js +1 -1
- package/dist/views/env/env.v2.js +115 -0
- package/dist/views/icons.js +6 -0
- package/dist/views/promote/promote.v2.js +46 -0
- package/node_modules/@colors/colors/LICENSE +26 -0
- package/node_modules/@colors/colors/README.md +219 -0
- package/node_modules/@colors/colors/examples/normal-usage.js +83 -0
- package/node_modules/@colors/colors/examples/safe-string.js +80 -0
- package/node_modules/@colors/colors/index.d.ts +136 -0
- package/node_modules/@colors/colors/lib/colors.js +211 -0
- package/node_modules/@colors/colors/lib/custom/trap.js +46 -0
- package/node_modules/@colors/colors/lib/custom/zalgo.js +110 -0
- package/node_modules/@colors/colors/lib/extendStringPrototype.js +110 -0
- package/node_modules/@colors/colors/lib/index.js +13 -0
- package/node_modules/@colors/colors/lib/maps/america.js +10 -0
- package/node_modules/@colors/colors/lib/maps/rainbow.js +12 -0
- package/node_modules/@colors/colors/lib/maps/random.js +11 -0
- package/node_modules/@colors/colors/lib/maps/zebra.js +5 -0
- package/node_modules/@colors/colors/lib/styles.js +95 -0
- package/node_modules/@colors/colors/lib/system/has-flag.js +35 -0
- package/node_modules/@colors/colors/lib/system/supports-colors.js +151 -0
- package/node_modules/@colors/colors/package.json +45 -0
- package/node_modules/@colors/colors/safe.d.ts +48 -0
- package/node_modules/@colors/colors/safe.js +10 -0
- package/node_modules/@colors/colors/themes/generic-logging.js +12 -0
- package/node_modules/ansi-regex/index.d.ts +33 -0
- package/node_modules/ansi-regex/index.js +14 -0
- package/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-regex/package.json +61 -0
- package/node_modules/ansi-regex/readme.md +66 -0
- package/node_modules/ansis/LICENSE +15 -0
- package/node_modules/ansis/README.md +5 -0
- package/node_modules/ansis/index.cjs +1 -0
- package/node_modules/ansis/index.d.ts +1 -0
- package/node_modules/ansis/index.mjs +1 -0
- package/node_modules/ansis/package.json +19 -0
- package/node_modules/cli-table3/LICENSE +21 -0
- package/node_modules/cli-table3/README.md +236 -0
- package/node_modules/cli-table3/index.d.ts +96 -0
- package/node_modules/cli-table3/index.js +1 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/index.d.ts +37 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/index.js +10 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/license +9 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/package.json +55 -0
- package/node_modules/cli-table3/node_modules/ansi-regex/readme.md +78 -0
- package/node_modules/cli-table3/node_modules/string-width/index.d.ts +29 -0
- package/node_modules/cli-table3/node_modules/string-width/index.js +47 -0
- package/node_modules/cli-table3/node_modules/string-width/license +9 -0
- package/node_modules/cli-table3/node_modules/string-width/package.json +56 -0
- package/node_modules/cli-table3/node_modules/string-width/readme.md +50 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/index.d.ts +17 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/index.js +4 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/license +9 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/package.json +54 -0
- package/node_modules/cli-table3/node_modules/strip-ansi/readme.md +46 -0
- package/node_modules/cli-table3/package.json +100 -0
- package/node_modules/cli-table3/src/cell.js +409 -0
- package/node_modules/cli-table3/src/debug.js +28 -0
- package/node_modules/cli-table3/src/layout-manager.js +254 -0
- package/node_modules/cli-table3/src/table.js +106 -0
- package/node_modules/cli-table3/src/utils.js +344 -0
- package/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/emoji-regex/README.md +73 -0
- package/node_modules/emoji-regex/es2015/index.js +6 -0
- package/node_modules/emoji-regex/es2015/text.js +6 -0
- package/node_modules/emoji-regex/index.d.ts +23 -0
- package/node_modules/emoji-regex/index.js +6 -0
- package/node_modules/emoji-regex/package.json +50 -0
- package/node_modules/emoji-regex/text.js +6 -0
- package/node_modules/get-east-asian-width/index.d.ts +60 -0
- package/node_modules/get-east-asian-width/index.js +30 -0
- package/node_modules/get-east-asian-width/license +9 -0
- package/node_modules/get-east-asian-width/lookup-data.js +21 -0
- package/node_modules/get-east-asian-width/lookup.js +138 -0
- package/node_modules/get-east-asian-width/package.json +71 -0
- package/node_modules/get-east-asian-width/readme.md +65 -0
- package/node_modules/get-east-asian-width/utilities.js +24 -0
- package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
- package/node_modules/is-fullwidth-code-point/index.js +50 -0
- package/node_modules/is-fullwidth-code-point/license +9 -0
- package/node_modules/is-fullwidth-code-point/package.json +42 -0
- package/node_modules/is-fullwidth-code-point/readme.md +39 -0
- package/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/string-width/index.js +207 -0
- package/node_modules/string-width/license +9 -0
- package/node_modules/string-width/package.json +65 -0
- package/node_modules/string-width/readme.md +66 -0
- package/node_modules/strip-ansi/index.d.ts +15 -0
- package/node_modules/strip-ansi/index.js +19 -0
- package/node_modules/strip-ansi/license +9 -0
- package/node_modules/strip-ansi/package.json +59 -0
- package/node_modules/strip-ansi/readme.md +37 -0
- package/package.json +9 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# string-width
|
|
2
|
+
|
|
3
|
+
> Get the visual width of a string - the number of columns required to display it
|
|
4
|
+
|
|
5
|
+
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
|
6
|
+
|
|
7
|
+
Useful to be able to measure the actual width of command-line output.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
$ npm install string-width
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const stringWidth = require('string-width');
|
|
21
|
+
|
|
22
|
+
stringWidth('a');
|
|
23
|
+
//=> 1
|
|
24
|
+
|
|
25
|
+
stringWidth('古');
|
|
26
|
+
//=> 2
|
|
27
|
+
|
|
28
|
+
stringWidth('\u001B[1m古\u001B[22m');
|
|
29
|
+
//=> 2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Related
|
|
34
|
+
|
|
35
|
+
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
|
36
|
+
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
|
37
|
+
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
<div align="center">
|
|
43
|
+
<b>
|
|
44
|
+
<a href="https://tidelift.com/subscription/pkg/npm-string-width?utm_source=npm-string-width&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|
45
|
+
</b>
|
|
46
|
+
<br>
|
|
47
|
+
<sub>
|
|
48
|
+
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|
49
|
+
</sub>
|
|
50
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
|
|
3
|
+
|
|
4
|
+
@example
|
|
5
|
+
```
|
|
6
|
+
import stripAnsi = require('strip-ansi');
|
|
7
|
+
|
|
8
|
+
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
|
9
|
+
//=> 'Unicorn'
|
|
10
|
+
|
|
11
|
+
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
|
12
|
+
//=> 'Click'
|
|
13
|
+
```
|
|
14
|
+
*/
|
|
15
|
+
declare function stripAnsi(string: string): string;
|
|
16
|
+
|
|
17
|
+
export = stripAnsi;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
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.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "strip-ansi",
|
|
3
|
+
"version": "6.0.1",
|
|
4
|
+
"description": "Strip ANSI escape codes from a string",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "chalk/strip-ansi",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sindre Sorhus",
|
|
9
|
+
"email": "sindresorhus@gmail.com",
|
|
10
|
+
"url": "sindresorhus.com"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=8"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "xo && ava && tsd"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"strip",
|
|
24
|
+
"trim",
|
|
25
|
+
"remove",
|
|
26
|
+
"ansi",
|
|
27
|
+
"styles",
|
|
28
|
+
"color",
|
|
29
|
+
"colour",
|
|
30
|
+
"colors",
|
|
31
|
+
"terminal",
|
|
32
|
+
"console",
|
|
33
|
+
"string",
|
|
34
|
+
"tty",
|
|
35
|
+
"escape",
|
|
36
|
+
"formatting",
|
|
37
|
+
"rgb",
|
|
38
|
+
"256",
|
|
39
|
+
"shell",
|
|
40
|
+
"xterm",
|
|
41
|
+
"log",
|
|
42
|
+
"logging",
|
|
43
|
+
"command-line",
|
|
44
|
+
"text"
|
|
45
|
+
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"ansi-regex": "^5.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"ava": "^2.4.0",
|
|
51
|
+
"tsd": "^0.10.0",
|
|
52
|
+
"xo": "^0.25.3"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# strip-ansi [](https://travis-ci.org/chalk/strip-ansi)
|
|
2
|
+
|
|
3
|
+
> Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
$ npm install strip-ansi
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const stripAnsi = require('strip-ansi');
|
|
17
|
+
|
|
18
|
+
stripAnsi('\u001B[4mUnicorn\u001B[0m');
|
|
19
|
+
//=> 'Unicorn'
|
|
20
|
+
|
|
21
|
+
stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
|
|
22
|
+
//=> 'Click'
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## strip-ansi for enterprise
|
|
27
|
+
|
|
28
|
+
Available as part of the Tidelift Subscription.
|
|
29
|
+
|
|
30
|
+
The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-strip-ansi?utm_source=npm-strip-ansi&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Related
|
|
34
|
+
|
|
35
|
+
- [strip-ansi-cli](https://github.com/chalk/strip-ansi-cli) - CLI for this module
|
|
36
|
+
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Streaming version of this module
|
|
37
|
+
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
|
38
|
+
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
|
39
|
+
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Maintainers
|
|
43
|
+
|
|
44
|
+
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
45
|
+
- [Josh Junon](https://github.com/qix-)
|
|
46
|
+
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cli-table3",
|
|
3
|
+
"version": "0.6.5",
|
|
4
|
+
"description": "Pretty unicode tables for the command line. Based on the original cli-table.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src/",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"index.js"
|
|
11
|
+
],
|
|
12
|
+
"directories": {
|
|
13
|
+
"test": "test"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"string-width": "^4.2.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"cli-table": "^0.3.1",
|
|
20
|
+
"eslint": "^6.0.0",
|
|
21
|
+
"eslint-config-prettier": "^6.0.0",
|
|
22
|
+
"eslint-plugin-prettier": "^3.0.0",
|
|
23
|
+
"jest": "^25.2.4",
|
|
24
|
+
"jest-runner-eslint": "^0.7.0",
|
|
25
|
+
"lerna-changelog": "^1.0.1",
|
|
26
|
+
"prettier": "2.3.2"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"@colors/colors": "1.5.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"changelog": "lerna-changelog",
|
|
33
|
+
"docs": "node ./scripts/update-docs.js",
|
|
34
|
+
"prettier": "prettier --write '{examples,lib,scripts,src,test}/**/*.js'",
|
|
35
|
+
"test": "jest --color",
|
|
36
|
+
"test:watch": "jest --color --watchAll --notify"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/cli-table/cli-table3.git"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"node",
|
|
44
|
+
"command",
|
|
45
|
+
"line",
|
|
46
|
+
"cli",
|
|
47
|
+
"table",
|
|
48
|
+
"tables",
|
|
49
|
+
"tabular",
|
|
50
|
+
"unicode",
|
|
51
|
+
"colors",
|
|
52
|
+
"grid"
|
|
53
|
+
],
|
|
54
|
+
"author": "James Talmage",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/cli-table/cli-table3/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/cli-table/cli-table3",
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": "10.* || >= 12.*"
|
|
62
|
+
},
|
|
63
|
+
"changelog": {
|
|
64
|
+
"repo": "cli-table/cli-table3",
|
|
65
|
+
"labels": {
|
|
66
|
+
"breaking": ":boom: Breaking Change",
|
|
67
|
+
"enhancement": ":rocket: Enhancement",
|
|
68
|
+
"bug": ":bug: Bug Fix",
|
|
69
|
+
"documentation": ":memo: Documentation",
|
|
70
|
+
"internal": ":house: Internal"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"jest": {
|
|
74
|
+
"projects": [
|
|
75
|
+
{
|
|
76
|
+
"displayName": "test",
|
|
77
|
+
"testMatch": [
|
|
78
|
+
"<rootDir>/test/**/*.js"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"runner": "jest-runner-eslint",
|
|
83
|
+
"displayName": "lint",
|
|
84
|
+
"testMatch": [
|
|
85
|
+
"<rootDir>/examples/**/*.js",
|
|
86
|
+
"<rootDir>/lib/**/*.js",
|
|
87
|
+
"<rootDir>/scripts/**/*.js",
|
|
88
|
+
"<rootDir>/src/**/*.js",
|
|
89
|
+
"<rootDir>/test/**/*.js"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"prettier": {
|
|
95
|
+
"printWidth": 120,
|
|
96
|
+
"tabWidth": 2,
|
|
97
|
+
"singleQuote": true,
|
|
98
|
+
"trailingComma": "es5"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
const { info, debug } = require('./debug');
|
|
2
|
+
const utils = require('./utils');
|
|
3
|
+
|
|
4
|
+
class Cell {
|
|
5
|
+
/**
|
|
6
|
+
* A representation of a cell within the table.
|
|
7
|
+
* Implementations must have `init` and `draw` methods,
|
|
8
|
+
* as well as `colSpan`, `rowSpan`, `desiredHeight` and `desiredWidth` properties.
|
|
9
|
+
* @param options
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.setOptions(options);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Each cell will have it's `x` and `y` values set by the `layout-manager` prior to
|
|
17
|
+
* `init` being called;
|
|
18
|
+
* @type {Number}
|
|
19
|
+
*/
|
|
20
|
+
this.x = null;
|
|
21
|
+
this.y = null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setOptions(options) {
|
|
25
|
+
if (['boolean', 'number', 'bigint', 'string'].indexOf(typeof options) !== -1) {
|
|
26
|
+
options = { content: '' + options };
|
|
27
|
+
}
|
|
28
|
+
options = options || {};
|
|
29
|
+
this.options = options;
|
|
30
|
+
let content = options.content;
|
|
31
|
+
if (['boolean', 'number', 'bigint', 'string'].indexOf(typeof content) !== -1) {
|
|
32
|
+
this.content = String(content);
|
|
33
|
+
} else if (!content) {
|
|
34
|
+
this.content = this.options.href || '';
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error('Content needs to be a primitive, got: ' + typeof content);
|
|
37
|
+
}
|
|
38
|
+
this.colSpan = options.colSpan || 1;
|
|
39
|
+
this.rowSpan = options.rowSpan || 1;
|
|
40
|
+
if (this.options.href) {
|
|
41
|
+
Object.defineProperty(this, 'href', {
|
|
42
|
+
get() {
|
|
43
|
+
return this.options.href;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
mergeTableOptions(tableOptions, cells) {
|
|
50
|
+
this.cells = cells;
|
|
51
|
+
|
|
52
|
+
let optionsChars = this.options.chars || {};
|
|
53
|
+
let tableChars = tableOptions.chars;
|
|
54
|
+
let chars = (this.chars = {});
|
|
55
|
+
CHAR_NAMES.forEach(function (name) {
|
|
56
|
+
setOption(optionsChars, tableChars, name, chars);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.truncate = this.options.truncate || tableOptions.truncate;
|
|
60
|
+
|
|
61
|
+
let style = (this.options.style = this.options.style || {});
|
|
62
|
+
let tableStyle = tableOptions.style;
|
|
63
|
+
setOption(style, tableStyle, 'padding-left', this);
|
|
64
|
+
setOption(style, tableStyle, 'padding-right', this);
|
|
65
|
+
this.head = style.head || tableStyle.head;
|
|
66
|
+
this.border = style.border || tableStyle.border;
|
|
67
|
+
|
|
68
|
+
this.fixedWidth = tableOptions.colWidths[this.x];
|
|
69
|
+
this.lines = this.computeLines(tableOptions);
|
|
70
|
+
|
|
71
|
+
this.desiredWidth = utils.strlen(this.content) + this.paddingLeft + this.paddingRight;
|
|
72
|
+
this.desiredHeight = this.lines.length;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
computeLines(tableOptions) {
|
|
76
|
+
const tableWordWrap = tableOptions.wordWrap || tableOptions.textWrap;
|
|
77
|
+
const { wordWrap = tableWordWrap } = this.options;
|
|
78
|
+
if (this.fixedWidth && wordWrap) {
|
|
79
|
+
this.fixedWidth -= this.paddingLeft + this.paddingRight;
|
|
80
|
+
if (this.colSpan) {
|
|
81
|
+
let i = 1;
|
|
82
|
+
while (i < this.colSpan) {
|
|
83
|
+
this.fixedWidth += tableOptions.colWidths[this.x + i];
|
|
84
|
+
i++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const { wrapOnWordBoundary: tableWrapOnWordBoundary = true } = tableOptions;
|
|
88
|
+
const { wrapOnWordBoundary = tableWrapOnWordBoundary } = this.options;
|
|
89
|
+
return this.wrapLines(utils.wordWrap(this.fixedWidth, this.content, wrapOnWordBoundary));
|
|
90
|
+
}
|
|
91
|
+
return this.wrapLines(this.content.split('\n'));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
wrapLines(computedLines) {
|
|
95
|
+
const lines = utils.colorizeLines(computedLines);
|
|
96
|
+
if (this.href) {
|
|
97
|
+
return lines.map((line) => utils.hyperlink(this.href, line));
|
|
98
|
+
}
|
|
99
|
+
return lines;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Initializes the Cells data structure.
|
|
104
|
+
*
|
|
105
|
+
* @param tableOptions - A fully populated set of tableOptions.
|
|
106
|
+
* In addition to the standard default values, tableOptions must have fully populated the
|
|
107
|
+
* `colWidths` and `rowWidths` arrays. Those arrays must have lengths equal to the number
|
|
108
|
+
* of columns or rows (respectively) in this table, and each array item must be a Number.
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
init(tableOptions) {
|
|
112
|
+
let x = this.x;
|
|
113
|
+
let y = this.y;
|
|
114
|
+
this.widths = tableOptions.colWidths.slice(x, x + this.colSpan);
|
|
115
|
+
this.heights = tableOptions.rowHeights.slice(y, y + this.rowSpan);
|
|
116
|
+
this.width = this.widths.reduce(sumPlusOne, -1);
|
|
117
|
+
this.height = this.heights.reduce(sumPlusOne, -1);
|
|
118
|
+
|
|
119
|
+
this.hAlign = this.options.hAlign || tableOptions.colAligns[x];
|
|
120
|
+
this.vAlign = this.options.vAlign || tableOptions.rowAligns[y];
|
|
121
|
+
|
|
122
|
+
this.drawRight = x + this.colSpan == tableOptions.colWidths.length;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Draws the given line of the cell.
|
|
127
|
+
* This default implementation defers to methods `drawTop`, `drawBottom`, `drawLine` and `drawEmpty`.
|
|
128
|
+
* @param lineNum - can be `top`, `bottom` or a numerical line number.
|
|
129
|
+
* @param spanningCell - will be a number if being called from a RowSpanCell, and will represent how
|
|
130
|
+
* many rows below it's being called from. Otherwise it's undefined.
|
|
131
|
+
* @returns {String} The representation of this line.
|
|
132
|
+
*/
|
|
133
|
+
draw(lineNum, spanningCell) {
|
|
134
|
+
if (lineNum == 'top') return this.drawTop(this.drawRight);
|
|
135
|
+
if (lineNum == 'bottom') return this.drawBottom(this.drawRight);
|
|
136
|
+
let content = utils.truncate(this.content, 10, this.truncate);
|
|
137
|
+
if (!lineNum) {
|
|
138
|
+
info(`${this.y}-${this.x}: ${this.rowSpan - lineNum}x${this.colSpan} Cell ${content}`);
|
|
139
|
+
} else {
|
|
140
|
+
// debug(`${lineNum}-${this.x}: 1x${this.colSpan} RowSpanCell ${content}`);
|
|
141
|
+
}
|
|
142
|
+
let padLen = Math.max(this.height - this.lines.length, 0);
|
|
143
|
+
let padTop;
|
|
144
|
+
switch (this.vAlign) {
|
|
145
|
+
case 'center':
|
|
146
|
+
padTop = Math.ceil(padLen / 2);
|
|
147
|
+
break;
|
|
148
|
+
case 'bottom':
|
|
149
|
+
padTop = padLen;
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
padTop = 0;
|
|
153
|
+
}
|
|
154
|
+
if (lineNum < padTop || lineNum >= padTop + this.lines.length) {
|
|
155
|
+
return this.drawEmpty(this.drawRight, spanningCell);
|
|
156
|
+
}
|
|
157
|
+
let forceTruncation = this.lines.length > this.height && lineNum + 1 >= this.height;
|
|
158
|
+
return this.drawLine(lineNum - padTop, this.drawRight, forceTruncation, spanningCell);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Renders the top line of the cell.
|
|
163
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
164
|
+
* @returns {String}
|
|
165
|
+
*/
|
|
166
|
+
drawTop(drawRight) {
|
|
167
|
+
let content = [];
|
|
168
|
+
if (this.cells) {
|
|
169
|
+
//TODO: cells should always exist - some tests don't fill it in though
|
|
170
|
+
this.widths.forEach(function (width, index) {
|
|
171
|
+
content.push(this._topLeftChar(index));
|
|
172
|
+
content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], width));
|
|
173
|
+
}, this);
|
|
174
|
+
} else {
|
|
175
|
+
content.push(this._topLeftChar(0));
|
|
176
|
+
content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], this.width));
|
|
177
|
+
}
|
|
178
|
+
if (drawRight) {
|
|
179
|
+
content.push(this.chars[this.y == 0 ? 'topRight' : 'rightMid']);
|
|
180
|
+
}
|
|
181
|
+
return this.wrapWithStyleColors('border', content.join(''));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_topLeftChar(offset) {
|
|
185
|
+
let x = this.x + offset;
|
|
186
|
+
let leftChar;
|
|
187
|
+
if (this.y == 0) {
|
|
188
|
+
leftChar = x == 0 ? 'topLeft' : offset == 0 ? 'topMid' : 'top';
|
|
189
|
+
} else {
|
|
190
|
+
if (x == 0) {
|
|
191
|
+
leftChar = 'leftMid';
|
|
192
|
+
} else {
|
|
193
|
+
leftChar = offset == 0 ? 'midMid' : 'bottomMid';
|
|
194
|
+
if (this.cells) {
|
|
195
|
+
//TODO: cells should always exist - some tests don't fill it in though
|
|
196
|
+
let spanAbove = this.cells[this.y - 1][x] instanceof Cell.ColSpanCell;
|
|
197
|
+
if (spanAbove) {
|
|
198
|
+
leftChar = offset == 0 ? 'topMid' : 'mid';
|
|
199
|
+
}
|
|
200
|
+
if (offset == 0) {
|
|
201
|
+
let i = 1;
|
|
202
|
+
while (this.cells[this.y][x - i] instanceof Cell.ColSpanCell) {
|
|
203
|
+
i++;
|
|
204
|
+
}
|
|
205
|
+
if (this.cells[this.y][x - i] instanceof Cell.RowSpanCell) {
|
|
206
|
+
leftChar = 'leftMid';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return this.chars[leftChar];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
wrapWithStyleColors(styleProperty, content) {
|
|
216
|
+
if (this[styleProperty] && this[styleProperty].length) {
|
|
217
|
+
try {
|
|
218
|
+
let colors = require('@colors/colors/safe');
|
|
219
|
+
for (let i = this[styleProperty].length - 1; i >= 0; i--) {
|
|
220
|
+
colors = colors[this[styleProperty][i]];
|
|
221
|
+
}
|
|
222
|
+
return colors(content);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
return content;
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
return content;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Renders a line of text.
|
|
233
|
+
* @param lineNum - Which line of text to render. This is not necessarily the line within the cell.
|
|
234
|
+
* There may be top-padding above the first line of text.
|
|
235
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
236
|
+
* @param forceTruncationSymbol - `true` if the rendered text should end with the truncation symbol even
|
|
237
|
+
* if the text fits. This is used when the cell is vertically truncated. If `false` the text should
|
|
238
|
+
* only include the truncation symbol if the text will not fit horizontally within the cell width.
|
|
239
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
240
|
+
* @returns {String}
|
|
241
|
+
*/
|
|
242
|
+
drawLine(lineNum, drawRight, forceTruncationSymbol, spanningCell) {
|
|
243
|
+
let left = this.chars[this.x == 0 ? 'left' : 'middle'];
|
|
244
|
+
if (this.x && spanningCell && this.cells) {
|
|
245
|
+
let cellLeft = this.cells[this.y + spanningCell][this.x - 1];
|
|
246
|
+
while (cellLeft instanceof ColSpanCell) {
|
|
247
|
+
cellLeft = this.cells[cellLeft.y][cellLeft.x - 1];
|
|
248
|
+
}
|
|
249
|
+
if (!(cellLeft instanceof RowSpanCell)) {
|
|
250
|
+
left = this.chars['rightMid'];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
let leftPadding = utils.repeat(' ', this.paddingLeft);
|
|
254
|
+
let right = drawRight ? this.chars['right'] : '';
|
|
255
|
+
let rightPadding = utils.repeat(' ', this.paddingRight);
|
|
256
|
+
let line = this.lines[lineNum];
|
|
257
|
+
let len = this.width - (this.paddingLeft + this.paddingRight);
|
|
258
|
+
if (forceTruncationSymbol) line += this.truncate || '…';
|
|
259
|
+
let content = utils.truncate(line, len, this.truncate);
|
|
260
|
+
content = utils.pad(content, len, ' ', this.hAlign);
|
|
261
|
+
content = leftPadding + content + rightPadding;
|
|
262
|
+
return this.stylizeLine(left, content, right);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
stylizeLine(left, content, right) {
|
|
266
|
+
left = this.wrapWithStyleColors('border', left);
|
|
267
|
+
right = this.wrapWithStyleColors('border', right);
|
|
268
|
+
if (this.y === 0) {
|
|
269
|
+
content = this.wrapWithStyleColors('head', content);
|
|
270
|
+
}
|
|
271
|
+
return left + content + right;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Renders the bottom line of the cell.
|
|
276
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
277
|
+
* @returns {String}
|
|
278
|
+
*/
|
|
279
|
+
drawBottom(drawRight) {
|
|
280
|
+
let left = this.chars[this.x == 0 ? 'bottomLeft' : 'bottomMid'];
|
|
281
|
+
let content = utils.repeat(this.chars.bottom, this.width);
|
|
282
|
+
let right = drawRight ? this.chars['bottomRight'] : '';
|
|
283
|
+
return this.wrapWithStyleColors('border', left + content + right);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Renders a blank line of text within the cell. Used for top and/or bottom padding.
|
|
288
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
289
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
290
|
+
* @returns {String}
|
|
291
|
+
*/
|
|
292
|
+
drawEmpty(drawRight, spanningCell) {
|
|
293
|
+
let left = this.chars[this.x == 0 ? 'left' : 'middle'];
|
|
294
|
+
if (this.x && spanningCell && this.cells) {
|
|
295
|
+
let cellLeft = this.cells[this.y + spanningCell][this.x - 1];
|
|
296
|
+
while (cellLeft instanceof ColSpanCell) {
|
|
297
|
+
cellLeft = this.cells[cellLeft.y][cellLeft.x - 1];
|
|
298
|
+
}
|
|
299
|
+
if (!(cellLeft instanceof RowSpanCell)) {
|
|
300
|
+
left = this.chars['rightMid'];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
let right = drawRight ? this.chars['right'] : '';
|
|
304
|
+
let content = utils.repeat(' ', this.width);
|
|
305
|
+
return this.stylizeLine(left, content, right);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
class ColSpanCell {
|
|
310
|
+
/**
|
|
311
|
+
* A Cell that doesn't do anything. It just draws empty lines.
|
|
312
|
+
* Used as a placeholder in column spanning.
|
|
313
|
+
* @constructor
|
|
314
|
+
*/
|
|
315
|
+
constructor() {}
|
|
316
|
+
|
|
317
|
+
draw(lineNum) {
|
|
318
|
+
if (typeof lineNum === 'number') {
|
|
319
|
+
debug(`${this.y}-${this.x}: 1x1 ColSpanCell`);
|
|
320
|
+
}
|
|
321
|
+
return '';
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
init() {}
|
|
325
|
+
|
|
326
|
+
mergeTableOptions() {}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
class RowSpanCell {
|
|
330
|
+
/**
|
|
331
|
+
* A placeholder Cell for a Cell that spans multiple rows.
|
|
332
|
+
* It delegates rendering to the original cell, but adds the appropriate offset.
|
|
333
|
+
* @param originalCell
|
|
334
|
+
* @constructor
|
|
335
|
+
*/
|
|
336
|
+
constructor(originalCell) {
|
|
337
|
+
this.originalCell = originalCell;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
init(tableOptions) {
|
|
341
|
+
let y = this.y;
|
|
342
|
+
let originalY = this.originalCell.y;
|
|
343
|
+
this.cellOffset = y - originalY;
|
|
344
|
+
this.offset = findDimension(tableOptions.rowHeights, originalY, this.cellOffset);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
draw(lineNum) {
|
|
348
|
+
if (lineNum == 'top') {
|
|
349
|
+
return this.originalCell.draw(this.offset, this.cellOffset);
|
|
350
|
+
}
|
|
351
|
+
if (lineNum == 'bottom') {
|
|
352
|
+
return this.originalCell.draw('bottom');
|
|
353
|
+
}
|
|
354
|
+
debug(`${this.y}-${this.x}: 1x${this.colSpan} RowSpanCell for ${this.originalCell.content}`);
|
|
355
|
+
return this.originalCell.draw(this.offset + 1 + lineNum);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
mergeTableOptions() {}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function firstDefined(...args) {
|
|
362
|
+
return args.filter((v) => v !== undefined && v !== null).shift();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// HELPER FUNCTIONS
|
|
366
|
+
function setOption(objA, objB, nameB, targetObj) {
|
|
367
|
+
let nameA = nameB.split('-');
|
|
368
|
+
if (nameA.length > 1) {
|
|
369
|
+
nameA[1] = nameA[1].charAt(0).toUpperCase() + nameA[1].substr(1);
|
|
370
|
+
nameA = nameA.join('');
|
|
371
|
+
targetObj[nameA] = firstDefined(objA[nameA], objA[nameB], objB[nameA], objB[nameB]);
|
|
372
|
+
} else {
|
|
373
|
+
targetObj[nameB] = firstDefined(objA[nameB], objB[nameB]);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function findDimension(dimensionTable, startingIndex, span) {
|
|
378
|
+
let ret = dimensionTable[startingIndex];
|
|
379
|
+
for (let i = 1; i < span; i++) {
|
|
380
|
+
ret += 1 + dimensionTable[startingIndex + i];
|
|
381
|
+
}
|
|
382
|
+
return ret;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function sumPlusOne(a, b) {
|
|
386
|
+
return a + b + 1;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
let CHAR_NAMES = [
|
|
390
|
+
'top',
|
|
391
|
+
'top-mid',
|
|
392
|
+
'top-left',
|
|
393
|
+
'top-right',
|
|
394
|
+
'bottom',
|
|
395
|
+
'bottom-mid',
|
|
396
|
+
'bottom-left',
|
|
397
|
+
'bottom-right',
|
|
398
|
+
'left',
|
|
399
|
+
'left-mid',
|
|
400
|
+
'mid',
|
|
401
|
+
'mid-mid',
|
|
402
|
+
'right',
|
|
403
|
+
'right-mid',
|
|
404
|
+
'middle',
|
|
405
|
+
];
|
|
406
|
+
|
|
407
|
+
module.exports = Cell;
|
|
408
|
+
module.exports.ColSpanCell = ColSpanCell;
|
|
409
|
+
module.exports.RowSpanCell = RowSpanCell;
|