zcatalyst-cli 1.13.2 → 1.14.0
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/docs/client-utils.toml +6 -1
- package/docs/commands/ds/import.toml +5 -0
- package/docs/fn-utils/lib/python.toml +4 -0
- package/docs/init/dependencies/python/ensure-python.toml +12 -0
- package/docs/init/dependencies/python/pip-install.toml +4 -0
- package/docs/serve/index.toml +5 -0
- package/lib/authentication/login.js +2 -1
- package/lib/cli_table/index.js +26 -2
- package/lib/cli_table/src/cell.js +359 -267
- package/lib/cli_table/src/layout-manager.js +231 -209
- package/lib/cli_table/src/table.js +76 -60
- package/lib/cli_table/src/utils.js +259 -224
- package/lib/client-utils.js +18 -4
- package/lib/command_needs/rc.js +57 -8
- package/lib/commands/config/delete.js +23 -0
- package/lib/commands/config/get.js +23 -0
- package/lib/commands/config/list.js +23 -0
- package/lib/commands/config/set.js +29 -0
- package/lib/commands/console/cache.js +31 -1
- package/lib/commands/console/queue.js +31 -1
- package/lib/commands/console/zcql.js +27 -1
- package/lib/commands/ds/export.js +2 -2
- package/lib/commands/ds/import.js +25 -5
- package/lib/commands/ds/status.js +2 -2
- package/lib/commands/iac/export.js +1 -1
- package/lib/commands/iac/import.js +1 -1
- package/lib/commands/iac/pack.js +16 -5
- package/lib/commands/iac/status.js +1 -1
- package/lib/commands/index.js +4 -0
- package/lib/commands/project/list.js +1 -1
- package/lib/commands/project/use.js +1 -1
- package/lib/deploy/features/client.js +2 -2
- package/lib/deploy/features/functions/index.js +13 -3
- package/lib/deploy/features/functions/languages/index.js +19 -2
- package/lib/endpoints/index.js +12 -5
- package/lib/endpoints/lib/env.js +5 -2
- package/lib/endpoints/lib/functions.js +30 -0
- package/lib/endpoints/lib/org.js +35 -0
- package/lib/endpoints/lib/project.js +7 -3
- package/lib/express_middlewares/unknownReqProxy.js +4 -1
- package/lib/fn-utils/index.js +2 -0
- package/lib/fn-utils/lib/common.js +68 -7
- package/lib/fn-utils/lib/integ.js +15 -11
- package/lib/fn-utils/lib/java.js +7 -3
- package/lib/fn-utils/lib/python.js +121 -0
- package/lib/fn-watcher.js +10 -2
- package/lib/index.js +2 -1
- package/lib/init/dependencies/python/ensure-python.js +151 -0
- package/lib/init/dependencies/python/pip-install.js +175 -0
- package/lib/init/features/functions/index.js +50 -29
- package/lib/init/features/functions/languages/index.js +3 -1
- package/lib/init/features/functions/languages/python.js +115 -0
- package/lib/init/features/index.js +2 -2
- package/lib/init/features/project.js +26 -6
- package/lib/init/util/project.js +2 -2
- package/lib/internal/api.js +2 -0
- package/lib/internal/command.js +1 -1
- package/lib/internal/rc.js +2 -0
- package/lib/port-resolver.js +4 -3
- package/lib/prompt/types/file-path.js +1 -1
- package/lib/pull/features/functions/index.js +35 -2
- package/lib/pull/features/functions/languages.js +8 -1
- package/lib/readLineUtils.js +37 -1
- package/lib/readline/features/cache.js +175 -1
- package/lib/readline/features/index.js +7 -1
- package/lib/readline/features/queue.js +209 -1
- package/lib/readline/features/zcql.js +237 -1
- package/lib/readline/index.js +30 -1
- package/lib/serve/index.js +48 -7
- package/lib/serve/server/index.js +118 -44
- package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
- package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
- package/lib/serve/server/lib/master.js +18 -5
- package/lib/serve/server/lib/node.mjs +41 -0
- package/lib/serve/server/lib/web_client/index.js +7 -3
- package/lib/serve/server/lib/web_client/server.js +31 -15
- package/lib/shell/dependencies/http-functions.js +57 -21
- package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
- package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
- package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
- package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
- package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
- package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
- package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
- package/lib/shell/dependencies/local-function.js +74 -22
- package/lib/shell/index.js +11 -2
- package/lib/shell/prepare/index.js +21 -0
- package/lib/shell/prepare/languages/index.js +8 -2
- package/lib/shell/prepare/languages/java.js +39 -2
- package/lib/shell/prepare/languages/node.js +21 -2
- package/lib/shell/prepare/languages/python.js +65 -0
- package/lib/throbber/index.js +3 -1
- package/lib/userConfig.js +48 -0
- package/lib/util_modules/constants/index.js +3 -1
- package/lib/util_modules/constants/lib/apig-rules.js +8 -0
- package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
- package/lib/util_modules/constants/lib/dc-type.js +8 -0
- package/lib/util_modules/constants/lib/default.js +2 -2
- package/lib/util_modules/constants/lib/env-path.js +12 -0
- package/lib/util_modules/constants/lib/file-names.js +4 -1
- package/lib/util_modules/constants/lib/folder-names.js +3 -1
- package/lib/util_modules/constants/lib/placeholders.js +6 -1
- package/lib/util_modules/constants/lib/runtime.js +2 -1
- package/lib/util_modules/constants/lib/scopes.js +1 -0
- package/lib/util_modules/constants/lib/template.js +9 -0
- package/lib/util_modules/constants/lib/urls.js +2 -6
- package/lib/util_modules/context-help.js +2 -0
- package/lib/util_modules/fs/lib/async.js +35 -11
- package/lib/util_modules/project.js +20 -1
- package/package.json +2 -1
- package/templates/init/functions/java/aio/catalyst-config.json +3 -2
- package/templates/init/functions/java/bio/catalyst-config.json +3 -2
- package/templates/init/functions/java/cron/catalyst-config.json +3 -2
- package/templates/init/functions/java/event/catalyst-config.json +3 -2
- package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/aio/catalyst-config.json +3 -2
- package/templates/init/functions/node/bio/catalyst-config.json +3 -2
- package/templates/init/functions/node/cron/catalyst-config.json +3 -2
- package/templates/init/functions/node/event/catalyst-config.json +3 -2
- package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
- package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
- package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
- package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
- package/templates/init/functions/node/integ/cliq/sample.js +4 -4
- package/templates/init/functions/python/aio/catalyst-config.json +11 -0
- package/templates/init/functions/python/aio/requirements.txt +1 -0
- package/templates/init/functions/python/aio/sample.py +26 -0
- package/templates/init/functions/python/bio/catalyst-config.json +11 -0
- package/templates/init/functions/python/bio/requirements.txt +1 -0
- package/templates/init/functions/python/bio/sample.py +6 -0
- package/templates/init/functions/python/cron/catalyst-config.json +11 -0
- package/templates/init/functions/python/cron/requirements.txt +1 -0
- package/templates/init/functions/python/cron/sample.py +18 -0
- package/templates/init/functions/python/event/catalyst-config.json +11 -0
- package/templates/init/functions/python/event/requirements.txt +1 -0
- package/templates/init/functions/python/event/sample.py +21 -0
- package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
- package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
- package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
- package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
- package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
- package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
- package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
- package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
- package/templates/init/functions/python/integ/cliq/sample.py +21 -0
- package/lib/serve/server/lib/node.js +0 -62
- package/lib/shell/dependencies/invoker/bio/node.js +0 -80
- package/lib/shell/dependencies/invoker/cron/node.js +0 -54
- package/lib/shell/dependencies/invoker/event/node.js +0 -56
- package/lib/shell/dependencies/invoker/integ/node.js +0 -79
- package/templates/.DS_Store +0 -0
- package/templates/init/.DS_Store +0 -0
- package/templates/init/client/.DS_Store +0 -0
- package/templates/init/client/react/.DS_Store +0 -0
- package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
|
@@ -1,284 +1,376 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
const utils = require('./utils');
|
|
2
|
+
|
|
3
3
|
class Cell {
|
|
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
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A representation of a cell within the table.
|
|
6
|
+
* Implementations must have `init` and `draw` methods,
|
|
7
|
+
* as well as `colSpan`, `rowSpan`, `desiredHeight` and `desiredWidth` properties.
|
|
8
|
+
* @param options
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.setOptions(options);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Each cell will have it's `x` and `y` values set by the `layout-manager` prior to
|
|
16
|
+
* `init` being called;
|
|
17
|
+
* @type {Number}
|
|
18
|
+
*/
|
|
19
|
+
this.x = null;
|
|
20
|
+
this.y = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setOptions(options) {
|
|
24
|
+
if (['boolean', 'number', 'string'].indexOf(typeof options) !== -1) {
|
|
25
|
+
options = { content: '' + options };
|
|
26
|
+
}
|
|
27
|
+
options = options || {};
|
|
28
|
+
this.options = options;
|
|
29
|
+
const content = options.content;
|
|
30
|
+
if (['boolean', 'number', 'string'].indexOf(typeof content) !== -1) {
|
|
31
|
+
this.content = String(content);
|
|
32
|
+
} else if (!content) {
|
|
33
|
+
this.content = '';
|
|
34
|
+
} else {
|
|
35
|
+
throw new Error('Content needs to be a primitive, got: ' + typeof content);
|
|
36
|
+
}
|
|
37
|
+
this.colSpan = options.colSpan || 1;
|
|
38
|
+
this.rowSpan = options.rowSpan || 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
mergeTableOptions(tableOptions, cells) {
|
|
42
|
+
this.cells = cells;
|
|
43
|
+
|
|
44
|
+
const optionsChars = this.options.chars || {};
|
|
45
|
+
const tableChars = tableOptions.chars;
|
|
46
|
+
const chars = (this.chars = {});
|
|
47
|
+
CHAR_NAMES.forEach((name) => {
|
|
48
|
+
setOption(optionsChars, tableChars, name, chars);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.truncate = this.options.truncate || tableOptions.truncate;
|
|
52
|
+
|
|
53
|
+
const style = (this.options.style = this.options.style || {});
|
|
54
|
+
const tableStyle = tableOptions.style;
|
|
55
|
+
setOption(style, tableStyle, 'padding-left', this);
|
|
56
|
+
setOption(style, tableStyle, 'padding-right', this);
|
|
57
|
+
this.head = style.head || tableStyle.head;
|
|
58
|
+
this.border = style.border || tableStyle.border;
|
|
59
|
+
|
|
60
|
+
let fixedWidth = tableOptions.colWidths[this.x];
|
|
61
|
+
if (tableOptions.wordWrap && fixedWidth) {
|
|
62
|
+
fixedWidth -= this.paddingLeft + this.paddingRight;
|
|
63
|
+
if (this.colSpan) {
|
|
64
|
+
let i = 1;
|
|
65
|
+
while (i < this.colSpan) {
|
|
66
|
+
fixedWidth += tableOptions.colWidths[this.x + i];
|
|
67
|
+
i++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.lines = utils.colorizeLines(utils.wordWrap(fixedWidth, this.content));
|
|
71
|
+
} else {
|
|
72
|
+
this.lines = utils.colorizeLines(this.content.split('\n'));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.desiredWidth = utils.strlen(this.content) + this.paddingLeft + this.paddingRight;
|
|
76
|
+
this.desiredHeight = this.lines.length;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Initializes the Cells data structure.
|
|
81
|
+
*
|
|
82
|
+
* @param tableOptions - A fully populated set of tableOptions.
|
|
83
|
+
* In addition to the standard default values, tableOptions must have fully populated the
|
|
84
|
+
* `colWidths` and `rowWidths` arrays. Those arrays must have lengths equal to the number
|
|
85
|
+
* of columns or rows (respectively) in this table, and each array item must be a Number.
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
init(tableOptions) {
|
|
89
|
+
const x = this.x;
|
|
90
|
+
const y = this.y;
|
|
91
|
+
this.widths = tableOptions.colWidths.slice(x, x + this.colSpan);
|
|
92
|
+
this.heights = tableOptions.rowHeights.slice(y, y + this.rowSpan);
|
|
93
|
+
this.width = this.widths.reduce(sumPlusOne, -1);
|
|
94
|
+
this.height = this.heights.reduce(sumPlusOne, -1);
|
|
95
|
+
|
|
96
|
+
this.hAlign = this.options.hAlign || tableOptions.colAligns[x];
|
|
97
|
+
this.vAlign = this.options.vAlign || tableOptions.rowAligns[y];
|
|
98
|
+
|
|
99
|
+
this.drawRight = x + this.colSpan == tableOptions.colWidths.length;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Draws the given line of the cell.
|
|
104
|
+
* This default implementation defers to methods `drawTop`, `drawBottom`, `drawLine` and `drawEmpty`.
|
|
105
|
+
* @param lineNum - can be `top`, `bottom` or a numerical line number.
|
|
106
|
+
* @param spanningCell - will be a number if being called from a RowSpanCell, and will represent how
|
|
107
|
+
* many rows below it's being called from. Otherwise it's undefined.
|
|
108
|
+
* @returns {String} The representation of this line.
|
|
109
|
+
*/
|
|
110
|
+
draw(lineNum, spanningCell) {
|
|
111
|
+
if (lineNum == 'top') {
|
|
112
|
+
return this.drawTop(this.drawRight);
|
|
113
|
+
}
|
|
114
|
+
if (lineNum == 'bottom') {
|
|
115
|
+
return this.drawBottom(this.drawRight);
|
|
116
|
+
}
|
|
117
|
+
const padLen = Math.max(this.height - this.lines.length, 0);
|
|
118
|
+
let padTop;
|
|
119
|
+
switch (this.vAlign) {
|
|
120
|
+
case 'center':
|
|
121
|
+
padTop = Math.ceil(padLen / 2);
|
|
122
|
+
break;
|
|
123
|
+
case 'bottom':
|
|
124
|
+
padTop = padLen;
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
padTop = 0;
|
|
128
|
+
}
|
|
129
|
+
if (lineNum < padTop || lineNum >= padTop + this.lines.length) {
|
|
130
|
+
return this.drawEmpty(this.drawRight, spanningCell);
|
|
131
|
+
}
|
|
132
|
+
const forceTruncation = this.lines.length > this.height && lineNum + 1 >= this.height;
|
|
133
|
+
return this.drawLine(lineNum - padTop, this.drawRight, forceTruncation, spanningCell);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Renders the top line of the cell.
|
|
138
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
139
|
+
* @returns {String}
|
|
140
|
+
*/
|
|
141
|
+
drawTop(drawRight) {
|
|
142
|
+
const content = [];
|
|
143
|
+
if (this.cells) {
|
|
144
|
+
// TODO: cells should always exist - some tests don't fill it in though
|
|
145
|
+
this.widths.forEach(function (width, index) {
|
|
146
|
+
content.push(this._topLeftChar(index));
|
|
147
|
+
content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], width));
|
|
148
|
+
}, this);
|
|
149
|
+
} else {
|
|
150
|
+
content.push(this._topLeftChar(0));
|
|
151
|
+
content.push(utils.repeat(this.chars[this.y == 0 ? 'top' : 'mid'], this.width));
|
|
152
|
+
}
|
|
153
|
+
if (drawRight) {
|
|
154
|
+
content.push(this.chars[this.y == 0 ? 'topRight' : 'rightMid']);
|
|
155
|
+
}
|
|
156
|
+
return this.wrapWithStyleColors('border', content.join(''));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
_topLeftChar(offset) {
|
|
160
|
+
const x = this.x + offset;
|
|
161
|
+
let leftChar;
|
|
162
|
+
if (this.y == 0) {
|
|
163
|
+
leftChar = x == 0 ? 'topLeft' : offset == 0 ? 'topMid' : 'top';
|
|
164
|
+
} else {
|
|
165
|
+
if (x == 0) {
|
|
166
|
+
leftChar = 'leftMid';
|
|
167
|
+
} else {
|
|
168
|
+
leftChar = offset == 0 ? 'midMid' : 'bottomMid';
|
|
169
|
+
if (this.cells) {
|
|
170
|
+
// TODO: cells should always exist - some tests don't fill it in though
|
|
171
|
+
const spanAbove = this.cells[this.y - 1][x] instanceof Cell.ColSpanCell;
|
|
172
|
+
if (spanAbove) {
|
|
173
|
+
leftChar = offset == 0 ? 'topMid' : 'mid';
|
|
174
|
+
}
|
|
175
|
+
if (offset == 0) {
|
|
176
|
+
let i = 1;
|
|
177
|
+
while (this.cells[this.y][x - i] instanceof Cell.ColSpanCell) {
|
|
178
|
+
i++;
|
|
179
|
+
}
|
|
180
|
+
if (this.cells[this.y][x - i] instanceof Cell.RowSpanCell) {
|
|
181
|
+
leftChar = 'leftMid';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return this.chars[leftChar];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
wrapWithStyleColors(styleProperty, content) {
|
|
191
|
+
if (this[styleProperty] && this[styleProperty].length) {
|
|
192
|
+
try {
|
|
193
|
+
let colors = require('colors/safe');
|
|
194
|
+
for (let i = this[styleProperty].length - 1; i >= 0; i--) {
|
|
195
|
+
colors = colors[this[styleProperty][i]];
|
|
196
|
+
}
|
|
197
|
+
return colors(content);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
return content;
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
return content;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Renders a line of text.
|
|
208
|
+
* @param lineNum - Which line of text to render. This is not necessarily the line within the cell.
|
|
209
|
+
* There may be top-padding above the first line of text.
|
|
210
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
211
|
+
* @param forceTruncationSymbol - `true` if the rendered text should end with the truncation symbol even
|
|
212
|
+
* if the text fits. This is used when the cell is vertically truncated. If `false` the text should
|
|
213
|
+
* only include the truncation symbol if the text will not fit horizontally within the cell width.
|
|
214
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
215
|
+
* @returns {String}
|
|
216
|
+
*/
|
|
217
|
+
drawLine(lineNum, drawRight, forceTruncationSymbol, spanningCell) {
|
|
218
|
+
let left = this.chars[this.x == 0 ? 'left' : 'middle'];
|
|
219
|
+
if (this.x && spanningCell && this.cells) {
|
|
220
|
+
let cellLeft = this.cells[this.y + spanningCell][this.x - 1];
|
|
221
|
+
while (cellLeft instanceof ColSpanCell) {
|
|
222
|
+
cellLeft = this.cells[cellLeft.y][cellLeft.x - 1];
|
|
223
|
+
}
|
|
224
|
+
if (!(cellLeft instanceof RowSpanCell)) {
|
|
225
|
+
left = this.chars.rightMid;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const leftPadding = utils.repeat(' ', this.paddingLeft);
|
|
229
|
+
const right = drawRight ? this.chars.right : '';
|
|
230
|
+
const rightPadding = utils.repeat(' ', this.paddingRight);
|
|
231
|
+
let line = this.lines[lineNum];
|
|
232
|
+
const len = this.width - (this.paddingLeft + this.paddingRight);
|
|
233
|
+
if (forceTruncationSymbol) {
|
|
234
|
+
line += this.truncate || '…';
|
|
235
|
+
}
|
|
236
|
+
let content = utils.truncate(line, len, this.truncate);
|
|
237
|
+
content = utils.pad(content, len, ' ', this.hAlign);
|
|
238
|
+
content = leftPadding + content + rightPadding;
|
|
239
|
+
return this.stylizeLine(left, content, right);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
stylizeLine(left, content, right) {
|
|
243
|
+
left = this.wrapWithStyleColors('border', left);
|
|
244
|
+
right = this.wrapWithStyleColors('border', right);
|
|
245
|
+
if (this.y === 0) {
|
|
246
|
+
content = this.wrapWithStyleColors('head', content);
|
|
247
|
+
}
|
|
248
|
+
return left + content + right;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Renders the bottom line of the cell.
|
|
253
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
254
|
+
* @returns {String}
|
|
255
|
+
*/
|
|
256
|
+
drawBottom(drawRight) {
|
|
257
|
+
const left = this.chars[this.x == 0 ? 'bottomLeft' : 'bottomMid'];
|
|
258
|
+
const content = utils.repeat(this.chars.bottom, this.width);
|
|
259
|
+
const right = drawRight ? this.chars.bottomRight : '';
|
|
260
|
+
return this.wrapWithStyleColors('border', left + content + right);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Renders a blank line of text within the cell. Used for top and/or bottom padding.
|
|
265
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
266
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
267
|
+
* @returns {String}
|
|
268
|
+
*/
|
|
269
|
+
drawEmpty(drawRight, spanningCell) {
|
|
270
|
+
let left = this.chars[this.x == 0 ? 'left' : 'middle'];
|
|
271
|
+
if (this.x && spanningCell && this.cells) {
|
|
272
|
+
let cellLeft = this.cells[this.y + spanningCell][this.x - 1];
|
|
273
|
+
while (cellLeft instanceof ColSpanCell) {
|
|
274
|
+
cellLeft = this.cells[cellLeft.y][cellLeft.x - 1];
|
|
275
|
+
}
|
|
276
|
+
if (!(cellLeft instanceof RowSpanCell)) {
|
|
277
|
+
left = this.chars.rightMid;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const right = drawRight ? this.chars.right : '';
|
|
281
|
+
const content = utils.repeat(' ', this.width);
|
|
282
|
+
return this.stylizeLine(left, content, right);
|
|
283
|
+
}
|
|
215
284
|
}
|
|
285
|
+
|
|
216
286
|
class ColSpanCell {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
287
|
+
/**
|
|
288
|
+
* A Cell that doesn't do anything. It just draws empty lines.
|
|
289
|
+
* Used as a placeholder in column spanning.
|
|
290
|
+
* @constructor
|
|
291
|
+
*/
|
|
292
|
+
constructor() {}
|
|
293
|
+
|
|
294
|
+
draw() {
|
|
295
|
+
return '';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
init() {}
|
|
299
|
+
|
|
300
|
+
mergeTableOptions() {}
|
|
223
301
|
}
|
|
302
|
+
|
|
224
303
|
class RowSpanCell {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
304
|
+
/**
|
|
305
|
+
* A placeholder Cell for a Cell that spans multiple rows.
|
|
306
|
+
* It delegates rendering to the original cell, but adds the appropriate offset.
|
|
307
|
+
* @param originalCell
|
|
308
|
+
* @constructor
|
|
309
|
+
*/
|
|
310
|
+
constructor(originalCell) {
|
|
311
|
+
this.originalCell = originalCell;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
init(tableOptions) {
|
|
315
|
+
const y = this.y;
|
|
316
|
+
const originalY = this.originalCell.y;
|
|
317
|
+
this.cellOffset = y - originalY;
|
|
318
|
+
this.offset = findDimension(tableOptions.rowHeights, originalY, this.cellOffset);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
draw(lineNum) {
|
|
322
|
+
if (lineNum == 'top') {
|
|
323
|
+
return this.originalCell.draw(this.offset, this.cellOffset);
|
|
324
|
+
}
|
|
325
|
+
if (lineNum == 'bottom') {
|
|
326
|
+
return this.originalCell.draw('bottom');
|
|
327
|
+
}
|
|
328
|
+
return this.originalCell.draw(this.offset + 1 + lineNum);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
mergeTableOptions() {}
|
|
244
332
|
}
|
|
333
|
+
|
|
334
|
+
// HELPER FUNCTIONS
|
|
245
335
|
function setOption(objA, objB, nameB, targetObj) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
336
|
+
let nameA = nameB.split('-');
|
|
337
|
+
if (nameA.length > 1) {
|
|
338
|
+
nameA[1] = nameA[1].charAt(0).toUpperCase() + nameA[1].substr(1);
|
|
339
|
+
nameA = nameA.join('');
|
|
340
|
+
targetObj[nameA] = objA[nameA] || objA[nameB] || objB[nameA] || objB[nameB];
|
|
341
|
+
} else {
|
|
342
|
+
targetObj[nameB] = objA[nameB] || objB[nameB];
|
|
343
|
+
}
|
|
255
344
|
}
|
|
345
|
+
|
|
256
346
|
function findDimension(dimensionTable, startingIndex, span) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
347
|
+
let ret = dimensionTable[startingIndex];
|
|
348
|
+
for (let i = 1; i < span; i++) {
|
|
349
|
+
ret += 1 + dimensionTable[startingIndex + i];
|
|
350
|
+
}
|
|
351
|
+
return ret;
|
|
262
352
|
}
|
|
353
|
+
|
|
263
354
|
function sumPlusOne(a, b) {
|
|
264
|
-
|
|
355
|
+
return a + b + 1;
|
|
265
356
|
}
|
|
357
|
+
|
|
266
358
|
const CHAR_NAMES = [
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
359
|
+
'top',
|
|
360
|
+
'top-mid',
|
|
361
|
+
'top-left',
|
|
362
|
+
'top-right',
|
|
363
|
+
'bottom',
|
|
364
|
+
'bottom-mid',
|
|
365
|
+
'bottom-left',
|
|
366
|
+
'bottom-right',
|
|
367
|
+
'left',
|
|
368
|
+
'left-mid',
|
|
369
|
+
'mid',
|
|
370
|
+
'mid-mid',
|
|
371
|
+
'right',
|
|
372
|
+
'right-mid',
|
|
373
|
+
'middle'
|
|
282
374
|
];
|
|
283
375
|
module.exports = Cell;
|
|
284
376
|
module.exports.ColSpanCell = ColSpanCell;
|