tty-table 6.0.1 → 7.0.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/README.md +61 -4
- package/dist/browser/tty-table.global.js +379 -3612
- package/dist/browser/tty-table.global.js.map +1 -1
- package/dist/browser.js +183 -352
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +181 -350
- package/dist/browser.mjs.map +1 -1
- package/dist/cli.js +215 -386
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +213 -384
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +183 -352
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +181 -350
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.d.mts +54 -0
- package/dist/mcp.d.ts +54 -0
- package/dist/mcp.js +937 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mcp.mjs +929 -0
- package/dist/mcp.mjs.map +1 -0
- package/package.json +10 -8
package/dist/mcp.mjs
ADDED
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
9
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
10
|
+
}) : x)(function(x) {
|
|
11
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
// node_modules/breakword/src/main.js
|
|
35
|
+
var require_main = __commonJS({
|
|
36
|
+
"node_modules/breakword/src/main.js"(exports, module) {
|
|
37
|
+
"use strict";
|
|
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");
|
|
177
|
+
}
|
|
178
|
+
if (char.length === 0) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
if (char.length > 1 && [...char].length > 1) {
|
|
182
|
+
throw new TypeError("width() expects exactly one Unicode code point");
|
|
183
|
+
}
|
|
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;
|
|
190
|
+
}
|
|
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;
|
|
200
|
+
}
|
|
201
|
+
indexOfLastFitChar = index;
|
|
202
|
+
fittableLength = currentLength;
|
|
203
|
+
index += 1;
|
|
204
|
+
}
|
|
205
|
+
return indexOfLastFitChar;
|
|
206
|
+
};
|
|
207
|
+
module.exports.width = width;
|
|
208
|
+
module.exports.internals = { UNICODE_VERSION, WIDE_RANGES, WIDE, ZERO, EMOJI, width };
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// src/mcp.ts
|
|
213
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
214
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
215
|
+
import { z } from "zod";
|
|
216
|
+
|
|
217
|
+
// src/defaults.ts
|
|
218
|
+
var defaults = {
|
|
219
|
+
borderCharacters: {
|
|
220
|
+
invisible: [
|
|
221
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " },
|
|
222
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " },
|
|
223
|
+
{ v: " ", l: " ", j: " ", h: " ", r: " " }
|
|
224
|
+
],
|
|
225
|
+
solid: [
|
|
226
|
+
{ v: "\u2502", l: "\u250C", j: "\u252C", h: "\u2500", r: "\u2510" },
|
|
227
|
+
{ v: "\u2502", l: "\u251C", j: "\u253C", h: "\u2500", r: "\u2524" },
|
|
228
|
+
{ v: "\u2502", l: "\u2514", j: "\u2534", h: "\u2500", r: "\u2518" }
|
|
229
|
+
],
|
|
230
|
+
dashed: [
|
|
231
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" },
|
|
232
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" },
|
|
233
|
+
{ v: "|", l: "+", j: "+", h: "-", r: "+" }
|
|
234
|
+
],
|
|
235
|
+
none: [
|
|
236
|
+
{ v: "", l: "", j: "", h: "", r: "" },
|
|
237
|
+
{ v: "", l: "", j: "", h: "", r: "" },
|
|
238
|
+
{ v: "", l: "", j: "", h: "", r: "" }
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
align: "center",
|
|
242
|
+
borderColor: null,
|
|
243
|
+
borderStyle: "solid",
|
|
244
|
+
color: false,
|
|
245
|
+
COLUMNS: 80,
|
|
246
|
+
// if !process.stdout.columns assume redirecting to write stream 80 columns is VT200 standard
|
|
247
|
+
compact: false,
|
|
248
|
+
defaultErrorValue: "\uFFFD",
|
|
249
|
+
defaultValue: "",
|
|
250
|
+
errorOnNull: false,
|
|
251
|
+
FIXED_WIDTH: false,
|
|
252
|
+
footerAlign: "center",
|
|
253
|
+
footerColor: false,
|
|
254
|
+
formatter: null,
|
|
255
|
+
headerAlign: "center",
|
|
256
|
+
headerColor: "yellow",
|
|
257
|
+
isNull: false,
|
|
258
|
+
// undocumented cell setting
|
|
259
|
+
marginLeft: 2,
|
|
260
|
+
marginTop: 1,
|
|
261
|
+
paddingBottom: 0,
|
|
262
|
+
paddingLeft: 1,
|
|
263
|
+
paddingRight: 1,
|
|
264
|
+
paddingTop: 0,
|
|
265
|
+
showHeader: null,
|
|
266
|
+
// undocumented
|
|
267
|
+
truncate: false,
|
|
268
|
+
width: "100%",
|
|
269
|
+
GUTTER: 1,
|
|
270
|
+
// undocumented
|
|
271
|
+
columnSettings: [],
|
|
272
|
+
// save so cell options can be merged into column options
|
|
273
|
+
table: {
|
|
274
|
+
body: "",
|
|
275
|
+
columnInnerWidths: [],
|
|
276
|
+
columnWidths: [],
|
|
277
|
+
columns: [],
|
|
278
|
+
footer: "",
|
|
279
|
+
header: "",
|
|
280
|
+
// post-rendered strings.
|
|
281
|
+
height: 0,
|
|
282
|
+
typeLocked: false
|
|
283
|
+
// once a table type is selected can't switch
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
defaults.borderCharacters["0"] = defaults.borderCharacters.none;
|
|
287
|
+
defaults.borderCharacters["1"] = defaults.borderCharacters.solid;
|
|
288
|
+
defaults.borderCharacters["2"] = defaults.borderCharacters.dashed;
|
|
289
|
+
var defaults_default = defaults;
|
|
290
|
+
|
|
291
|
+
// src/style.ts
|
|
292
|
+
import chalk from "chalk";
|
|
293
|
+
import kleur from "kleur";
|
|
294
|
+
import stripAnsi from "strip-ansi";
|
|
295
|
+
var colorLib = process && process.stdout ? chalk : kleur;
|
|
296
|
+
var style = (str, ...colors) => {
|
|
297
|
+
const out = colors.reduce(function(input, color) {
|
|
298
|
+
return colorLib[color](input);
|
|
299
|
+
}, str);
|
|
300
|
+
return out;
|
|
301
|
+
};
|
|
302
|
+
var styleEachChar = (str, ...colors) => {
|
|
303
|
+
const chars = [...stripAnsi(str)];
|
|
304
|
+
const out = chars.reduce((prev, current) => {
|
|
305
|
+
const coded = colors.reduce((input, color) => {
|
|
306
|
+
return colorLib[color](input);
|
|
307
|
+
}, current);
|
|
308
|
+
return prev + coded;
|
|
309
|
+
}, "");
|
|
310
|
+
return out;
|
|
311
|
+
};
|
|
312
|
+
var resetStyle = function(str) {
|
|
313
|
+
this.configure({ reset: true });
|
|
314
|
+
return stripAnsi(str);
|
|
315
|
+
};
|
|
316
|
+
var colorizeCell = (str, cellOptions, rowType) => {
|
|
317
|
+
let color = false;
|
|
318
|
+
switch (true) {
|
|
319
|
+
case rowType === "body":
|
|
320
|
+
color = cellOptions.color || color;
|
|
321
|
+
break;
|
|
322
|
+
case rowType === "header":
|
|
323
|
+
color = cellOptions.headerColor || color;
|
|
324
|
+
break;
|
|
325
|
+
default:
|
|
326
|
+
color = cellOptions.footerColor || color;
|
|
327
|
+
}
|
|
328
|
+
if (color) {
|
|
329
|
+
str = style(str, color);
|
|
330
|
+
}
|
|
331
|
+
return str;
|
|
332
|
+
};
|
|
333
|
+
var isColorEnabled = () => {
|
|
334
|
+
return process && process.stdout ? colorLib.level > 0 : colorLib.enabled;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/format.ts
|
|
338
|
+
import smartwrap from "smartwrap";
|
|
339
|
+
|
|
340
|
+
// src/ansi.ts
|
|
341
|
+
var import_breakword = __toESM(require_main());
|
|
342
|
+
var ANSI = /\u001B\[[0-?]*[ -\/]*[@-~]/g;
|
|
343
|
+
var stripAnsi2 = (value) => value.replace(ANSI, "");
|
|
344
|
+
var codePointWidth = (value) => [...value].reduce((total, char) => total + import_breakword.default.width(char), 0);
|
|
345
|
+
var displayWidth = (value) => Math.max(0, ...stripAnsi2(value).split(/\r?\n/).map(codePointWidth));
|
|
346
|
+
|
|
347
|
+
// src/format.ts
|
|
348
|
+
var addPadding = (config, width) => {
|
|
349
|
+
return width + config.paddingLeft + config.paddingRight;
|
|
350
|
+
};
|
|
351
|
+
var getDisplayWidth = (value) => {
|
|
352
|
+
return displayWidth(value.toString());
|
|
353
|
+
};
|
|
354
|
+
var getMaxLength = (columnOptions, rows, columnIndex) => {
|
|
355
|
+
let widest = 0;
|
|
356
|
+
if (columnOptions && (columnOptions.value || columnOptions.alias)) {
|
|
357
|
+
const value = columnOptions.alias || columnOptions.value;
|
|
358
|
+
widest = getDisplayWidth(value);
|
|
359
|
+
}
|
|
360
|
+
for (const row of rows) {
|
|
361
|
+
if (row[columnIndex]) {
|
|
362
|
+
const value = row[columnIndex].value ? row[columnIndex].value : row[columnIndex];
|
|
363
|
+
const width = getDisplayWidth(value);
|
|
364
|
+
if (width > widest) widest = width;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return widest;
|
|
368
|
+
};
|
|
369
|
+
var getAvailableWidth = (config) => {
|
|
370
|
+
if (process && (process.stdout && process.stdout.columns || process.env && process.env.COLUMNS)) {
|
|
371
|
+
let viewport = process.stdout && process.stdout.columns ? process.stdout.columns : process.env.COLUMNS;
|
|
372
|
+
viewport = viewport - config.marginLeft;
|
|
373
|
+
if (config.width !== "auto" && /^\d+%$/.test(config.width)) {
|
|
374
|
+
return Math.min(1, config.width.slice(0, -1) * 0.01) * viewport;
|
|
375
|
+
}
|
|
376
|
+
if (config.width !== "auto" && /^\d+$/.test(config.width)) {
|
|
377
|
+
config.FIXED_WIDTH = true;
|
|
378
|
+
return config.width;
|
|
379
|
+
}
|
|
380
|
+
return viewport;
|
|
381
|
+
}
|
|
382
|
+
if (typeof globalThis.window !== "undefined") return globalThis.window.innerWidth;
|
|
383
|
+
return config.COLUMNS - config.marginLeft;
|
|
384
|
+
};
|
|
385
|
+
var getStringLength = (str) => {
|
|
386
|
+
return displayWidth(str);
|
|
387
|
+
};
|
|
388
|
+
var wrapCellText = (config, cellValue, columnIndex, cellOptions, rowType) => {
|
|
389
|
+
const startAnsiRegexp = /^(\x1b\[[0-9;]*m)+/;
|
|
390
|
+
const endAnsiRegexp = /(\x1b\[[0-9;]*m)+$/;
|
|
391
|
+
let str = cellValue.toString();
|
|
392
|
+
const startMatches = str.match(startAnsiRegexp) || [""];
|
|
393
|
+
str = str.replace(startAnsiRegexp, "");
|
|
394
|
+
const endMatches = str.match(endAnsiRegexp) || [""];
|
|
395
|
+
str = str.replace(endAnsiRegexp, "");
|
|
396
|
+
let alignTgt;
|
|
397
|
+
switch (rowType) {
|
|
398
|
+
case "header":
|
|
399
|
+
alignTgt = "headerAlign";
|
|
400
|
+
break;
|
|
401
|
+
case "body":
|
|
402
|
+
alignTgt = "align";
|
|
403
|
+
break;
|
|
404
|
+
default:
|
|
405
|
+
alignTgt = "footerAlign";
|
|
406
|
+
}
|
|
407
|
+
if (cellOptions[alignTgt] === "center") {
|
|
408
|
+
cellOptions.paddingLeft = cellOptions.paddingRight = Math.max(
|
|
409
|
+
cellOptions.paddingRight,
|
|
410
|
+
cellOptions.paddingLeft,
|
|
411
|
+
0
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
const columnWidth = config.table.columnWidths[columnIndex];
|
|
415
|
+
const innerWidth = columnWidth - cellOptions.paddingLeft - cellOptions.paddingRight - config.GUTTER;
|
|
416
|
+
if (typeof config.truncate === "string") {
|
|
417
|
+
str = truncate(str, cellOptions, innerWidth);
|
|
418
|
+
} else {
|
|
419
|
+
str = wrap(str, cellOptions, innerWidth);
|
|
420
|
+
}
|
|
421
|
+
const cell = str.split("\n").map((line) => {
|
|
422
|
+
line = line.trim();
|
|
423
|
+
const lineLength = getStringLength(line);
|
|
424
|
+
if (lineLength < columnWidth) {
|
|
425
|
+
let emptySpace = columnWidth - lineLength;
|
|
426
|
+
switch (true) {
|
|
427
|
+
case cellOptions[alignTgt] === "center":
|
|
428
|
+
emptySpace--;
|
|
429
|
+
const padBoth = Math.floor(emptySpace / 2);
|
|
430
|
+
const padRemainder = emptySpace % 2;
|
|
431
|
+
line = " ".repeat(padBoth) + line + " ".repeat(padBoth + padRemainder);
|
|
432
|
+
break;
|
|
433
|
+
case cellOptions[alignTgt] === "right":
|
|
434
|
+
line = " ".repeat(emptySpace - cellOptions.paddingRight - 1) + line + " ".repeat(cellOptions.paddingRight);
|
|
435
|
+
break;
|
|
436
|
+
default:
|
|
437
|
+
line = " ".repeat(cellOptions.paddingLeft) + line + " ".repeat(emptySpace - cellOptions.paddingLeft - 1);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return startMatches[0] + line + endMatches[0];
|
|
441
|
+
});
|
|
442
|
+
return { cell, innerWidth };
|
|
443
|
+
};
|
|
444
|
+
var truncate = (str, cellOptions, maxWidth) => {
|
|
445
|
+
const stringWidth = displayWidth(str);
|
|
446
|
+
if (maxWidth < stringWidth) {
|
|
447
|
+
str = smartwrap(str, {
|
|
448
|
+
width: maxWidth - displayWidth(cellOptions.truncate),
|
|
449
|
+
breakword: true
|
|
450
|
+
}).split("\n")[0];
|
|
451
|
+
str = str + cellOptions.truncate;
|
|
452
|
+
}
|
|
453
|
+
return str;
|
|
454
|
+
};
|
|
455
|
+
var wrap = (str, cellOptions, innerWidth) => {
|
|
456
|
+
const outstring = smartwrap(str, {
|
|
457
|
+
errorChar: cellOptions.defaultErrorValue,
|
|
458
|
+
minWidth: 1,
|
|
459
|
+
trim: true,
|
|
460
|
+
width: innerWidth
|
|
461
|
+
});
|
|
462
|
+
return outstring;
|
|
463
|
+
};
|
|
464
|
+
var getColumnWidths = (config, rows) => {
|
|
465
|
+
const availableWidth = getAvailableWidth(config);
|
|
466
|
+
const iterable = config.table.header[0] && config.table.header[0].length > 0 ? config.table.header[0] : rows[0];
|
|
467
|
+
let widths = iterable.map((column, columnIndex) => {
|
|
468
|
+
let result;
|
|
469
|
+
switch (true) {
|
|
470
|
+
// column width is a percentage of table width specified in column header
|
|
471
|
+
case (typeof column === "object" && /^\d+%$/.test(column.width)):
|
|
472
|
+
result = column.width.slice(0, -1) * 0.01 * availableWidth;
|
|
473
|
+
result = addPadding(config, result);
|
|
474
|
+
break;
|
|
475
|
+
// column width is specified in column header
|
|
476
|
+
case (typeof column === "object" && /^\d+$/.test(column.width)):
|
|
477
|
+
result = column.width;
|
|
478
|
+
break;
|
|
479
|
+
// 'auto' sets column width to its longest value in the initial data set
|
|
480
|
+
default: {
|
|
481
|
+
const columnOptions = config.table.header[0][columnIndex] ? config.table.header[0][columnIndex] : {};
|
|
482
|
+
const measurableRows = rows.length ? rows : config.table.header[0];
|
|
483
|
+
result = getMaxLength(columnOptions, measurableRows, columnIndex);
|
|
484
|
+
result = addPadding(config, result);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
result = result + config.GUTTER;
|
|
488
|
+
return result;
|
|
489
|
+
});
|
|
490
|
+
const totalWidth = widths.reduce((prev, current) => prev + current);
|
|
491
|
+
if (totalWidth > availableWidth || config.FIXED_WIDTH) {
|
|
492
|
+
const proportion = (availableWidth / totalWidth).toFixed(2) - 0.01;
|
|
493
|
+
const relativeWidths = widths.map((value) => Math.max(2, Math.floor(proportion * value)));
|
|
494
|
+
if (config.FIXED_WIDTH) return relativeWidths;
|
|
495
|
+
if (proportion > 0) {
|
|
496
|
+
const totalRelativeWidths = relativeWidths.reduce((prev, current) => prev + current);
|
|
497
|
+
widths = totalRelativeWidths < totalWidth ? relativeWidths : widths;
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
widths = widths.map(Math.floor);
|
|
501
|
+
}
|
|
502
|
+
return widths;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/render.ts
|
|
506
|
+
import stripAnsi3 from "strip-ansi";
|
|
507
|
+
var stringifyData = (config, inputData) => {
|
|
508
|
+
const sections = { header: [], body: [], footer: [] };
|
|
509
|
+
const marginLeft = " ".repeat(config.marginLeft);
|
|
510
|
+
const borderStyle = config.borderCharacters[config.borderStyle];
|
|
511
|
+
const borders = [];
|
|
512
|
+
const constructorType = getConstructorGeometry(inputData[0] || [], config);
|
|
513
|
+
const rows = coerceConstructorGeometry(config, inputData, constructorType);
|
|
514
|
+
if (!global.columnWidths) global.columnWidths = {};
|
|
515
|
+
if (global.columnWidths[config.tableId]) {
|
|
516
|
+
config.table.columnWidths = global.columnWidths[config.tableId];
|
|
517
|
+
} else {
|
|
518
|
+
const formattedRows = rows.map((row, rowIndex) => {
|
|
519
|
+
return row.map((cell, cellIndex) => buildCell(config, cell, cellIndex, "body", rowIndex, rows, inputData, true));
|
|
520
|
+
});
|
|
521
|
+
global.columnWidths[config.tableId] = config.table.columnWidths = getColumnWidths(config, formattedRows);
|
|
522
|
+
}
|
|
523
|
+
switch (true) {
|
|
524
|
+
case (config.showHeader !== null && !config.showHeader):
|
|
525
|
+
sections.header = [];
|
|
526
|
+
break;
|
|
527
|
+
case config.showHeader === true:
|
|
528
|
+
case !!config.table.header[0].find((obj) => obj.value || obj.alias):
|
|
529
|
+
sections.header = config.table.header.map((row) => buildRow(config, row, "header", null, rows, inputData));
|
|
530
|
+
break;
|
|
531
|
+
default:
|
|
532
|
+
sections.header = [];
|
|
533
|
+
}
|
|
534
|
+
sections.body = rows.map((row, rowIndex) => buildRow(config, row, "body", rowIndex, rows, inputData));
|
|
535
|
+
sections.footer = config.table.footer instanceof Array && config.table.footer.length > 0 ? [config.table.footer] : [];
|
|
536
|
+
sections.footer = sections.footer.map((row) => buildRow(config, row, "footer", null, rows, inputData));
|
|
537
|
+
for (let a = 0; a < 3; a++) {
|
|
538
|
+
borders[a] = borderStyle[a].l;
|
|
539
|
+
config.table.columnWidths.forEach((columnWidth, index, arr) => {
|
|
540
|
+
borders[a] += borderStyle[a].h.repeat(Math.max(columnWidth, 2) - 1);
|
|
541
|
+
borders[a] += index + 1 < arr.length ? borderStyle[a].j : "";
|
|
542
|
+
});
|
|
543
|
+
borders[a] += borderStyle[a].r;
|
|
544
|
+
borders[a] = a < 2 ? `${marginLeft + borders[a]}
|
|
545
|
+
` : marginLeft + borders[a];
|
|
546
|
+
}
|
|
547
|
+
const output = [borders[0]];
|
|
548
|
+
for (const [sectionIndex, sectionName] of Object.keys(sections).entries()) {
|
|
549
|
+
const section = sections[sectionName];
|
|
550
|
+
for (let rowIndex = 0; rowIndex < section.length; rowIndex++) {
|
|
551
|
+
const row = section[rowIndex];
|
|
552
|
+
row.forEach((line) => {
|
|
553
|
+
output.push(marginLeft + borderStyle[1].v + line.join(borderStyle[1].v) + borderStyle[1].v + "\n");
|
|
554
|
+
});
|
|
555
|
+
switch (true) {
|
|
556
|
+
case (rowIndex === section.length - 1 && sectionIndex === 1 && sections.footer.length === 0):
|
|
557
|
+
break;
|
|
558
|
+
case (rowIndex === section.length - 1 && sectionIndex === 2):
|
|
559
|
+
break;
|
|
560
|
+
case (config.compact && sectionName === "body" && !row.empty):
|
|
561
|
+
break;
|
|
562
|
+
case (config.borderStyle === "none" && config.compact):
|
|
563
|
+
break;
|
|
564
|
+
default:
|
|
565
|
+
output.push(borders[1]);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
output.push(borders[2]);
|
|
570
|
+
const finalOutput = "\n".repeat(config.marginTop) + output.join("");
|
|
571
|
+
config.height = finalOutput.split(/\r\n|\r|\n/).length;
|
|
572
|
+
return finalOutput;
|
|
573
|
+
};
|
|
574
|
+
var buildRow = (config, row, rowType, rowIndex, rowData, inputData) => {
|
|
575
|
+
let minRowHeight = 0;
|
|
576
|
+
if (row.length === 0 && config.compact) {
|
|
577
|
+
row.empty = true;
|
|
578
|
+
return row;
|
|
579
|
+
}
|
|
580
|
+
const lengthDifference = config.table.columnWidths.length - row.length;
|
|
581
|
+
if (lengthDifference > 0) row = row.concat(Array.apply(null, new Array(lengthDifference)).map(() => null));
|
|
582
|
+
else if (lengthDifference < 0) row.length = config.table.columnWidths.length;
|
|
583
|
+
row = row.map((elem, elemIndex) => {
|
|
584
|
+
const cell = buildCell(config, elem, elemIndex, rowType, rowIndex, rowData, inputData);
|
|
585
|
+
minRowHeight = minRowHeight < cell.length ? cell.length : minRowHeight;
|
|
586
|
+
return cell;
|
|
587
|
+
});
|
|
588
|
+
minRowHeight = rowType === "header" ? minRowHeight : minRowHeight + (config.paddingBottom + config.paddingTop);
|
|
589
|
+
const linedRow = Array.apply(null, { length: minRowHeight }).map(Function.call, () => []);
|
|
590
|
+
row.forEach(function(cell, a) {
|
|
591
|
+
const whitespace = " ".repeat(Math.max(config.table.columnWidths[a] - 1, 0));
|
|
592
|
+
if (rowType === "body") {
|
|
593
|
+
for (let i = 0; i < config.paddingTop; i++) cell.unshift(whitespace);
|
|
594
|
+
for (let i = 0; i < config.paddingBottom; i++) cell.push(whitespace);
|
|
595
|
+
}
|
|
596
|
+
for (let i = 0; i < minRowHeight; i++) linedRow[i].push(typeof cell[i] !== "undefined" ? cell[i] : whitespace);
|
|
597
|
+
});
|
|
598
|
+
return linedRow;
|
|
599
|
+
};
|
|
600
|
+
var buildCell = (config, elem, columnIndex, rowType, rowIndex, rowData, inputData, dryRun = false) => {
|
|
601
|
+
let cellValue = null;
|
|
602
|
+
const cellOptions = Object.assign(
|
|
603
|
+
{ reset: false },
|
|
604
|
+
config,
|
|
605
|
+
rowType !== "header" ? config.columnSettings[columnIndex] : {},
|
|
606
|
+
typeof elem === "object" ? elem : {}
|
|
607
|
+
);
|
|
608
|
+
if (rowType === "header") {
|
|
609
|
+
config.table.columns.push(cellOptions);
|
|
610
|
+
cellValue = cellOptions.alias || cellOptions.value || "";
|
|
611
|
+
} else {
|
|
612
|
+
switch (true) {
|
|
613
|
+
case (typeof elem === "undefined" || elem === null):
|
|
614
|
+
cellValue = config.errorOnNull ? config.defaultErrorValue : config.defaultValue;
|
|
615
|
+
if (!isColorEnabled()) cellValue = stripAnsi3(cellValue);
|
|
616
|
+
cellOptions.isNull = true;
|
|
617
|
+
break;
|
|
618
|
+
case (typeof elem === "object" && elem !== null && typeof elem.value !== "undefined"):
|
|
619
|
+
cellValue = elem.value;
|
|
620
|
+
break;
|
|
621
|
+
case typeof elem === "function":
|
|
622
|
+
cellValue = elem.bind({
|
|
623
|
+
configure: function(object) {
|
|
624
|
+
return Object.assign(cellOptions, object);
|
|
625
|
+
},
|
|
626
|
+
style,
|
|
627
|
+
resetStyle
|
|
628
|
+
})(cellValue, columnIndex, rowIndex, rowData, inputData);
|
|
629
|
+
break;
|
|
630
|
+
default:
|
|
631
|
+
cellValue = elem;
|
|
632
|
+
}
|
|
633
|
+
if (rowType === "body" && typeof cellOptions.formatter === "function") {
|
|
634
|
+
cellValue = cellOptions.formatter.bind({
|
|
635
|
+
configure: function(object) {
|
|
636
|
+
return Object.assign(cellOptions, object);
|
|
637
|
+
},
|
|
638
|
+
style,
|
|
639
|
+
resetStyle
|
|
640
|
+
})(cellValue, columnIndex, rowIndex, rowData, inputData);
|
|
641
|
+
}
|
|
642
|
+
if (dryRun) return cellValue;
|
|
643
|
+
}
|
|
644
|
+
if (!cellOptions.reset) cellValue = colorizeCell(cellValue, cellOptions, rowType);
|
|
645
|
+
const { cell, innerWidth } = wrapCellText(cellOptions, cellValue, columnIndex, cellOptions, rowType);
|
|
646
|
+
if (rowType === "header") config.table.columnInnerWidths.push(innerWidth);
|
|
647
|
+
return cell;
|
|
648
|
+
};
|
|
649
|
+
var getConstructorGeometry = (row, config) => {
|
|
650
|
+
let type;
|
|
651
|
+
if (typeof row === "object" && !(row instanceof Array)) {
|
|
652
|
+
const keys = Object.keys(row);
|
|
653
|
+
if (config.adapter === "automattic") {
|
|
654
|
+
const key = keys[0];
|
|
655
|
+
type = row[key] instanceof Array ? "automattic-cross" : "automattic-vertical";
|
|
656
|
+
} else type = "o-horizontal";
|
|
657
|
+
} else type = "a-horizontal";
|
|
658
|
+
return type;
|
|
659
|
+
};
|
|
660
|
+
var coerceConstructorGeometry = (config, rows, constructorType) => {
|
|
661
|
+
let output = [];
|
|
662
|
+
switch (constructorType) {
|
|
663
|
+
case "automattic-cross":
|
|
664
|
+
config.columnSettings[0] = config.columnSettings[0] || {};
|
|
665
|
+
config.columnSettings[0].color = config.headerColor;
|
|
666
|
+
output = rows.map((obj) => {
|
|
667
|
+
const key = Object.keys(obj)[0];
|
|
668
|
+
return [key].concat(obj[key]);
|
|
669
|
+
});
|
|
670
|
+
break;
|
|
671
|
+
case "automattic-vertical":
|
|
672
|
+
config.columnSettings[0] = config.columnSettings[0] || {};
|
|
673
|
+
config.columnSettings[0].color = config.headerColor;
|
|
674
|
+
output = rows.map((value) => {
|
|
675
|
+
const key = Object.keys(value)[0];
|
|
676
|
+
return [key, value[key]];
|
|
677
|
+
});
|
|
678
|
+
break;
|
|
679
|
+
case "o-horizontal":
|
|
680
|
+
if (config.table.header[0].length && config.table.header[0].every((obj) => obj.value)) {
|
|
681
|
+
output = rows.map((row) => config.table.header[0].map((obj) => row[obj.value]));
|
|
682
|
+
} else output = rows.map((obj) => Object.values(obj));
|
|
683
|
+
break;
|
|
684
|
+
case "a-horizontal":
|
|
685
|
+
output = rows;
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
return output;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// src/factory.ts
|
|
692
|
+
var counter = 0;
|
|
693
|
+
var Factory = function(paramsArr) {
|
|
694
|
+
const _configKey = Symbol.config;
|
|
695
|
+
let header = [];
|
|
696
|
+
const body = [];
|
|
697
|
+
let footer = [];
|
|
698
|
+
let options = {};
|
|
699
|
+
switch (true) {
|
|
700
|
+
// header, rows, footer, and options
|
|
701
|
+
case paramsArr.length === 4:
|
|
702
|
+
header = paramsArr[0];
|
|
703
|
+
body.push(...paramsArr[1]);
|
|
704
|
+
footer = paramsArr[2];
|
|
705
|
+
options = paramsArr[3];
|
|
706
|
+
break;
|
|
707
|
+
// header, rows, footer
|
|
708
|
+
case (paramsArr.length === 3 && paramsArr[2] instanceof Array):
|
|
709
|
+
header = paramsArr[0];
|
|
710
|
+
body.push(...paramsArr[1]);
|
|
711
|
+
footer = paramsArr[2];
|
|
712
|
+
break;
|
|
713
|
+
// header, rows, options
|
|
714
|
+
case (paramsArr.length === 3 && typeof paramsArr[2] === "object"):
|
|
715
|
+
header = paramsArr[0];
|
|
716
|
+
body.push(...paramsArr[1]);
|
|
717
|
+
options = paramsArr[2];
|
|
718
|
+
break;
|
|
719
|
+
// header, rows (rows, footer is not an option)
|
|
720
|
+
case (paramsArr.length === 2 && paramsArr[1] instanceof Array):
|
|
721
|
+
header = paramsArr[0];
|
|
722
|
+
body.push(...paramsArr[1]);
|
|
723
|
+
break;
|
|
724
|
+
// rows, options
|
|
725
|
+
case (paramsArr.length === 2 && typeof paramsArr[1] === "object"):
|
|
726
|
+
body.push(...paramsArr[0]);
|
|
727
|
+
options = paramsArr[1];
|
|
728
|
+
break;
|
|
729
|
+
// rows
|
|
730
|
+
case (paramsArr.length === 1 && paramsArr[0] instanceof Array):
|
|
731
|
+
body.push(...paramsArr[0]);
|
|
732
|
+
break;
|
|
733
|
+
// adapter called: i.e. `require('tty-table')('automattic-cli-table')`
|
|
734
|
+
case (paramsArr.length === 1 && typeof paramsArr[0] === "string"): {
|
|
735
|
+
const adapters = {
|
|
736
|
+
"automattic-cli-table": () => __require("../adapters/automattic-cli-table.js"),
|
|
737
|
+
"default-adapter": () => __require("../adapters/default-adapter.js"),
|
|
738
|
+
"terminal-adapter": () => __require("../adapters/terminal-adapter.js")
|
|
739
|
+
};
|
|
740
|
+
const load = adapters[paramsArr[0]];
|
|
741
|
+
if (!load) throw new Error(`Unknown adapter: "${paramsArr[0]}". Available adapters: ${Object.keys(adapters).join(", ")}`);
|
|
742
|
+
return load();
|
|
743
|
+
}
|
|
744
|
+
/* istanbul ignore next */
|
|
745
|
+
default:
|
|
746
|
+
console.log("Error: Bad params. \nSee docs at github.com/tecfu/tty-table");
|
|
747
|
+
process.exit();
|
|
748
|
+
}
|
|
749
|
+
const cloneddefaults = JSON.parse(JSON.stringify(defaults_default));
|
|
750
|
+
const config = Object.assign({}, cloneddefaults, options);
|
|
751
|
+
config.align = config.alignment || config.align;
|
|
752
|
+
config.headerAlign = config.headerAlignment || config.headerAlign;
|
|
753
|
+
if (config.truncate === true) config.truncate = "";
|
|
754
|
+
if (config.borderColor) {
|
|
755
|
+
config.borderCharacters[config.borderStyle] = config.borderCharacters[config.borderStyle].map(function(obj) {
|
|
756
|
+
Object.keys(obj).forEach(function(key) {
|
|
757
|
+
obj[key] = style(obj[key], config.borderColor);
|
|
758
|
+
});
|
|
759
|
+
return obj;
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
config.columnSettings = header.slice(0);
|
|
763
|
+
config.table.header = header;
|
|
764
|
+
config.table.header = [config.table.header];
|
|
765
|
+
config.table.footer = footer;
|
|
766
|
+
if (config.terminalAdapter !== true) {
|
|
767
|
+
counter++;
|
|
768
|
+
}
|
|
769
|
+
config.tableId = counter;
|
|
770
|
+
const tableObject = Object.create(body);
|
|
771
|
+
tableObject[_configKey] = config;
|
|
772
|
+
tableObject.render = function() {
|
|
773
|
+
const output = stringifyData(this[_configKey], this.slice(0));
|
|
774
|
+
tableObject.height = this[_configKey].height;
|
|
775
|
+
return output;
|
|
776
|
+
};
|
|
777
|
+
return tableObject;
|
|
778
|
+
};
|
|
779
|
+
var Table = function(...params) {
|
|
780
|
+
return Factory(params);
|
|
781
|
+
};
|
|
782
|
+
Table.resetStyle = resetStyle;
|
|
783
|
+
Table.style = styleEachChar;
|
|
784
|
+
var factory_default = Table;
|
|
785
|
+
|
|
786
|
+
// src/index.ts
|
|
787
|
+
var src_default = factory_default;
|
|
788
|
+
|
|
789
|
+
// package.json
|
|
790
|
+
var package_default = {
|
|
791
|
+
name: "tty-table",
|
|
792
|
+
version: "7.0.0",
|
|
793
|
+
description: "Typed terminal table renderer for Node.js and browsers",
|
|
794
|
+
main: "dist/index.js",
|
|
795
|
+
module: "dist/index.mjs",
|
|
796
|
+
types: "dist/index.d.ts",
|
|
797
|
+
browser: "dist/browser/tty-table.global.js",
|
|
798
|
+
exports: {
|
|
799
|
+
".": {
|
|
800
|
+
types: "./dist/index.d.ts",
|
|
801
|
+
import: "./dist/index.mjs",
|
|
802
|
+
require: "./dist/index.js"
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
engines: {
|
|
806
|
+
node: ">=22"
|
|
807
|
+
},
|
|
808
|
+
bin: {
|
|
809
|
+
"tty-table": "adapters/terminal-adapter.js",
|
|
810
|
+
"tty-table-mcp": "dist/mcp.js"
|
|
811
|
+
},
|
|
812
|
+
files: [
|
|
813
|
+
"dist/",
|
|
814
|
+
"adapters/",
|
|
815
|
+
"README.md",
|
|
816
|
+
"LICENSE.txt"
|
|
817
|
+
],
|
|
818
|
+
scripts: {
|
|
819
|
+
build: "tsup && tsup --config tsup.browser.config.ts",
|
|
820
|
+
test: "npx mocha",
|
|
821
|
+
"test:watch": "vitest",
|
|
822
|
+
typecheck: "tsc --noEmit",
|
|
823
|
+
lint: "eslint .",
|
|
824
|
+
"lint:fix": "eslint . --fix",
|
|
825
|
+
prepublishOnly: "npm run typecheck && npm run build && npm test && npm run test:unit",
|
|
826
|
+
"test:unit": "vitest run",
|
|
827
|
+
"view-examples": "node npm_scripts/run-examples.js view",
|
|
828
|
+
"save-tests": "node npm_scripts/run-examples.js save"
|
|
829
|
+
},
|
|
830
|
+
repository: {
|
|
831
|
+
type: "git",
|
|
832
|
+
url: "https://github.com/tecfu/tty-table.git"
|
|
833
|
+
},
|
|
834
|
+
keywords: [
|
|
835
|
+
"table",
|
|
836
|
+
"cli-table",
|
|
837
|
+
"terminal table",
|
|
838
|
+
"console table",
|
|
839
|
+
"ascii table"
|
|
840
|
+
],
|
|
841
|
+
author: "Tecfu",
|
|
842
|
+
license: "MIT",
|
|
843
|
+
bugs: {
|
|
844
|
+
url: "https://github.com/tecfu/tty-table/issues"
|
|
845
|
+
},
|
|
846
|
+
homepage: "https://github.com/tecfu/tty-table",
|
|
847
|
+
dependencies: {
|
|
848
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
849
|
+
breakword: "^2.1.0",
|
|
850
|
+
chalk: "^4.1.2",
|
|
851
|
+
csv: "^6.3.11",
|
|
852
|
+
kleur: "^4.1.5",
|
|
853
|
+
smartwrap: "^4.0.0",
|
|
854
|
+
"strip-ansi": "^6.0.1",
|
|
855
|
+
yargs: "^17.7.2",
|
|
856
|
+
zod: "^4.6.5"
|
|
857
|
+
},
|
|
858
|
+
devDependencies: {
|
|
859
|
+
"@eslint/js": "^9.30.0",
|
|
860
|
+
"@types/node": "^22.15.0",
|
|
861
|
+
"@types/yargs": "^17.0.33",
|
|
862
|
+
chai: "^4.5.0",
|
|
863
|
+
commander: "^4.1.1",
|
|
864
|
+
eslint: "^9.30.0",
|
|
865
|
+
glob: "^13.0.6",
|
|
866
|
+
mocha: "^12.0.0",
|
|
867
|
+
tsup: "^8.5.0",
|
|
868
|
+
typescript: "^5.8.3",
|
|
869
|
+
"typescript-eslint": "^8.35.0",
|
|
870
|
+
vitest: "^4.1.11"
|
|
871
|
+
},
|
|
872
|
+
defaultTestColumns: 90
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/mcp.ts
|
|
876
|
+
var headerEntry = z.union([
|
|
877
|
+
z.string(),
|
|
878
|
+
z.object({
|
|
879
|
+
value: z.string(),
|
|
880
|
+
align: z.enum(["left", "center", "right"]).optional(),
|
|
881
|
+
width: z.union([z.number(), z.string()]).optional()
|
|
882
|
+
})
|
|
883
|
+
]);
|
|
884
|
+
var renderTableInputSchema = {
|
|
885
|
+
header: z.array(headerEntry).optional().describe("Column definitions: names, or {value, align, width} objects"),
|
|
886
|
+
rows: z.array(z.union([z.array(z.unknown()), z.record(z.string(), z.unknown())])).describe("Row data: arrays of cells, or objects keyed by column name"),
|
|
887
|
+
options: z.record(z.string(), z.unknown()).optional().describe('tty-table options, e.g. {width: 80, borderStyle: "solid"}')
|
|
888
|
+
};
|
|
889
|
+
function handleRenderTable({ header, rows, options }) {
|
|
890
|
+
try {
|
|
891
|
+
const opts = options ?? {};
|
|
892
|
+
const head = header;
|
|
893
|
+
const table = head?.length ? src_default(head, rows, opts) : src_default(rows, opts);
|
|
894
|
+
return { content: [{ type: "text", text: table.render() }] };
|
|
895
|
+
} catch (error) {
|
|
896
|
+
return {
|
|
897
|
+
isError: true,
|
|
898
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }]
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function createMcpServer() {
|
|
903
|
+
const server = new McpServer({ name: "tty-table", version: package_default.version });
|
|
904
|
+
server.registerTool(
|
|
905
|
+
"render_table",
|
|
906
|
+
{
|
|
907
|
+
title: "Render a terminal table",
|
|
908
|
+
description: "Render data as an ASCII/Unicode terminal table (tty-table). Pass header (column names or {value, align, width} objects), rows (array of arrays, or objects whose keys match the header), and optional options (any tty-table table option, e.g. width, borderStyle, align, compact). Returns the rendered table as text.",
|
|
909
|
+
inputSchema: renderTableInputSchema
|
|
910
|
+
},
|
|
911
|
+
(args) => handleRenderTable(args)
|
|
912
|
+
);
|
|
913
|
+
return server;
|
|
914
|
+
}
|
|
915
|
+
var isMain = typeof process !== "undefined" && process.argv[1] && (process.argv[1].endsWith("mcp.js") || process.argv[1].endsWith("mcp.mjs") || process.argv[1].endsWith("mcp.ts") || process.argv[1].includes("tty-table-mcp"));
|
|
916
|
+
if (isMain) {
|
|
917
|
+
const server = createMcpServer();
|
|
918
|
+
void server.connect(new StdioServerTransport()).catch((error) => {
|
|
919
|
+
process.stderr.write(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
920
|
+
process.exit(1);
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
export {
|
|
924
|
+
createMcpServer,
|
|
925
|
+
handleRenderTable,
|
|
926
|
+
renderTableInputSchema
|
|
927
|
+
};
|
|
928
|
+
;if (typeof module !== "undefined" && typeof module.exports?.default === "function") { module.exports = Object.assign(module.exports.default, module.exports) }
|
|
929
|
+
//# sourceMappingURL=mcp.mjs.map
|