tty-table 6.1.0 → 7.0.1

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/cli.mjs CHANGED
@@ -31,351 +31,181 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
31
31
  mod
32
32
  ));
33
33
 
34
- // node_modules/clone/clone.js
35
- var require_clone = __commonJS({
36
- "node_modules/clone/clone.js"(exports, module) {
34
+ // node_modules/breakword/src/main.js
35
+ var require_main = __commonJS({
36
+ "node_modules/breakword/src/main.js"(exports, module) {
37
37
  "use strict";
38
- var clone = (function() {
39
- "use strict";
40
- function clone2(parent, circular, depth, prototype) {
41
- var filter;
42
- if (typeof circular === "object") {
43
- depth = circular.depth;
44
- prototype = circular.prototype;
45
- filter = circular.filter;
46
- circular = circular.circular;
47
- }
48
- var allParents = [];
49
- var allChildren = [];
50
- var useBuffer = typeof Buffer != "undefined";
51
- if (typeof circular == "undefined")
52
- circular = true;
53
- if (typeof depth == "undefined")
54
- depth = Infinity;
55
- function _clone(parent2, depth2) {
56
- if (parent2 === null)
57
- return null;
58
- if (depth2 == 0)
59
- return parent2;
60
- var child;
61
- var proto;
62
- if (typeof parent2 != "object") {
63
- return parent2;
64
- }
65
- if (clone2.__isArray(parent2)) {
66
- child = [];
67
- } else if (clone2.__isRegExp(parent2)) {
68
- child = new RegExp(parent2.source, __getRegExpFlags(parent2));
69
- if (parent2.lastIndex) child.lastIndex = parent2.lastIndex;
70
- } else if (clone2.__isDate(parent2)) {
71
- child = new Date(parent2.getTime());
72
- } else if (useBuffer && Buffer.isBuffer(parent2)) {
73
- if (Buffer.allocUnsafe) {
74
- child = Buffer.allocUnsafe(parent2.length);
75
- } else {
76
- child = new Buffer(parent2.length);
77
- }
78
- parent2.copy(child);
79
- return child;
80
- } else {
81
- if (typeof prototype == "undefined") {
82
- proto = Object.getPrototypeOf(parent2);
83
- child = Object.create(proto);
84
- } else {
85
- child = Object.create(prototype);
86
- proto = prototype;
87
- }
88
- }
89
- if (circular) {
90
- var index = allParents.indexOf(parent2);
91
- if (index != -1) {
92
- return allChildren[index];
93
- }
94
- allParents.push(parent2);
95
- allChildren.push(child);
96
- }
97
- for (var i in parent2) {
98
- var attrs;
99
- if (proto) {
100
- attrs = Object.getOwnPropertyDescriptor(proto, i);
101
- }
102
- if (attrs && attrs.set == null) {
103
- continue;
104
- }
105
- child[i] = _clone(parent2[i], depth2 - 1);
106
- }
107
- return child;
108
- }
109
- return _clone(parent, depth);
110
- }
111
- clone2.clonePrototype = function clonePrototype(parent) {
112
- if (parent === null)
113
- return null;
114
- var c = function() {
115
- };
116
- c.prototype = parent;
117
- return new c();
118
- };
119
- function __objToStr(o) {
120
- return Object.prototype.toString.call(o);
121
- }
122
- ;
123
- clone2.__objToStr = __objToStr;
124
- function __isDate(o) {
125
- return typeof o === "object" && __objToStr(o) === "[object Date]";
126
- }
127
- ;
128
- clone2.__isDate = __isDate;
129
- function __isArray(o) {
130
- return typeof o === "object" && __objToStr(o) === "[object Array]";
38
+ var UNICODE_VERSION = "18.0.0";
39
+ var WIDE_RANGES = [
40
+ [4352, 4447],
41
+ [8986, 8987],
42
+ [9001, 9002],
43
+ [9193, 9196],
44
+ [9200, 9200],
45
+ [9203, 9203],
46
+ [9725, 9726],
47
+ [9748, 9749],
48
+ [9776, 9783],
49
+ [9800, 9811],
50
+ [9855, 9855],
51
+ [9866, 9871],
52
+ [9875, 9875],
53
+ [9889, 9889],
54
+ [9898, 9899],
55
+ [9917, 9918],
56
+ [9924, 9925],
57
+ [9934, 9934],
58
+ [9940, 9940],
59
+ [9962, 9962],
60
+ [9970, 9971],
61
+ [9973, 9973],
62
+ [9978, 9978],
63
+ [9981, 9981],
64
+ [9989, 9989],
65
+ [9994, 9995],
66
+ [10024, 10024],
67
+ [10060, 10060],
68
+ [10062, 10062],
69
+ [10067, 10069],
70
+ [10071, 10071],
71
+ [10133, 10135],
72
+ [10160, 10160],
73
+ [10175, 10175],
74
+ [11035, 11036],
75
+ [11088, 11088],
76
+ [11093, 11093],
77
+ [11904, 11929],
78
+ [11931, 12019],
79
+ [12032, 12245],
80
+ [12272, 12350],
81
+ [12353, 12438],
82
+ [12441, 12543],
83
+ [12549, 12591],
84
+ [12593, 12686],
85
+ [12688, 12773],
86
+ [12783, 12830],
87
+ [12832, 12871],
88
+ [12880, 42124],
89
+ [42128, 42182],
90
+ [43360, 43388],
91
+ [44032, 55203],
92
+ [63744, 64255],
93
+ [65040, 65049],
94
+ [65072, 65106],
95
+ [65108, 65126],
96
+ [65128, 65131],
97
+ [65281, 65376],
98
+ [65504, 65510],
99
+ [94176, 94180],
100
+ [94192, 94198],
101
+ [94208, 101594],
102
+ [101631, 101664],
103
+ [101760, 101874],
104
+ [101888, 102801],
105
+ [102816, 102866],
106
+ [110576, 110579],
107
+ [110581, 110587],
108
+ [110589, 110590],
109
+ [110592, 110888],
110
+ [110898, 110898],
111
+ [110928, 110930],
112
+ [110933, 110933],
113
+ [110948, 110952],
114
+ [110960, 111355],
115
+ [119552, 119638],
116
+ [119648, 119670],
117
+ [126980, 126980],
118
+ [127183, 127183],
119
+ [127374, 127374],
120
+ [127377, 127386],
121
+ [127406, 127406],
122
+ [127488, 127490],
123
+ [127504, 127547],
124
+ [127552, 127560],
125
+ [127568, 127569],
126
+ [127584, 127589],
127
+ [127744, 127776],
128
+ [127789, 127797],
129
+ [127799, 127868],
130
+ [127870, 127891],
131
+ [127904, 127946],
132
+ [127951, 127955],
133
+ [127968, 127984],
134
+ [127988, 127988],
135
+ [127992, 128062],
136
+ [128064, 128064],
137
+ [128066, 128252],
138
+ [128255, 128317],
139
+ [128331, 128334],
140
+ [128336, 128359],
141
+ [128378, 128378],
142
+ [128405, 128406],
143
+ [128420, 128420],
144
+ [128507, 128591],
145
+ [128640, 128709],
146
+ [128716, 128716],
147
+ [128720, 128722],
148
+ [128725, 128729],
149
+ [128732, 128735],
150
+ [128747, 128748],
151
+ [128756, 128764],
152
+ [128986, 128986],
153
+ [128992, 129003],
154
+ [129008, 129008],
155
+ [129292, 129338],
156
+ [129340, 129349],
157
+ [129351, 129535],
158
+ [129648, 129660],
159
+ [129664, 129734],
160
+ [129736, 129736],
161
+ [129740, 129757],
162
+ [129759, 129771],
163
+ [129775, 129786],
164
+ [131072, 196605],
165
+ [196608, 262141]
166
+ ];
167
+ var cell = (cp) => cp <= 65535 ? `\\u${cp.toString(16).toUpperCase().padStart(4, "0")}` : `\\u{${cp.toString(16).toUpperCase()}}`;
168
+ var WIDE = new RegExp(
169
+ "[" + WIDE_RANGES.map(([lo, hi]) => cell(lo) + (hi > lo ? `-${cell(hi)}` : "")).join("") + "]",
170
+ "u"
171
+ );
172
+ var ZERO = /[\u200B\p{Mn}\p{Me}\p{Cf}\u1160-\u11FF]/u;
173
+ var EMOJI = /\p{Emoji_Presentation}/u;
174
+ function width(char) {
175
+ if (typeof char !== "string") {
176
+ throw new TypeError("width() expects a string");
131
177
  }
132
- ;
133
- clone2.__isArray = __isArray;
134
- function __isRegExp(o) {
135
- return typeof o === "object" && __objToStr(o) === "[object RegExp]";
178
+ if (char.length === 0) {
179
+ return 0;
136
180
  }
137
- ;
138
- clone2.__isRegExp = __isRegExp;
139
- function __getRegExpFlags(re) {
140
- var flags = "";
141
- if (re.global) flags += "g";
142
- if (re.ignoreCase) flags += "i";
143
- if (re.multiline) flags += "m";
144
- return flags;
181
+ if (char.length > 1 && [...char].length > 1) {
182
+ throw new TypeError("width() expects exactly one Unicode code point");
145
183
  }
146
- ;
147
- clone2.__getRegExpFlags = __getRegExpFlags;
148
- return clone2;
149
- })();
150
- if (typeof module === "object" && module.exports) {
151
- module.exports = clone;
184
+ const cp = char.codePointAt(0);
185
+ if (cp < 32 || cp >= 127 && cp < 160) return 0;
186
+ if (cp === 173) return 1;
187
+ if (ZERO.test(char)) return 0;
188
+ if (EMOJI.test(char) && !(cp >= 127462 && cp <= 127487)) return 2;
189
+ return WIDE.test(char) ? 2 : 1;
152
190
  }
153
- }
154
- });
155
-
156
- // node_modules/defaults/index.js
157
- var require_defaults = __commonJS({
158
- "node_modules/defaults/index.js"(exports, module) {
159
- "use strict";
160
- var clone = require_clone();
161
- module.exports = function(options, defaults2) {
162
- options = options || {};
163
- Object.keys(defaults2).forEach(function(key) {
164
- if (typeof options[key] === "undefined") {
165
- options[key] = clone(defaults2[key]);
191
+ module.exports = function breakword2(input, breakAtLength) {
192
+ const str = String(input);
193
+ let indexOfLastFitChar = 0;
194
+ let fittableLength = 0;
195
+ let index = 0;
196
+ for (const char of str) {
197
+ const currentLength = fittableLength + width(char);
198
+ if (currentLength > breakAtLength) {
199
+ break;
166
200
  }
167
- });
168
- return options;
169
- };
170
- }
171
- });
172
-
173
- // node_modules/wcwidth/combining.js
174
- var require_combining = __commonJS({
175
- "node_modules/wcwidth/combining.js"(exports, module) {
176
- "use strict";
177
- module.exports = [
178
- [768, 879],
179
- [1155, 1158],
180
- [1160, 1161],
181
- [1425, 1469],
182
- [1471, 1471],
183
- [1473, 1474],
184
- [1476, 1477],
185
- [1479, 1479],
186
- [1536, 1539],
187
- [1552, 1557],
188
- [1611, 1630],
189
- [1648, 1648],
190
- [1750, 1764],
191
- [1767, 1768],
192
- [1770, 1773],
193
- [1807, 1807],
194
- [1809, 1809],
195
- [1840, 1866],
196
- [1958, 1968],
197
- [2027, 2035],
198
- [2305, 2306],
199
- [2364, 2364],
200
- [2369, 2376],
201
- [2381, 2381],
202
- [2385, 2388],
203
- [2402, 2403],
204
- [2433, 2433],
205
- [2492, 2492],
206
- [2497, 2500],
207
- [2509, 2509],
208
- [2530, 2531],
209
- [2561, 2562],
210
- [2620, 2620],
211
- [2625, 2626],
212
- [2631, 2632],
213
- [2635, 2637],
214
- [2672, 2673],
215
- [2689, 2690],
216
- [2748, 2748],
217
- [2753, 2757],
218
- [2759, 2760],
219
- [2765, 2765],
220
- [2786, 2787],
221
- [2817, 2817],
222
- [2876, 2876],
223
- [2879, 2879],
224
- [2881, 2883],
225
- [2893, 2893],
226
- [2902, 2902],
227
- [2946, 2946],
228
- [3008, 3008],
229
- [3021, 3021],
230
- [3134, 3136],
231
- [3142, 3144],
232
- [3146, 3149],
233
- [3157, 3158],
234
- [3260, 3260],
235
- [3263, 3263],
236
- [3270, 3270],
237
- [3276, 3277],
238
- [3298, 3299],
239
- [3393, 3395],
240
- [3405, 3405],
241
- [3530, 3530],
242
- [3538, 3540],
243
- [3542, 3542],
244
- [3633, 3633],
245
- [3636, 3642],
246
- [3655, 3662],
247
- [3761, 3761],
248
- [3764, 3769],
249
- [3771, 3772],
250
- [3784, 3789],
251
- [3864, 3865],
252
- [3893, 3893],
253
- [3895, 3895],
254
- [3897, 3897],
255
- [3953, 3966],
256
- [3968, 3972],
257
- [3974, 3975],
258
- [3984, 3991],
259
- [3993, 4028],
260
- [4038, 4038],
261
- [4141, 4144],
262
- [4146, 4146],
263
- [4150, 4151],
264
- [4153, 4153],
265
- [4184, 4185],
266
- [4448, 4607],
267
- [4959, 4959],
268
- [5906, 5908],
269
- [5938, 5940],
270
- [5970, 5971],
271
- [6002, 6003],
272
- [6068, 6069],
273
- [6071, 6077],
274
- [6086, 6086],
275
- [6089, 6099],
276
- [6109, 6109],
277
- [6155, 6157],
278
- [6313, 6313],
279
- [6432, 6434],
280
- [6439, 6440],
281
- [6450, 6450],
282
- [6457, 6459],
283
- [6679, 6680],
284
- [6912, 6915],
285
- [6964, 6964],
286
- [6966, 6970],
287
- [6972, 6972],
288
- [6978, 6978],
289
- [7019, 7027],
290
- [7616, 7626],
291
- [7678, 7679],
292
- [8203, 8207],
293
- [8234, 8238],
294
- [8288, 8291],
295
- [8298, 8303],
296
- [8400, 8431],
297
- [12330, 12335],
298
- [12441, 12442],
299
- [43014, 43014],
300
- [43019, 43019],
301
- [43045, 43046],
302
- [64286, 64286],
303
- [65024, 65039],
304
- [65056, 65059],
305
- [65279, 65279],
306
- [65529, 65531],
307
- [68097, 68099],
308
- [68101, 68102],
309
- [68108, 68111],
310
- [68152, 68154],
311
- [68159, 68159],
312
- [119143, 119145],
313
- [119155, 119170],
314
- [119173, 119179],
315
- [119210, 119213],
316
- [119362, 119364],
317
- [917505, 917505],
318
- [917536, 917631],
319
- [917760, 917999]
320
- ];
321
- }
322
- });
323
-
324
- // node_modules/wcwidth/index.js
325
- var require_wcwidth = __commonJS({
326
- "node_modules/wcwidth/index.js"(exports, module) {
327
- "use strict";
328
- var defaults2 = require_defaults();
329
- var combining = require_combining();
330
- var DEFAULTS = {
331
- nul: 0,
332
- control: 0
333
- };
334
- module.exports = function wcwidth3(str) {
335
- return wcswidth(str, DEFAULTS);
336
- };
337
- module.exports.config = function(opts) {
338
- opts = defaults2(opts || {}, DEFAULTS);
339
- return function wcwidth3(str) {
340
- return wcswidth(str, opts);
341
- };
342
- };
343
- function wcswidth(str, opts) {
344
- if (typeof str !== "string") return wcwidth2(str, opts);
345
- var s = 0;
346
- for (var i = 0; i < str.length; i++) {
347
- var n = wcwidth2(str.charCodeAt(i), opts);
348
- if (n < 0) return -1;
349
- s += n;
201
+ indexOfLastFitChar = index;
202
+ fittableLength = currentLength;
203
+ index += 1;
350
204
  }
351
- return s;
352
- }
353
- function wcwidth2(ucs, opts) {
354
- if (ucs === 0) return opts.nul;
355
- if (ucs < 32 || ucs >= 127 && ucs < 160) return opts.control;
356
- if (bisearch(ucs)) return 0;
357
- return 1 + (ucs >= 4352 && (ucs <= 4447 || // Hangul Jamo init. consonants
358
- ucs == 9001 || ucs == 9002 || ucs >= 11904 && ucs <= 42191 && ucs != 12351 || // CJK ... Yi
359
- ucs >= 44032 && ucs <= 55203 || // Hangul Syllables
360
- ucs >= 63744 && ucs <= 64255 || // CJK Compatibility Ideographs
361
- ucs >= 65040 && ucs <= 65049 || // Vertical forms
362
- ucs >= 65072 && ucs <= 65135 || // CJK Compatibility Forms
363
- ucs >= 65280 && ucs <= 65376 || // Fullwidth Forms
364
- ucs >= 65504 && ucs <= 65510 || ucs >= 131072 && ucs <= 196605 || ucs >= 196608 && ucs <= 262141));
365
- }
366
- function bisearch(ucs) {
367
- var min = 0;
368
- var max = combining.length - 1;
369
- var mid;
370
- if (ucs < combining[0][0] || ucs > combining[max][1]) return false;
371
- while (max >= min) {
372
- mid = Math.floor((min + max) / 2);
373
- if (ucs > combining[mid][1]) min = mid + 1;
374
- else if (ucs < combining[mid][0]) max = mid - 1;
375
- else return true;
376
- }
377
- return false;
378
- }
205
+ return indexOfLastFitChar;
206
+ };
207
+ module.exports.width = width;
208
+ module.exports.internals = { UNICODE_VERSION, WIDE_RANGES, WIDE, ZERO, EMOJI, width };
379
209
  }
380
210
  });
381
211
 
@@ -462,24 +292,18 @@ var defaults_default = defaults;
462
292
 
463
293
  // src/style.ts
464
294
  import chalk from "chalk";
465
- import kleur from "kleur";
466
295
  import stripAnsi from "strip-ansi";
467
- var colorLib = process && process.stdout ? chalk : kleur;
468
- var style = (str, ...colors) => {
469
- const out = colors.reduce(function(input, color) {
470
- return colorLib[color](input);
471
- }, str);
472
- return out;
296
+ var colorLib = typeof process !== "undefined" && process.stdout ? chalk : new chalk.Instance({ level: 1 });
297
+ var colorize = (value, color) => {
298
+ const fn = colorLib[color];
299
+ return typeof fn === "function" ? fn(value) : value;
473
300
  };
301
+ var style = (str, ...colors) => colors.reduce(colorize, str);
474
302
  var styleEachChar = (str, ...colors) => {
475
303
  const chars = [...stripAnsi(str)];
476
- const out = chars.reduce((prev, current) => {
477
- const coded = colors.reduce((input, color) => {
478
- return colorLib[color](input);
479
- }, current);
480
- return prev + coded;
304
+ return chars.reduce((result, char) => {
305
+ return result + colors.reduce(colorize, char);
481
306
  }, "");
482
- return out;
483
307
  };
484
308
  var resetStyle = function(str) {
485
309
  this.configure({ reset: true });
@@ -502,25 +326,56 @@ var colorizeCell = (str, cellOptions, rowType) => {
502
326
  }
503
327
  return str;
504
328
  };
505
- var isColorEnabled = () => {
506
- return process && process.stdout ? colorLib.level > 0 : colorLib.enabled;
507
- };
329
+ var isColorEnabled = () => colorLib.level > 0;
508
330
 
509
331
  // src/format.ts
510
- var import_wcwidth = __toESM(require_wcwidth());
511
- import stripAnsi2 from "strip-ansi";
512
332
  import smartwrap from "smartwrap";
333
+
334
+ // src/ansi.ts
335
+ var import_breakword = __toESM(require_main());
336
+ var ANSI = /\u001B\[[0-?]*[ -\/]*[@-~]/g;
337
+ var codes = {
338
+ reset: "0",
339
+ bold: "1",
340
+ dim: "2",
341
+ italic: "3",
342
+ underline: "4",
343
+ inverse: "7",
344
+ hidden: "8",
345
+ strikethrough: "9",
346
+ black: "30",
347
+ red: "31",
348
+ green: "32",
349
+ yellow: "33",
350
+ blue: "34",
351
+ magenta: "35",
352
+ cyan: "36",
353
+ white: "37",
354
+ gray: "90",
355
+ grey: "90",
356
+ bgBlack: "40",
357
+ bgRed: "41",
358
+ bgGreen: "42",
359
+ bgYellow: "43",
360
+ bgBlue: "44",
361
+ bgMagenta: "45",
362
+ bgCyan: "46",
363
+ bgWhite: "47"
364
+ };
365
+ var stripAnsi2 = (value) => value.replace(ANSI, "");
366
+ var codePointWidth = (value) => [...value].reduce((total, char) => total + import_breakword.default.width(char), 0);
367
+ var displayWidth = (value) => Math.max(0, ...stripAnsi2(value).split(/\r?\n/).map(codePointWidth));
368
+ var style2 = (value, ...styles) => {
369
+ const active = styles.map((s) => codes[s]).filter(Boolean);
370
+ return active.length ? `\x1B[${active.join(";")}m${value}\x1B[0m` : value;
371
+ };
372
+
373
+ // src/format.ts
513
374
  var addPadding = (config, width) => {
514
375
  return width + config.paddingLeft + config.paddingRight;
515
376
  };
516
377
  var getDisplayWidth = (value) => {
517
- const lines = stripAnsi2(value.toString()).split(/[\n\r]/);
518
- let widest = 0;
519
- for (const line of lines) {
520
- const width = (0, import_wcwidth.default)(line);
521
- if (width > widest) widest = width;
522
- }
523
- return widest;
378
+ return displayWidth(value.toString());
524
379
  };
525
380
  var getMaxLength = (columnOptions, rows, columnIndex) => {
526
381
  let widest = 0;
@@ -554,7 +409,7 @@ var getAvailableWidth = (config) => {
554
409
  return config.COLUMNS - config.marginLeft;
555
410
  };
556
411
  var getStringLength = (str) => {
557
- return (0, import_wcwidth.default)(stripAnsi2(str));
412
+ return displayWidth(str);
558
413
  };
559
414
  var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
560
415
  const startAnsiRegexp = /^(\x1b\[[0-9;]*m)+/;
@@ -613,10 +468,10 @@ var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
613
468
  return { cell, innerWidth };
614
469
  };
615
470
  var truncate = (str, cellOptions, maxWidth) => {
616
- const stringWidth = (0, import_wcwidth.default)(str);
471
+ const stringWidth = displayWidth(str);
617
472
  if (maxWidth < stringWidth) {
618
473
  str = smartwrap(str, {
619
- width: maxWidth - cellOptions.truncate.length,
474
+ width: maxWidth - displayWidth(cellOptions.truncate),
620
475
  breakword: true
621
476
  }).split("\n")[0];
622
477
  str = str + cellOptions.truncate;
@@ -957,40 +812,6 @@ var factory_default = Table;
957
812
  // src/index.ts
958
813
  var src_default = factory_default;
959
814
 
960
- // src/ansi.ts
961
- var codes = {
962
- reset: "0",
963
- bold: "1",
964
- dim: "2",
965
- italic: "3",
966
- underline: "4",
967
- inverse: "7",
968
- hidden: "8",
969
- strikethrough: "9",
970
- black: "30",
971
- red: "31",
972
- green: "32",
973
- yellow: "33",
974
- blue: "34",
975
- magenta: "35",
976
- cyan: "36",
977
- white: "37",
978
- gray: "90",
979
- grey: "90",
980
- bgBlack: "40",
981
- bgRed: "41",
982
- bgGreen: "42",
983
- bgYellow: "43",
984
- bgBlue: "44",
985
- bgMagenta: "45",
986
- bgCyan: "46",
987
- bgWhite: "47"
988
- };
989
- var style2 = (value, ...styles) => {
990
- const active = styles.map((s) => codes[s]).filter(Boolean);
991
- return active.length ? `\x1B[${active.join(";")}m${value}\x1B[0m` : value;
992
- };
993
-
994
815
  // src/cli.ts
995
816
  var main = async () => {
996
817
  const argv = await yargs(hideBin(process.argv)).options({