@nomicfoundation/hardhat-utils 3.0.2 → 3.0.4
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/CHANGELOG.md +13 -0
- package/dist/src/format.d.ts +103 -0
- package/dist/src/format.d.ts.map +1 -0
- package/dist/src/format.js +193 -0
- package/dist/src/format.js.map +1 -0
- package/dist/src/internal/format.d.ts +89 -0
- package/dist/src/internal/format.d.ts.map +1 -0
- package/dist/src/internal/format.js +199 -0
- package/dist/src/internal/format.js.map +1 -0
- package/dist/src/internal/panic-errors.d.ts +2 -0
- package/dist/src/internal/panic-errors.d.ts.map +1 -0
- package/dist/src/internal/panic-errors.js +24 -0
- package/dist/src/internal/panic-errors.js.map +1 -0
- package/dist/src/panic-errors.d.ts +13 -0
- package/dist/src/panic-errors.d.ts.map +1 -1
- package/dist/src/panic-errors.js +14 -23
- package/dist/src/panic-errors.js.map +1 -1
- package/dist/src/spinner.d.ts +46 -0
- package/dist/src/spinner.d.ts.map +1 -0
- package/dist/src/spinner.js +91 -0
- package/dist/src/spinner.js.map +1 -0
- package/package.json +4 -2
- package/src/format.ts +267 -0
- package/src/internal/format.ts +260 -0
- package/src/internal/panic-errors.ts +23 -0
- package/src/panic-errors.ts +14 -24
- package/src/spinner.ts +130 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d1969e7: Added support for showing gas statistics after running nodejs tests ([#7472](https://github.com/NomicFoundation/hardhat/issues/7428)).
|
|
8
|
+
|
|
9
|
+
## 3.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d821a0a: Fix npm artifact cleanup on windows ([#7459](https://github.com/NomicFoundation/hardhat/issues/7459))
|
|
14
|
+
- b13620a: Add compilation progress spinner to show build progress ([#7460](https://github.com/NomicFoundation/hardhat/pull/7460))
|
|
15
|
+
|
|
3
16
|
## 3.0.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export type TableRow = string[];
|
|
2
|
+
export interface TableDivider {
|
|
3
|
+
type: "divider";
|
|
4
|
+
}
|
|
5
|
+
export type TableItem = TableRow | TableDivider;
|
|
6
|
+
export declare const divider: TableDivider;
|
|
7
|
+
/**
|
|
8
|
+
* Formats an array of rows and dividers into a table string.
|
|
9
|
+
*
|
|
10
|
+
* @param items An array of table rows (string arrays) and dividers.
|
|
11
|
+
* Dividers are objects with type: "divider" and will be rendered as table dividers.
|
|
12
|
+
* @returns The formatted table as a string, ready to be rendered.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* formatTable([
|
|
17
|
+
* ["Name", "Age"],
|
|
18
|
+
* divider,
|
|
19
|
+
* ["Alice", "30"],
|
|
20
|
+
* ["Bob", "25"],
|
|
21
|
+
* divider,
|
|
22
|
+
* ["Average", "27.5"]
|
|
23
|
+
* ]);
|
|
24
|
+
*
|
|
25
|
+
* // =>
|
|
26
|
+
* // | Name | Age |
|
|
27
|
+
* // | ------- | ---- |
|
|
28
|
+
* // | Alice | 30 |
|
|
29
|
+
* // | Bob | 25 |
|
|
30
|
+
* // | ------- | ---- |
|
|
31
|
+
* // | Average | 27.5 |
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatTable(items: TableItem[]): string;
|
|
35
|
+
export interface TableTitleV2 {
|
|
36
|
+
type: "title";
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TableSectionHeaderV2 {
|
|
40
|
+
type: "section-header";
|
|
41
|
+
text: string;
|
|
42
|
+
}
|
|
43
|
+
export interface TableHeaderV2 {
|
|
44
|
+
type: "header";
|
|
45
|
+
cells: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface TableRowV2 {
|
|
48
|
+
type: "row";
|
|
49
|
+
cells: string[];
|
|
50
|
+
}
|
|
51
|
+
export type TableItemV2 = TableTitleV2 | TableSectionHeaderV2 | TableHeaderV2 | TableRowV2;
|
|
52
|
+
/**
|
|
53
|
+
* Formats an array of titles, section headers, headers, and rows into a table
|
|
54
|
+
* string with box-drawing characters.
|
|
55
|
+
*
|
|
56
|
+
* Features:
|
|
57
|
+
* - Titles are centered in a standalone box with double borders (╔═╗)
|
|
58
|
+
* - Section headers group related content with automatic closing
|
|
59
|
+
* - Headers and rows can have different numbers of cells
|
|
60
|
+
* - Rows with fewer cells than max columns are handled with special rendering
|
|
61
|
+
*
|
|
62
|
+
* @param items An array of table items (titles, section headers, headers, and rows).
|
|
63
|
+
* Sections are automatically closed when a new section-header or title appears, or
|
|
64
|
+
* at the end of the table.
|
|
65
|
+
* @returns The formatted table as a string, ready to be rendered.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* formatTableV2([
|
|
70
|
+
* { type: "title", text: "My Table" },
|
|
71
|
+
* { type: "section-header", text: "User Data" },
|
|
72
|
+
* { type: "header", cells: ["Name", "Age", "City"] },
|
|
73
|
+
* { type: "row", cells: ["Alice", "30", "NYC"] },
|
|
74
|
+
* { type: "row", cells: ["Bob", "25", "LA"] },
|
|
75
|
+
* { type: "section-header", text: "Summary" },
|
|
76
|
+
* { type: "header", cells: ["Total", "Count"] },
|
|
77
|
+
* { type: "row", cells: ["55", "2"] }
|
|
78
|
+
* ]);
|
|
79
|
+
*
|
|
80
|
+
* // =>
|
|
81
|
+
* // ╔═══════════════════╗
|
|
82
|
+
* // ║ My Table ║
|
|
83
|
+
* // ╚═══════════════════╝
|
|
84
|
+
* // ╔═══════════════════╗
|
|
85
|
+
* // ║ User Data ║
|
|
86
|
+
* // ╟───────┬─────┬─────╢
|
|
87
|
+
* // ║ Name │ Age │ City║
|
|
88
|
+
* // ╟───────┼─────┼─────╢
|
|
89
|
+
* // ║ Alice │ 30 │ NYC ║
|
|
90
|
+
* // ╟───────┼─────┼─────╢
|
|
91
|
+
* // ║ Bob │ 25 │ LA ║
|
|
92
|
+
* // ╚═══════╧═════╧═════╝
|
|
93
|
+
* // ╔═══════════════════╗
|
|
94
|
+
* // ║ Summary ║
|
|
95
|
+
* // ╟───────┬───────────╢
|
|
96
|
+
* // ║ Total │ Count ║
|
|
97
|
+
* // ╟───────┼───────────╢
|
|
98
|
+
* // ║ 55 │ 2 ║
|
|
99
|
+
* // ╚═══════╧═══════════╝
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function formatTableV2(items: TableItemV2[]): string;
|
|
103
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;CACjB;AACD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEhD,eAAO,MAAM,OAAO,EAAE,YAAkC,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CA8CtD;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GACnB,YAAY,GACZ,oBAAoB,GACpB,aAAa,GACb,UAAU,CAAC;AAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAgG1D"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getColumnWidths, getContentWidth, getHeadingWidth, getStringWidth, renderContentLine, renderHeaderOpen, renderRowSeparator, renderSectionClose, } from "./internal/format.js";
|
|
2
|
+
export const divider = { type: "divider" };
|
|
3
|
+
/**
|
|
4
|
+
* Formats an array of rows and dividers into a table string.
|
|
5
|
+
*
|
|
6
|
+
* @param items An array of table rows (string arrays) and dividers.
|
|
7
|
+
* Dividers are objects with type: "divider" and will be rendered as table dividers.
|
|
8
|
+
* @returns The formatted table as a string, ready to be rendered.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* formatTable([
|
|
13
|
+
* ["Name", "Age"],
|
|
14
|
+
* divider,
|
|
15
|
+
* ["Alice", "30"],
|
|
16
|
+
* ["Bob", "25"],
|
|
17
|
+
* divider,
|
|
18
|
+
* ["Average", "27.5"]
|
|
19
|
+
* ]);
|
|
20
|
+
*
|
|
21
|
+
* // =>
|
|
22
|
+
* // | Name | Age |
|
|
23
|
+
* // | ------- | ---- |
|
|
24
|
+
* // | Alice | 30 |
|
|
25
|
+
* // | Bob | 25 |
|
|
26
|
+
* // | ------- | ---- |
|
|
27
|
+
* // | Average | 27.5 |
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function formatTable(items) {
|
|
31
|
+
const widths = [];
|
|
32
|
+
const dataRows = [];
|
|
33
|
+
for (const item of items) {
|
|
34
|
+
if (Array.isArray(item)) {
|
|
35
|
+
dataRows.push([...item]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Calculate maximum width for each column
|
|
39
|
+
for (const row of dataRows) {
|
|
40
|
+
for (let i = 0; i < row.length; i++) {
|
|
41
|
+
while (i >= widths.length) {
|
|
42
|
+
widths.push(0);
|
|
43
|
+
}
|
|
44
|
+
widths[i] = Math.max(widths[i], getStringWidth(row[i]));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const dividerRow = widths.map((width) => "-".repeat(width));
|
|
48
|
+
const outputRows = [];
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
if (Array.isArray(item)) {
|
|
51
|
+
const row = [...item];
|
|
52
|
+
// Pad the row to match the number of columns
|
|
53
|
+
while (row.length < widths.length) {
|
|
54
|
+
row.push("");
|
|
55
|
+
}
|
|
56
|
+
outputRows.push(row);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
outputRows.push([...dividerRow]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
outputRows.forEach((row) => {
|
|
63
|
+
for (let i = 0; i < row.length; i++) {
|
|
64
|
+
const displayWidth = getStringWidth(row[i]);
|
|
65
|
+
const actualLength = row[i].length;
|
|
66
|
+
// Adjust padding to account for difference between display width and actual length
|
|
67
|
+
row[i] = row[i].padEnd(widths[i] + actualLength - displayWidth);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return outputRows.map((row) => `| ${row.join(" | ")} |`).join("\n");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Formats an array of titles, section headers, headers, and rows into a table
|
|
74
|
+
* string with box-drawing characters.
|
|
75
|
+
*
|
|
76
|
+
* Features:
|
|
77
|
+
* - Titles are centered in a standalone box with double borders (╔═╗)
|
|
78
|
+
* - Section headers group related content with automatic closing
|
|
79
|
+
* - Headers and rows can have different numbers of cells
|
|
80
|
+
* - Rows with fewer cells than max columns are handled with special rendering
|
|
81
|
+
*
|
|
82
|
+
* @param items An array of table items (titles, section headers, headers, and rows).
|
|
83
|
+
* Sections are automatically closed when a new section-header or title appears, or
|
|
84
|
+
* at the end of the table.
|
|
85
|
+
* @returns The formatted table as a string, ready to be rendered.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* formatTableV2([
|
|
90
|
+
* { type: "title", text: "My Table" },
|
|
91
|
+
* { type: "section-header", text: "User Data" },
|
|
92
|
+
* { type: "header", cells: ["Name", "Age", "City"] },
|
|
93
|
+
* { type: "row", cells: ["Alice", "30", "NYC"] },
|
|
94
|
+
* { type: "row", cells: ["Bob", "25", "LA"] },
|
|
95
|
+
* { type: "section-header", text: "Summary" },
|
|
96
|
+
* { type: "header", cells: ["Total", "Count"] },
|
|
97
|
+
* { type: "row", cells: ["55", "2"] }
|
|
98
|
+
* ]);
|
|
99
|
+
*
|
|
100
|
+
* // =>
|
|
101
|
+
* // ╔═══════════════════╗
|
|
102
|
+
* // ║ My Table ║
|
|
103
|
+
* // ╚═══════════════════╝
|
|
104
|
+
* // ╔═══════════════════╗
|
|
105
|
+
* // ║ User Data ║
|
|
106
|
+
* // ╟───────┬─────┬─────╢
|
|
107
|
+
* // ║ Name │ Age │ City║
|
|
108
|
+
* // ╟───────┼─────┼─────╢
|
|
109
|
+
* // ║ Alice │ 30 │ NYC ║
|
|
110
|
+
* // ╟───────┼─────┼─────╢
|
|
111
|
+
* // ║ Bob │ 25 │ LA ║
|
|
112
|
+
* // ╚═══════╧═════╧═════╝
|
|
113
|
+
* // ╔═══════════════════╗
|
|
114
|
+
* // ║ Summary ║
|
|
115
|
+
* // ╟───────┬───────────╢
|
|
116
|
+
* // ║ Total │ Count ║
|
|
117
|
+
* // ╟───────┼───────────╢
|
|
118
|
+
* // ║ 55 │ 2 ║
|
|
119
|
+
* // ╚═══════╧═══════════╝
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function formatTableV2(items) {
|
|
123
|
+
if (items.length === 0) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
const columnWidths = getColumnWidths(items);
|
|
127
|
+
const contentWidth = getContentWidth(columnWidths);
|
|
128
|
+
const headingWidth = getHeadingWidth(items);
|
|
129
|
+
// If heading is wider than content, expand last column to fit
|
|
130
|
+
if (headingWidth > contentWidth && columnWidths.length > 0) {
|
|
131
|
+
const extraSpace = headingWidth - contentWidth;
|
|
132
|
+
columnWidths[columnWidths.length - 1] += extraSpace;
|
|
133
|
+
}
|
|
134
|
+
const tableWidth = Math.max(contentWidth, headingWidth);
|
|
135
|
+
const lines = [];
|
|
136
|
+
let previousCellCount = 0; // Keep track of previous row/header cell count
|
|
137
|
+
let inSection = false;
|
|
138
|
+
for (let i = 0; i < items.length; i++) {
|
|
139
|
+
const [previous, current] = [items[i - 1], items[i]];
|
|
140
|
+
if (current.type === "title") {
|
|
141
|
+
if (inSection) {
|
|
142
|
+
lines.push(renderSectionClose(columnWidths, previousCellCount));
|
|
143
|
+
inSection = false;
|
|
144
|
+
}
|
|
145
|
+
lines.push("╔" + "═".repeat(tableWidth) + "╗");
|
|
146
|
+
const titleDisplayWidth = getStringWidth(current.text);
|
|
147
|
+
const titleActualLength = current.text.length;
|
|
148
|
+
const centeredTitle = current.text
|
|
149
|
+
.padStart((tableWidth + titleDisplayWidth) / 2 +
|
|
150
|
+
(titleActualLength - titleDisplayWidth))
|
|
151
|
+
.padEnd(tableWidth + (titleActualLength - titleDisplayWidth));
|
|
152
|
+
lines.push("║" + centeredTitle + "║");
|
|
153
|
+
lines.push("╚" + "═".repeat(tableWidth) + "╝");
|
|
154
|
+
}
|
|
155
|
+
else if (current.type === "section-header") {
|
|
156
|
+
if (inSection) {
|
|
157
|
+
lines.push(renderSectionClose(columnWidths, previousCellCount));
|
|
158
|
+
}
|
|
159
|
+
lines.push("╔" + "═".repeat(tableWidth) + "╗");
|
|
160
|
+
const headerDisplayWidth = getStringWidth(current.text);
|
|
161
|
+
const headerActualLength = current.text.length;
|
|
162
|
+
const paddedHeader = current.text.padEnd(tableWidth - 2 + (headerActualLength - headerDisplayWidth));
|
|
163
|
+
lines.push("║ " + paddedHeader + " ║");
|
|
164
|
+
inSection = true;
|
|
165
|
+
}
|
|
166
|
+
else if (current.type === "header") {
|
|
167
|
+
const currentCellCount = current.cells.length;
|
|
168
|
+
const innerJoiner = previous !== undefined && previous.type === "section-header"
|
|
169
|
+
? "┬"
|
|
170
|
+
: "┼";
|
|
171
|
+
const needsTransition = previous !== undefined &&
|
|
172
|
+
previous.type !== "section-header" &&
|
|
173
|
+
currentCellCount < previousCellCount;
|
|
174
|
+
lines.push(renderHeaderOpen(columnWidths, currentCellCount, innerJoiner, needsTransition));
|
|
175
|
+
lines.push(renderContentLine(current.cells, columnWidths, currentCellCount));
|
|
176
|
+
previousCellCount = currentCellCount;
|
|
177
|
+
}
|
|
178
|
+
else if (current.type === "row") {
|
|
179
|
+
const currentCellCount = current.cells.length;
|
|
180
|
+
// Only add separator if previous wasn't a row
|
|
181
|
+
if (previous === undefined || previous.type !== "row") {
|
|
182
|
+
lines.push(renderRowSeparator(columnWidths, currentCellCount));
|
|
183
|
+
}
|
|
184
|
+
lines.push(renderContentLine(current.cells, columnWidths, currentCellCount));
|
|
185
|
+
previousCellCount = currentCellCount;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (inSection) {
|
|
189
|
+
lines.push(renderSectionClose(columnWidths, previousCellCount));
|
|
190
|
+
}
|
|
191
|
+
return lines.join("\n");
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAQ9B,MAAM,CAAC,MAAM,OAAO,GAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;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CAAC,IAAI,KAAK,gBAAgB;gBAClC,gBAAgB,GAAG,iBAAiB,CAAC;YAEvC,KAAK,CAAC,IAAI,CACR,gBAAgB,CACd,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,eAAe,CAChB,CACF,CAAC;YACF,KAAK,CAAC,IAAI,CACR,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACjE,CAAC;YACF,iBAAiB,GAAG,gBAAgB,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YAClC,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC;YAE9C,8CAA8C;YAC9C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;gBACtD,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC;YACjE,CAAC;YACD,KAAK,CAAC,IAAI,CACR,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACjE,CAAC;YACF,iBAAiB,GAAG,gBAAgB,CAAC;QACvC,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { TableItemV2 } from "../format.js";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the display width of a string by removing ANSI escape codes.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: This implementation only removes basic ANSI color/style codes and may
|
|
6
|
+
* not handle all escape sequences (e.g., cursor movement, complex control
|
|
7
|
+
* sequences).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getStringWidth(str: string): number;
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the minimum width needed by each column in the table
|
|
12
|
+
* to fit its content (accounting for ANSI color codes).
|
|
13
|
+
*/
|
|
14
|
+
export declare function getColumnWidths(items: TableItemV2[]): number[];
|
|
15
|
+
/**
|
|
16
|
+
* Calculates the inner width needed to fit the rows and headers
|
|
17
|
+
* (excludes borders, which are added during rendering).
|
|
18
|
+
*
|
|
19
|
+
* Each column is padded by 1 space on each side, and columns are
|
|
20
|
+
* separated by " │ " (3 spaces).
|
|
21
|
+
*/
|
|
22
|
+
export declare function getContentWidth(columnWidths: number[]): number;
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the inner width needed to fit titles and section headers
|
|
25
|
+
* (excludes borders, which are added during rendering).
|
|
26
|
+
*
|
|
27
|
+
* Each title/header is padded by 1 space on each side.
|
|
28
|
+
* Accounts for ANSI color codes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getHeadingWidth(items: TableItemV2[]): number;
|
|
31
|
+
/**
|
|
32
|
+
* Calculates the width needed for unused columns when a row/header has fewer
|
|
33
|
+
* cells than the total column count (e.g., if table has 6 columns but row
|
|
34
|
+
* only has 2 cells, calculates space for the remaining 4 columns).
|
|
35
|
+
*/
|
|
36
|
+
export declare function getUnusedColumnsWidth(columnWidths: number[], previousCellCount: number): number;
|
|
37
|
+
/**
|
|
38
|
+
* Renders a horizontal rule segment by repeating a character for each column
|
|
39
|
+
* with padding, joined by a separator (e.g., "─────┼─────┼─────").
|
|
40
|
+
*/
|
|
41
|
+
export declare function renderRuleSegment(columnWidths: number[], char: string, joiner: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Renders a complete horizontal rule with left and right borders
|
|
44
|
+
* (e.g., "╟─────┼─────┼─────╢").
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderHorizontalRule(leftBorder: string, columnWidths: number[], char: string, joiner: string, rightBorder: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Renders a content line containing cells from either a header or row.
|
|
49
|
+
*
|
|
50
|
+
* Handles two cases:
|
|
51
|
+
* - Full width: When all columns are used, cells are separated by " │ " and
|
|
52
|
+
* line ends with " ║" (e.g., "║ cell1 │ cell2 │ cell3 ║")
|
|
53
|
+
* - Short line: When fewer columns are used, active cells are followed by
|
|
54
|
+
* " │ " and empty space, ending with "║" (e.g., "║ cell1 │ cell2 │ ║")
|
|
55
|
+
*
|
|
56
|
+
* Accounts for ANSI color codes when padding cells.
|
|
57
|
+
*/
|
|
58
|
+
export declare function renderContentLine(cells: string[], columnWidths: number[], currentCellCount: number): string;
|
|
59
|
+
/**
|
|
60
|
+
* Renders the horizontal rule that appears above a header row.
|
|
61
|
+
*
|
|
62
|
+
* Handles three cases:
|
|
63
|
+
* - Transition rule: When going from more columns to fewer, shows ┴ marks
|
|
64
|
+
* where columns collapse (e.g., "╟───┼───┼───┴───┴───╢")
|
|
65
|
+
* - Full width: When header uses all columns (e.g., "╟───┬───┬───╢" or "╟───┼───┼───╢")
|
|
66
|
+
* - Short header: When header uses fewer columns than max (e.g., "╟───┬─────────╢")
|
|
67
|
+
*
|
|
68
|
+
* The innerJoiner determines the separator character: ┬ after section-header, ┼ otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export declare function renderHeaderOpen(columnWidths: number[], currentCellCount: number, innerJoiner: string, needsTransition: boolean): string;
|
|
71
|
+
/**
|
|
72
|
+
* Renders the horizontal rule that appears above a row.
|
|
73
|
+
*
|
|
74
|
+
* Handles two cases:
|
|
75
|
+
* - Full width: When row uses all columns, renders with ┼ joiners and
|
|
76
|
+
* ends with ╢ (e.g., "╟───┼───┼───╢")
|
|
77
|
+
* - Short row: When row uses fewer columns, renders active columns with
|
|
78
|
+
* ┼ joiners, ends with ┤, then fills remaining space and ends with ║
|
|
79
|
+
* (e.g., "╟───┼───┤ ║")
|
|
80
|
+
*/
|
|
81
|
+
export declare function renderRowSeparator(columnWidths: number[], currentCellCount: number): string;
|
|
82
|
+
/**
|
|
83
|
+
* Renders the section's bottom border, placing ╧ marks under column
|
|
84
|
+
* separators where the last row/header had cells (e.g., if the last row
|
|
85
|
+
* looked like "║ a │ b │ ║", the bottom border would be
|
|
86
|
+
* "╚═══╧═══╧═══════╝").
|
|
87
|
+
*/
|
|
88
|
+
export declare function renderSectionClose(columnWidths: number[], previousCellCount: number): string;
|
|
89
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/internal/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIlD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,CAY9D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAM9D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAQ5D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EAAE,EACtB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAIR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EAAE,EACf,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAmCR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,GACvB,MAAM,CA2BR;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EAAE,EACtB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAkBR;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EAAE,EACtB,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAcR"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the display width of a string by removing ANSI escape codes.
|
|
3
|
+
*
|
|
4
|
+
* NOTE: This implementation only removes basic ANSI color/style codes and may
|
|
5
|
+
* not handle all escape sequences (e.g., cursor movement, complex control
|
|
6
|
+
* sequences).
|
|
7
|
+
*/
|
|
8
|
+
export function getStringWidth(str) {
|
|
9
|
+
// Remove ANSI escape codes if present
|
|
10
|
+
const stripped = str.replace(/\u001b\[[0-9;]*m/g, "");
|
|
11
|
+
return stripped.length;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the minimum width needed by each column in the table
|
|
15
|
+
* to fit its content (accounting for ANSI color codes).
|
|
16
|
+
*/
|
|
17
|
+
export function getColumnWidths(items) {
|
|
18
|
+
const columnWidths = [];
|
|
19
|
+
for (const item of items) {
|
|
20
|
+
if (item.type === "row" || item.type === "header") {
|
|
21
|
+
item.cells.forEach((cell, i) => {
|
|
22
|
+
columnWidths[i] = Math.max(columnWidths[i] ?? 0, getStringWidth(cell));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return columnWidths;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Calculates the inner width needed to fit the rows and headers
|
|
30
|
+
* (excludes borders, which are added during rendering).
|
|
31
|
+
*
|
|
32
|
+
* Each column is padded by 1 space on each side, and columns are
|
|
33
|
+
* separated by " │ " (3 spaces).
|
|
34
|
+
*/
|
|
35
|
+
export function getContentWidth(columnWidths) {
|
|
36
|
+
return (columnWidths.reduce((sum, w) => sum + w, 0) +
|
|
37
|
+
(columnWidths.length - 1) * 3 +
|
|
38
|
+
2);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Calculates the inner width needed to fit titles and section headers
|
|
42
|
+
* (excludes borders, which are added during rendering).
|
|
43
|
+
*
|
|
44
|
+
* Each title/header is padded by 1 space on each side.
|
|
45
|
+
* Accounts for ANSI color codes.
|
|
46
|
+
*/
|
|
47
|
+
export function getHeadingWidth(items) {
|
|
48
|
+
let headingWidth = 0;
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
if (item.type === "section-header" || item.type === "title") {
|
|
51
|
+
headingWidth = Math.max(headingWidth, getStringWidth(item.text) + 2);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return headingWidth;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Calculates the width needed for unused columns when a row/header has fewer
|
|
58
|
+
* cells than the total column count (e.g., if table has 6 columns but row
|
|
59
|
+
* only has 2 cells, calculates space for the remaining 4 columns).
|
|
60
|
+
*/
|
|
61
|
+
export function getUnusedColumnsWidth(columnWidths, previousCellCount) {
|
|
62
|
+
const remainingWidths = columnWidths.slice(previousCellCount);
|
|
63
|
+
return remainingWidths.reduce((sum, w) => sum + w + 3, 0) - 3;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Renders a horizontal rule segment by repeating a character for each column
|
|
67
|
+
* with padding, joined by a separator (e.g., "─────┼─────┼─────").
|
|
68
|
+
*/
|
|
69
|
+
export function renderRuleSegment(columnWidths, char, joiner) {
|
|
70
|
+
return columnWidths.map((w) => char.repeat(w + 2)).join(joiner);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Renders a complete horizontal rule with left and right borders
|
|
74
|
+
* (e.g., "╟─────┼─────┼─────╢").
|
|
75
|
+
*/
|
|
76
|
+
export function renderHorizontalRule(leftBorder, columnWidths, char, joiner, rightBorder) {
|
|
77
|
+
return (leftBorder + renderRuleSegment(columnWidths, char, joiner) + rightBorder);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Renders a content line containing cells from either a header or row.
|
|
81
|
+
*
|
|
82
|
+
* Handles two cases:
|
|
83
|
+
* - Full width: When all columns are used, cells are separated by " │ " and
|
|
84
|
+
* line ends with " ║" (e.g., "║ cell1 │ cell2 │ cell3 ║")
|
|
85
|
+
* - Short line: When fewer columns are used, active cells are followed by
|
|
86
|
+
* " │ " and empty space, ending with "║" (e.g., "║ cell1 │ cell2 │ ║")
|
|
87
|
+
*
|
|
88
|
+
* Accounts for ANSI color codes when padding cells.
|
|
89
|
+
*/
|
|
90
|
+
export function renderContentLine(cells, columnWidths, currentCellCount) {
|
|
91
|
+
if (currentCellCount === columnWidths.length) {
|
|
92
|
+
return ("║ " +
|
|
93
|
+
cells
|
|
94
|
+
.map((cell, j) => {
|
|
95
|
+
const displayWidth = getStringWidth(cell);
|
|
96
|
+
const actualLength = cell.length;
|
|
97
|
+
// Adjust padding to account for ANSI escape codes
|
|
98
|
+
return cell.padEnd(columnWidths[j] + actualLength - displayWidth);
|
|
99
|
+
})
|
|
100
|
+
.join(" │ ") +
|
|
101
|
+
" ║");
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const usedWidths = columnWidths.slice(0, currentCellCount);
|
|
105
|
+
const remainingWidth = getUnusedColumnsWidth(columnWidths, currentCellCount);
|
|
106
|
+
return ("║ " +
|
|
107
|
+
cells
|
|
108
|
+
.map((cell, j) => {
|
|
109
|
+
const displayWidth = getStringWidth(cell);
|
|
110
|
+
const actualLength = cell.length;
|
|
111
|
+
// Adjust padding to account for ANSI escape codes
|
|
112
|
+
return cell.padEnd(usedWidths[j] + actualLength - displayWidth);
|
|
113
|
+
})
|
|
114
|
+
.join(" │ ") +
|
|
115
|
+
" │ " +
|
|
116
|
+
" ".repeat(remainingWidth + 1) +
|
|
117
|
+
"║");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Renders the horizontal rule that appears above a header row.
|
|
122
|
+
*
|
|
123
|
+
* Handles three cases:
|
|
124
|
+
* - Transition rule: When going from more columns to fewer, shows ┴ marks
|
|
125
|
+
* where columns collapse (e.g., "╟───┼───┼───┴───┴───╢")
|
|
126
|
+
* - Full width: When header uses all columns (e.g., "╟───┬───┬───╢" or "╟───┼───┼───╢")
|
|
127
|
+
* - Short header: When header uses fewer columns than max (e.g., "╟───┬─────────╢")
|
|
128
|
+
*
|
|
129
|
+
* The innerJoiner determines the separator character: ┬ after section-header, ┼ otherwise.
|
|
130
|
+
*/
|
|
131
|
+
export function renderHeaderOpen(columnWidths, currentCellCount, innerJoiner, needsTransition) {
|
|
132
|
+
if (needsTransition) {
|
|
133
|
+
const usedWidths = columnWidths.slice(0, currentCellCount);
|
|
134
|
+
const collapsingWidths = columnWidths.slice(currentCellCount);
|
|
135
|
+
return ("╟" +
|
|
136
|
+
renderRuleSegment(usedWidths, "─", "┼") +
|
|
137
|
+
"┼" +
|
|
138
|
+
renderRuleSegment(collapsingWidths, "─", "┴") +
|
|
139
|
+
"╢");
|
|
140
|
+
}
|
|
141
|
+
else if (currentCellCount === columnWidths.length) {
|
|
142
|
+
return renderHorizontalRule("╟", columnWidths, "─", innerJoiner, "╢");
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const usedWidths = columnWidths.slice(0, currentCellCount);
|
|
146
|
+
const remainingWidth = getUnusedColumnsWidth(columnWidths, currentCellCount);
|
|
147
|
+
return ("╟" +
|
|
148
|
+
renderRuleSegment(usedWidths, "─", innerJoiner) +
|
|
149
|
+
innerJoiner +
|
|
150
|
+
"─".repeat(remainingWidth + 2) +
|
|
151
|
+
"╢");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Renders the horizontal rule that appears above a row.
|
|
156
|
+
*
|
|
157
|
+
* Handles two cases:
|
|
158
|
+
* - Full width: When row uses all columns, renders with ┼ joiners and
|
|
159
|
+
* ends with ╢ (e.g., "╟───┼───┼───╢")
|
|
160
|
+
* - Short row: When row uses fewer columns, renders active columns with
|
|
161
|
+
* ┼ joiners, ends with ┤, then fills remaining space and ends with ║
|
|
162
|
+
* (e.g., "╟───┼───┤ ║")
|
|
163
|
+
*/
|
|
164
|
+
export function renderRowSeparator(columnWidths, currentCellCount) {
|
|
165
|
+
if (currentCellCount === columnWidths.length) {
|
|
166
|
+
return renderHorizontalRule("╟", columnWidths, "─", "┼", "╢");
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Short row - ends with ┤ instead of ╢
|
|
170
|
+
const usedWidths = columnWidths.slice(0, currentCellCount);
|
|
171
|
+
const remainingWidth = getUnusedColumnsWidth(columnWidths, currentCellCount);
|
|
172
|
+
return ("╟" +
|
|
173
|
+
renderRuleSegment(usedWidths, "─", "┼") +
|
|
174
|
+
"┤" +
|
|
175
|
+
" ".repeat(remainingWidth + 2) +
|
|
176
|
+
"║");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Renders the section's bottom border, placing ╧ marks under column
|
|
181
|
+
* separators where the last row/header had cells (e.g., if the last row
|
|
182
|
+
* looked like "║ a │ b │ ║", the bottom border would be
|
|
183
|
+
* "╚═══╧═══╧═══════╝").
|
|
184
|
+
*/
|
|
185
|
+
export function renderSectionClose(columnWidths, previousCellCount) {
|
|
186
|
+
if (previousCellCount === columnWidths.length) {
|
|
187
|
+
return renderHorizontalRule("╚", columnWidths, "═", "╧", "╝");
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const usedWidths = columnWidths.slice(0, previousCellCount);
|
|
191
|
+
const unusedWidth = getUnusedColumnsWidth(columnWidths, previousCellCount);
|
|
192
|
+
return ("╚" +
|
|
193
|
+
renderRuleSegment(usedWidths, "═", "╧") +
|
|
194
|
+
"╧" +
|
|
195
|
+
renderRuleSegment([unusedWidth], "═", "") +
|
|
196
|
+
"╝");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/internal/format.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,sCAAsC;IACtC,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,MAAM,YAAY,GAAa,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;gBAC7B,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,YAAsB;IACpD,OAAO,CACL,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAA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