@fnndsc/chili 3.2.5
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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/chefs/chefs.d.ts +15 -0
- package/dist/chefs/chefs.js +195 -0
- package/dist/commands/compute/fields.d.ts +6 -0
- package/dist/commands/compute/fields.js +13 -0
- package/dist/commands/compute/list.d.ts +19 -0
- package/dist/commands/compute/list.js +20 -0
- package/dist/commands/connect/login.d.ts +16 -0
- package/dist/commands/connect/login.js +18 -0
- package/dist/commands/connect/logout.d.ts +6 -0
- package/dist/commands/connect/logout.js +16 -0
- package/dist/commands/feed/comments.d.ts +41 -0
- package/dist/commands/feed/comments.js +45 -0
- package/dist/commands/feed/create.d.ts +13 -0
- package/dist/commands/feed/create.js +40 -0
- package/dist/commands/feed/note.d.ts +21 -0
- package/dist/commands/feed/note.js +24 -0
- package/dist/commands/feeds/delete.d.ts +14 -0
- package/dist/commands/feeds/delete.js +34 -0
- package/dist/commands/feeds/fields.d.ts +6 -0
- package/dist/commands/feeds/fields.js +17 -0
- package/dist/commands/feeds/list.d.ts +17 -0
- package/dist/commands/feeds/list.js +38 -0
- package/dist/commands/feeds/share.d.ts +17 -0
- package/dist/commands/feeds/share.js +19 -0
- package/dist/commands/file/view.d.ts +8 -0
- package/dist/commands/file/view.js +25 -0
- package/dist/commands/files/delete.d.ts +16 -0
- package/dist/commands/files/delete.js +36 -0
- package/dist/commands/files/fields.d.ts +7 -0
- package/dist/commands/files/fields.js +18 -0
- package/dist/commands/files/list.d.ts +11 -0
- package/dist/commands/files/list.js +23 -0
- package/dist/commands/fs/cat.d.ts +15 -0
- package/dist/commands/fs/cat.js +26 -0
- package/dist/commands/fs/cp.d.ts +17 -0
- package/dist/commands/fs/cp.js +26 -0
- package/dist/commands/fs/create.d.ts +15 -0
- package/dist/commands/fs/create.js +83 -0
- package/dist/commands/fs/download.d.ts +25 -0
- package/dist/commands/fs/download.js +235 -0
- package/dist/commands/fs/edit.d.ts +16 -0
- package/dist/commands/fs/edit.js +25 -0
- package/dist/commands/fs/ls.d.ts +18 -0
- package/dist/commands/fs/ls.js +142 -0
- package/dist/commands/fs/mkdir.d.ts +8 -0
- package/dist/commands/fs/mkdir.js +21 -0
- package/dist/commands/fs/mv.d.ts +13 -0
- package/dist/commands/fs/mv.js +73 -0
- package/dist/commands/fs/rm.d.ts +24 -0
- package/dist/commands/fs/rm.js +108 -0
- package/dist/commands/fs/touch.d.ts +16 -0
- package/dist/commands/fs/touch.js +62 -0
- package/dist/commands/fs/upload.d.ts +55 -0
- package/dist/commands/fs/upload.js +221 -0
- package/dist/commands/groups/fields.d.ts +6 -0
- package/dist/commands/groups/fields.js +13 -0
- package/dist/commands/groups/list.d.ts +16 -0
- package/dist/commands/groups/list.js +26 -0
- package/dist/commands/man/doc.d.ts +16 -0
- package/dist/commands/man/doc.js +32 -0
- package/dist/commands/man/topics.d.ts +6 -0
- package/dist/commands/man/topics.js +27 -0
- package/dist/commands/pipeline/fields.d.ts +6 -0
- package/dist/commands/pipeline/fields.js +13 -0
- package/dist/commands/pipeline/run.d.ts +18 -0
- package/dist/commands/pipeline/run.js +33 -0
- package/dist/commands/plugin/readme.d.ts +14 -0
- package/dist/commands/plugin/readme.js +49 -0
- package/dist/commands/plugin/run.d.ts +10 -0
- package/dist/commands/plugin/run.js +29 -0
- package/dist/commands/plugin/search.d.ts +7 -0
- package/dist/commands/plugin/search.js +18 -0
- package/dist/commands/plugininstances/fields.d.ts +6 -0
- package/dist/commands/plugininstances/fields.js +13 -0
- package/dist/commands/plugininstances/list.d.ts +16 -0
- package/dist/commands/plugininstances/list.js +26 -0
- package/dist/commands/pluginmetas/fields.d.ts +6 -0
- package/dist/commands/pluginmetas/fields.js +13 -0
- package/dist/commands/pluginmetas/list.d.ts +16 -0
- package/dist/commands/pluginmetas/list.js +26 -0
- package/dist/commands/plugins/add.d.ts +34 -0
- package/dist/commands/plugins/add.js +374 -0
- package/dist/commands/plugins/delete.d.ts +14 -0
- package/dist/commands/plugins/delete.js +34 -0
- package/dist/commands/plugins/fields.d.ts +6 -0
- package/dist/commands/plugins/fields.js +17 -0
- package/dist/commands/plugins/list.d.ts +17 -0
- package/dist/commands/plugins/list.js +40 -0
- package/dist/commands/plugins/overview.d.ts +6 -0
- package/dist/commands/plugins/overview.js +17 -0
- package/dist/commands/store/list.d.ts +23 -0
- package/dist/commands/store/list.js +48 -0
- package/dist/commands/tags/fields.d.ts +6 -0
- package/dist/commands/tags/fields.js +13 -0
- package/dist/commands/tags/list.d.ts +16 -0
- package/dist/commands/tags/list.js +26 -0
- package/dist/commands/workflows/fields.d.ts +6 -0
- package/dist/commands/workflows/fields.js +13 -0
- package/dist/commands/workflows/list.d.ts +16 -0
- package/dist/commands/workflows/list.js +26 -0
- package/dist/config/colorConfig.d.ts +56 -0
- package/dist/config/colorConfig.js +161 -0
- package/dist/connect/connectHandler.d.ts +15 -0
- package/dist/connect/connectHandler.js +48 -0
- package/dist/context/contextCommand.d.ts +13 -0
- package/dist/context/contextCommand.js +193 -0
- package/dist/controllers/baseController.d.ts +43 -0
- package/dist/controllers/baseController.js +67 -0
- package/dist/controllers/feedController.d.ts +35 -0
- package/dist/controllers/feedController.js +53 -0
- package/dist/controllers/fileController.d.ts +56 -0
- package/dist/controllers/fileController.js +93 -0
- package/dist/controllers/pluginContextController.d.ts +24 -0
- package/dist/controllers/pluginContextController.js +49 -0
- package/dist/controllers/pluginController.d.ts +70 -0
- package/dist/controllers/pluginController.js +98 -0
- package/dist/controllers/pluginMetaController.d.ts +41 -0
- package/dist/controllers/pluginMetaController.js +52 -0
- package/dist/feeds/feedHandler.d.ts +64 -0
- package/dist/feeds/feedHandler.js +203 -0
- package/dist/filesystem/fileGroupHandler.d.ts +92 -0
- package/dist/filesystem/fileGroupHandler.js +318 -0
- package/dist/filesystem/filesystemHandler.d.ts +12 -0
- package/dist/filesystem/filesystemHandler.js +135 -0
- package/dist/filesystem/inodeCommand.d.ts +12 -0
- package/dist/filesystem/inodeCommand.js +37 -0
- package/dist/handlers/baseGroupHandler.d.ts +103 -0
- package/dist/handlers/baseGroupHandler.js +342 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +239 -0
- package/dist/lfs/lfs.d.ts +25 -0
- package/dist/lfs/lfs.js +74 -0
- package/dist/man/man.d.ts +15 -0
- package/dist/man/man.js +31 -0
- package/dist/man/renderer.d.ts +26 -0
- package/dist/man/renderer.js +187 -0
- package/dist/models/feed.d.ts +18 -0
- package/dist/models/feed.js +8 -0
- package/dist/models/listing.d.ts +33 -0
- package/dist/models/listing.js +9 -0
- package/dist/models/plugin.d.ts +27 -0
- package/dist/models/plugin.js +1 -0
- package/dist/models/resource.d.ts +39 -0
- package/dist/models/resource.js +9 -0
- package/dist/pacs/pacsQueryHandler.d.ts +55 -0
- package/dist/pacs/pacsQueryHandler.js +196 -0
- package/dist/pacs/pacsQueryPayload.d.ts +19 -0
- package/dist/pacs/pacsQueryPayload.js +44 -0
- package/dist/pacs/pacsResultRender.d.ts +20 -0
- package/dist/pacs/pacsResultRender.js +141 -0
- package/dist/pacs/pacsRetrieveHandler.d.ts +87 -0
- package/dist/pacs/pacsRetrieveHandler.js +272 -0
- package/dist/pacs/pacsServerHandler.d.ts +15 -0
- package/dist/pacs/pacsServerHandler.js +32 -0
- package/dist/path/pathCommand.d.ts +64 -0
- package/dist/path/pathCommand.js +805 -0
- package/dist/path/pathMapper.d.ts +189 -0
- package/dist/path/pathMapper.js +382 -0
- package/dist/plugins/pluginGroupHandler.d.ts +42 -0
- package/dist/plugins/pluginGroupHandler.js +90 -0
- package/dist/plugins/pluginHandler.d.ts +87 -0
- package/dist/plugins/pluginHandler.js +303 -0
- package/dist/plugins/pluginMetaHandler.d.ts +21 -0
- package/dist/plugins/pluginMetaHandler.js +27 -0
- package/dist/screen/screen.d.ts +214 -0
- package/dist/screen/screen.js +478 -0
- package/dist/utils/admin_prompt.d.ts +42 -0
- package/dist/utils/admin_prompt.js +105 -0
- package/dist/utils/cli.d.ts +67 -0
- package/dist/utils/cli.js +112 -0
- package/dist/utils/docker.d.ts +74 -0
- package/dist/utils/docker.js +155 -0
- package/dist/utils/input_format.d.ts +77 -0
- package/dist/utils/input_format.js +135 -0
- package/dist/utils/sort.d.ts +29 -0
- package/dist/utils/sort.js +63 -0
- package/dist/utils/ui.d.ts +7 -0
- package/dist/utils/ui.js +26 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +14 -0
- package/dist/views/compute.d.ts +17 -0
- package/dist/views/compute.js +40 -0
- package/dist/views/connect.d.ts +13 -0
- package/dist/views/connect.js +35 -0
- package/dist/views/feed.d.ts +44 -0
- package/dist/views/feed.js +110 -0
- package/dist/views/file.d.ts +25 -0
- package/dist/views/file.js +71 -0
- package/dist/views/fs.d.ts +51 -0
- package/dist/views/fs.js +105 -0
- package/dist/views/ls.d.ts +37 -0
- package/dist/views/ls.js +190 -0
- package/dist/views/plugin.d.ts +28 -0
- package/dist/views/plugin.js +71 -0
- package/dist/views/pluginParameters.d.ts +17 -0
- package/dist/views/pluginParameters.js +79 -0
- package/docs/00_intro.adoc +25 -0
- package/docs/01_setup.adoc +63 -0
- package/docs/02_context.adoc +128 -0
- package/docs/03_searchable.adoc +134 -0
- package/docs/10_everyday_examples.adoc +9 -0
- package/docs/11_upload_data.adoc +146 -0
- package/docs/12_create_a_feed.adoc +9 -0
- package/docs/13_run_a_plugin.adoc +271 -0
- package/docs/20_plugins.adoc +16 -0
- package/docs/21_pluginReadme.adoc +123 -0
- package/docs/30_filesystem.adoc +93 -0
- package/docs/31_fileops.adoc +51 -0
- package/docs/32_file_content.adoc +471 -0
- package/docs/_architecture.adoc +48 -0
- package/docs/_deepContext.adoc +84 -0
- package/docs/_roadmap.adoc +42 -0
- package/docs/_searchable.adoc +187 -0
- package/docs/_state.adoc +68 -0
- package/docs/pacs.adoc +101 -0
- package/docs/pathMapper.md +246 -0
- package/package.json +92 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Terminal table/screen rendering utilities and the Screen singleton.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A chalk-style color function mapping a string to a styled string.
|
|
8
|
+
*/
|
|
9
|
+
export interface ChalkColorFunction {
|
|
10
|
+
(text: string): string;
|
|
11
|
+
bold: (text: string) => string;
|
|
12
|
+
}
|
|
13
|
+
type Justification = "left" | "center" | "right";
|
|
14
|
+
/**
|
|
15
|
+
* Per-column rendering options for table output.
|
|
16
|
+
*/
|
|
17
|
+
export interface ColumnOptions {
|
|
18
|
+
width?: number;
|
|
19
|
+
color?: string;
|
|
20
|
+
justification?: Justification;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options controlling table rendering (borders, headers, colors).
|
|
24
|
+
*/
|
|
25
|
+
export interface TableOptions {
|
|
26
|
+
columns?: ColumnOptions[];
|
|
27
|
+
head?: string[];
|
|
28
|
+
typeColors?: {
|
|
29
|
+
number?: string;
|
|
30
|
+
string?: string;
|
|
31
|
+
boolean?: string;
|
|
32
|
+
object?: string;
|
|
33
|
+
};
|
|
34
|
+
title?: Title;
|
|
35
|
+
borderless?: boolean;
|
|
36
|
+
/** When set and shown < total, renders a pagination footer after the table. */
|
|
37
|
+
pagination?: {
|
|
38
|
+
shown: number;
|
|
39
|
+
total: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface Title {
|
|
43
|
+
title: string;
|
|
44
|
+
justification?: Justification;
|
|
45
|
+
}
|
|
46
|
+
interface Borders {
|
|
47
|
+
left?: boolean;
|
|
48
|
+
top?: boolean;
|
|
49
|
+
right?: boolean;
|
|
50
|
+
bottom?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A single row of table data keyed by column name.
|
|
54
|
+
*/
|
|
55
|
+
export interface TableDataRow {
|
|
56
|
+
[key: string]: string | number | boolean | null | undefined | object | unknown;
|
|
57
|
+
}
|
|
58
|
+
interface TableContent {
|
|
59
|
+
headers: string[];
|
|
60
|
+
body: unknown[][];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Draws a border around the given text.
|
|
64
|
+
*
|
|
65
|
+
* @param text - The text to wrap with a border.
|
|
66
|
+
* @param borders - Optional configuration for which borders to draw.
|
|
67
|
+
* @returns The text surrounded by a border.
|
|
68
|
+
*/
|
|
69
|
+
export declare function border_draw(text: string, borders?: Borders): string;
|
|
70
|
+
/**
|
|
71
|
+
* Displays a formatted table in the console.
|
|
72
|
+
*
|
|
73
|
+
* @param tableData - The data for the table.
|
|
74
|
+
* @param headers - The headers for the table.
|
|
75
|
+
* @param options - Optional table display options.
|
|
76
|
+
* @returns The `TableContent` object or null on error.
|
|
77
|
+
*/
|
|
78
|
+
export declare function table_display(tableData: TableDataRow[] | string[][] | string[], headers: string[] | string, options?: TableOptions): TableContent | null;
|
|
79
|
+
/**
|
|
80
|
+
* Provides screen utilities for logging and table output.
|
|
81
|
+
*/
|
|
82
|
+
export declare class Screen {
|
|
83
|
+
log(...args: unknown[]): void;
|
|
84
|
+
error(...args: unknown[]): void;
|
|
85
|
+
warn(...args: unknown[]): void;
|
|
86
|
+
info(...args: unknown[]): void;
|
|
87
|
+
/**
|
|
88
|
+
* Generates a formatted table output string.
|
|
89
|
+
*
|
|
90
|
+
* @param data - The data to display in the table.
|
|
91
|
+
* @param options - Options for table formatting, including headers, columns, and title.
|
|
92
|
+
* @returns A string representation of the formatted table.
|
|
93
|
+
*/
|
|
94
|
+
table_output(data: TableDataRow[] | Object, options?: TableOptions): string;
|
|
95
|
+
/**
|
|
96
|
+
* Prepares raw data for table display.
|
|
97
|
+
*
|
|
98
|
+
* @param data - The input data, which can be an array or an object.
|
|
99
|
+
* @param options - Table options, specifically for `head`.
|
|
100
|
+
* @returns An object containing `tableData` (2D array) and `headers`.
|
|
101
|
+
*/
|
|
102
|
+
private data_prepare;
|
|
103
|
+
/**
|
|
104
|
+
* Ensures that the `columns` option has enough entries for all table columns.
|
|
105
|
+
*
|
|
106
|
+
* @param tableData - The 2D array of table data.
|
|
107
|
+
* @param headers - The array of table headers.
|
|
108
|
+
* @param options - Table options.
|
|
109
|
+
* @returns An array of `ColumnOptions` with enough entries for all columns.
|
|
110
|
+
*/
|
|
111
|
+
private safeColumns_prepare;
|
|
112
|
+
/**
|
|
113
|
+
* Calculates the width for each column.
|
|
114
|
+
*
|
|
115
|
+
* @param tableData - The 2D array of table data.
|
|
116
|
+
* @param headers - The array of table headers.
|
|
117
|
+
* @param safeColumns - The array of `ColumnOptions` for each column.
|
|
118
|
+
* @returns An array of numbers representing the calculated width for each column.
|
|
119
|
+
*/
|
|
120
|
+
private columnWidths_calculate;
|
|
121
|
+
/**
|
|
122
|
+
* Calculates the maximum visible width for a specific column.
|
|
123
|
+
*
|
|
124
|
+
* @param data - The 2D array of data (including headers).
|
|
125
|
+
* @param columnIndex - The index of the column to calculate width for.
|
|
126
|
+
* @returns The maximum visible length in the column.
|
|
127
|
+
*/
|
|
128
|
+
private columnWidth_calculate;
|
|
129
|
+
/**
|
|
130
|
+
* Applies styling (color, justification) to the table data.
|
|
131
|
+
*
|
|
132
|
+
* @param tableData - The 2D array of raw table data.
|
|
133
|
+
* @param headers - The array of table headers.
|
|
134
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
135
|
+
* @param colWidths - The calculated widths for each column.
|
|
136
|
+
* @param options - Table options for type colors.
|
|
137
|
+
* @returns A 2D array of styled strings.
|
|
138
|
+
*/
|
|
139
|
+
private data_applyStyle;
|
|
140
|
+
/**
|
|
141
|
+
* Styles an individual table cell based on its content type and column options.
|
|
142
|
+
*
|
|
143
|
+
* @param cell - The cell content.
|
|
144
|
+
* @param index - The column index of the cell.
|
|
145
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
146
|
+
* @param colWidths - The calculated width for the column.
|
|
147
|
+
* @param options - Table options for type colors.
|
|
148
|
+
* @returns The styled and justified cell string.
|
|
149
|
+
*/
|
|
150
|
+
private cell_style;
|
|
151
|
+
/**
|
|
152
|
+
* Styles a table header cell.
|
|
153
|
+
*
|
|
154
|
+
* @param header - The header string.
|
|
155
|
+
* @param index - The column index of the header.
|
|
156
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
157
|
+
* @param colWidths - The calculated width for the column.
|
|
158
|
+
* @returns The styled and justified header string.
|
|
159
|
+
*/
|
|
160
|
+
private header_style;
|
|
161
|
+
/**
|
|
162
|
+
* Determines the color for a cell based on its type.
|
|
163
|
+
*
|
|
164
|
+
* @param cell - The cell content.
|
|
165
|
+
* @param typeColors - Map of type to color strings.
|
|
166
|
+
* @returns The color string or undefined if no specific color for the type.
|
|
167
|
+
*/
|
|
168
|
+
private color_determine;
|
|
169
|
+
/**
|
|
170
|
+
* Prepares the title string for the table, including justification and truncation.
|
|
171
|
+
*
|
|
172
|
+
* @param title - The Title object.
|
|
173
|
+
* @param width - The total width of the table.
|
|
174
|
+
* @returns The formatted title string.
|
|
175
|
+
*/
|
|
176
|
+
private title_prepare;
|
|
177
|
+
/**
|
|
178
|
+
* Prepares the `table` library configuration object.
|
|
179
|
+
*
|
|
180
|
+
* @param hasTitle - Whether the table has a title (affects border drawing).
|
|
181
|
+
* @param options - Table options to check for borderless mode.
|
|
182
|
+
* @returns The `TableUserConfig` object.
|
|
183
|
+
*/
|
|
184
|
+
private tableConfig_prepare;
|
|
185
|
+
/**
|
|
186
|
+
* Calculates the visible length of a string, accounting for ANSI escape codes.
|
|
187
|
+
*
|
|
188
|
+
* @param str - The string to measure.
|
|
189
|
+
* @returns The visible length of the string.
|
|
190
|
+
*/
|
|
191
|
+
private visibleLength_get;
|
|
192
|
+
/**
|
|
193
|
+
* Safely converts any value to a string.
|
|
194
|
+
*
|
|
195
|
+
* @param value - The value to convert.
|
|
196
|
+
* @returns The string representation of the value.
|
|
197
|
+
*/
|
|
198
|
+
private string_safeConvert;
|
|
199
|
+
/**
|
|
200
|
+
* Justifies text within a given width.
|
|
201
|
+
*
|
|
202
|
+
* @param text - The text to justify.
|
|
203
|
+
* @param width - The total width for justification.
|
|
204
|
+
* @param justification - The justification type ('left', 'center', 'right').
|
|
205
|
+
* @returns The justified text string.
|
|
206
|
+
*/
|
|
207
|
+
private text_justify;
|
|
208
|
+
clear(): void;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Shared Screen singleton for terminal rendering.
|
|
212
|
+
*/
|
|
213
|
+
export declare const screen: Screen;
|
|
214
|
+
export {};
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Terminal table/screen rendering utilities and the Screen singleton.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { table, getBorderCharacters } from "table";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
/**
|
|
9
|
+
* Processes raw table input data and headers into a standardized format.
|
|
10
|
+
*
|
|
11
|
+
* @param tableData - The raw table data, can be `TableDataRow[] | string[][] | string[]`.
|
|
12
|
+
* @param headers - The headers for the table, can be `string[] | string`.
|
|
13
|
+
* @returns An object containing the processed table data and headers.
|
|
14
|
+
*/
|
|
15
|
+
function tableInput_process(tableData, headers) {
|
|
16
|
+
let processedTableData;
|
|
17
|
+
let processedHeaders;
|
|
18
|
+
processedHeaders = Array.isArray(headers)
|
|
19
|
+
? headers
|
|
20
|
+
: headers.split(",").map((h) => h.trim());
|
|
21
|
+
if (Array.isArray(tableData) &&
|
|
22
|
+
Array.isArray(tableData[0]) &&
|
|
23
|
+
typeof tableData[0][0] === "string") {
|
|
24
|
+
// tableData is a string[][]
|
|
25
|
+
processedTableData = tableData.map((row) => {
|
|
26
|
+
return processedHeaders.reduce((rowObj, header, index) => {
|
|
27
|
+
rowObj[header] = row[index];
|
|
28
|
+
return rowObj;
|
|
29
|
+
}, {});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (Array.isArray(tableData) && typeof tableData[0] === "string") {
|
|
33
|
+
// tableData is a string[]
|
|
34
|
+
processedTableData = tableData.map((rowStr) => {
|
|
35
|
+
const rowValues = rowStr.split(",");
|
|
36
|
+
return processedHeaders.reduce((rowObj, header, index) => {
|
|
37
|
+
rowObj[header] = rowValues[index];
|
|
38
|
+
return rowObj;
|
|
39
|
+
}, {});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// tableData is neither string[][] nor string[]
|
|
44
|
+
processedTableData = tableData;
|
|
45
|
+
}
|
|
46
|
+
return { processedTableData, processedHeaders };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Packs table data and selected fields into a `TableContent` object.
|
|
50
|
+
*
|
|
51
|
+
* @param tableData - The table data.
|
|
52
|
+
* @param selectedFields - The fields to include as headers.
|
|
53
|
+
* @returns A `TableContent` object or null if invalid data.
|
|
54
|
+
*/
|
|
55
|
+
function tableContent_pack(tableData, selectedFields) {
|
|
56
|
+
let headers;
|
|
57
|
+
let body;
|
|
58
|
+
if (Array.isArray(tableData) && tableData.length > 0) {
|
|
59
|
+
headers = selectedFields;
|
|
60
|
+
body = tableData.map((row) => headers.map((field) => (row[field] !== undefined ? row[field] : "")));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error("Invalid table data");
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return { headers, body };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Draws a border around the given text.
|
|
70
|
+
*
|
|
71
|
+
* @param text - The text to wrap with a border.
|
|
72
|
+
* @param borders - Optional configuration for which borders to draw.
|
|
73
|
+
* @returns The text surrounded by a border.
|
|
74
|
+
*/
|
|
75
|
+
export function border_draw(text, borders = {}) {
|
|
76
|
+
const defaultBorders = {
|
|
77
|
+
left: true,
|
|
78
|
+
top: true,
|
|
79
|
+
right: true,
|
|
80
|
+
bottom: true,
|
|
81
|
+
};
|
|
82
|
+
const actualBorders = { ...defaultBorders, ...borders };
|
|
83
|
+
const lines = text.split("\n");
|
|
84
|
+
const data = lines.map((line) => [line]);
|
|
85
|
+
const config = {
|
|
86
|
+
border: getBorderCharacters("norc"),
|
|
87
|
+
columnDefault: {
|
|
88
|
+
paddingLeft: 1,
|
|
89
|
+
paddingRight: 1,
|
|
90
|
+
},
|
|
91
|
+
drawHorizontalLine: (index, size) => (actualBorders.top && index === 0) ||
|
|
92
|
+
(actualBorders.bottom && index === size),
|
|
93
|
+
drawVerticalLine: (index, size) => (actualBorders.left && index === 0) ||
|
|
94
|
+
(actualBorders.right && index === 1),
|
|
95
|
+
};
|
|
96
|
+
return table(data, config).trim();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Applies default settings to the first column of a table.
|
|
100
|
+
*
|
|
101
|
+
* @param columns - An array of ColumnOptions.
|
|
102
|
+
* @returns The updated array of ColumnOptions.
|
|
103
|
+
*/
|
|
104
|
+
function firstColumnSettings_apply(columns) {
|
|
105
|
+
if (columns.length > 1) {
|
|
106
|
+
return [
|
|
107
|
+
{ ...columns[0], justification: "right", color: "white" },
|
|
108
|
+
...columns.slice(1),
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
return columns;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Displays a formatted table in the console.
|
|
115
|
+
*
|
|
116
|
+
* @param tableData - The data for the table.
|
|
117
|
+
* @param headers - The headers for the table.
|
|
118
|
+
* @param options - Optional table display options.
|
|
119
|
+
* @returns The `TableContent` object or null on error.
|
|
120
|
+
*/
|
|
121
|
+
export function table_display(tableData, headers, options = {}) {
|
|
122
|
+
const { processedTableData, processedHeaders } = tableInput_process(tableData, headers);
|
|
123
|
+
const tableObj = tableContent_pack(processedTableData, processedHeaders);
|
|
124
|
+
if (!tableObj) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const columns = tableObj.headers.map((_, index) => {
|
|
128
|
+
const existingCol = options.columns?.[index] || {};
|
|
129
|
+
return {
|
|
130
|
+
justification: "left",
|
|
131
|
+
...existingCol,
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
const updatedColumns = firstColumnSettings_apply(columns);
|
|
135
|
+
const tableOptions = {
|
|
136
|
+
...options,
|
|
137
|
+
head: processedHeaders,
|
|
138
|
+
columns: updatedColumns,
|
|
139
|
+
typeColors: {
|
|
140
|
+
string: "green",
|
|
141
|
+
number: "yellow",
|
|
142
|
+
boolean: "cyan",
|
|
143
|
+
object: "magenta",
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
const result = screen.table_output(processedTableData, tableOptions);
|
|
147
|
+
console.log(result);
|
|
148
|
+
if (options.pagination && options.pagination.shown < options.pagination.total) {
|
|
149
|
+
const { shown, total } = options.pagination;
|
|
150
|
+
console.log(chalk.dim(` ↓ showing ${shown} of ${total} · --all to fetch all · --limit <n> for page size`));
|
|
151
|
+
}
|
|
152
|
+
return tableObj;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Provides screen utilities for logging and table output.
|
|
156
|
+
*/
|
|
157
|
+
export class Screen {
|
|
158
|
+
log(...args) {
|
|
159
|
+
console.log(...args);
|
|
160
|
+
}
|
|
161
|
+
error(...args) {
|
|
162
|
+
console.error(chalk.red(...args));
|
|
163
|
+
}
|
|
164
|
+
warn(...args) {
|
|
165
|
+
console.warn(chalk.yellow(...args));
|
|
166
|
+
}
|
|
167
|
+
info(...args) {
|
|
168
|
+
console.info(chalk.blue(...args));
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Generates a formatted table output string.
|
|
172
|
+
*
|
|
173
|
+
* @param data - The data to display in the table.
|
|
174
|
+
* @param options - Options for table formatting, including headers, columns, and title.
|
|
175
|
+
* @returns A string representation of the formatted table.
|
|
176
|
+
*/
|
|
177
|
+
table_output(data, options = {}) {
|
|
178
|
+
try {
|
|
179
|
+
const { tableData, headers } = this.data_prepare(data, options);
|
|
180
|
+
const safeColumns = this.safeColumns_prepare(tableData, headers, options);
|
|
181
|
+
const colWidths = this.columnWidths_calculate(tableData, headers, safeColumns);
|
|
182
|
+
const styledData = this.data_applyStyle(tableData, headers, safeColumns, colWidths, options);
|
|
183
|
+
// First pass: Generate table without title to get width
|
|
184
|
+
const config = this.tableConfig_prepare(false, options);
|
|
185
|
+
const tempOutput = table(styledData, config);
|
|
186
|
+
const tableWidth = tempOutput.split("\n")[0].length;
|
|
187
|
+
// Prepare title if needed
|
|
188
|
+
let titleString = "";
|
|
189
|
+
if (options.title) {
|
|
190
|
+
titleString = this.title_prepare(options.title, tableWidth);
|
|
191
|
+
}
|
|
192
|
+
// Second pass: Generate full table with correct title
|
|
193
|
+
const fullConfig = this.tableConfig_prepare(!!options.title, options);
|
|
194
|
+
const output = table(styledData, fullConfig);
|
|
195
|
+
// Combine title (if any) and table
|
|
196
|
+
return titleString
|
|
197
|
+
? border_draw(titleString, { bottom: false }) + "\n" + output
|
|
198
|
+
: output;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
console.error("Error in table_output method:", error);
|
|
202
|
+
return "Error generating table";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Prepares raw data for table display.
|
|
207
|
+
*
|
|
208
|
+
* @param data - The input data, which can be an array or an object.
|
|
209
|
+
* @param options - Table options, specifically for `head`.
|
|
210
|
+
* @returns An object containing `tableData` (2D array) and `headers`.
|
|
211
|
+
*/
|
|
212
|
+
data_prepare(data, options) {
|
|
213
|
+
if (Array.isArray(data)) {
|
|
214
|
+
const headers = options.head || Object.keys(data[0]);
|
|
215
|
+
const tableData = data.map((row) => headers.map((header) => (row[header] !== undefined ? row[header] : "")));
|
|
216
|
+
return { tableData, headers };
|
|
217
|
+
}
|
|
218
|
+
if (typeof data === "object" && data !== null) {
|
|
219
|
+
const headers = options.head || ["Key", "Value"];
|
|
220
|
+
const tableData = Object.entries(data);
|
|
221
|
+
return { tableData, headers };
|
|
222
|
+
}
|
|
223
|
+
const headers = options.head || ["Value"];
|
|
224
|
+
const tableData = [[data]];
|
|
225
|
+
return { tableData, headers };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Ensures that the `columns` option has enough entries for all table columns.
|
|
229
|
+
*
|
|
230
|
+
* @param tableData - The 2D array of table data.
|
|
231
|
+
* @param headers - The array of table headers.
|
|
232
|
+
* @param options - Table options.
|
|
233
|
+
* @returns An array of `ColumnOptions` with enough entries for all columns.
|
|
234
|
+
*/
|
|
235
|
+
safeColumns_prepare(tableData, headers, options) {
|
|
236
|
+
const safeColumns = options.columns || [];
|
|
237
|
+
const columnCount = Math.max(headers.length, ...tableData.map((row) => row.length));
|
|
238
|
+
while (safeColumns.length < columnCount) {
|
|
239
|
+
safeColumns.push({});
|
|
240
|
+
}
|
|
241
|
+
return safeColumns;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Calculates the width for each column.
|
|
245
|
+
*
|
|
246
|
+
* @param tableData - The 2D array of table data.
|
|
247
|
+
* @param headers - The array of table headers.
|
|
248
|
+
* @param safeColumns - The array of `ColumnOptions` for each column.
|
|
249
|
+
* @returns An array of numbers representing the calculated width for each column.
|
|
250
|
+
*/
|
|
251
|
+
columnWidths_calculate(tableData, headers, safeColumns) {
|
|
252
|
+
return safeColumns.map((col, index) => col.width || this.columnWidth_calculate([headers, ...tableData], index));
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Calculates the maximum visible width for a specific column.
|
|
256
|
+
*
|
|
257
|
+
* @param data - The 2D array of data (including headers).
|
|
258
|
+
* @param columnIndex - The index of the column to calculate width for.
|
|
259
|
+
* @returns The maximum visible length in the column.
|
|
260
|
+
*/
|
|
261
|
+
columnWidth_calculate(data, columnIndex) {
|
|
262
|
+
const columnData = data.map((row) => row[columnIndex]);
|
|
263
|
+
const maxWidth = Math.max(...columnData.map((cell) => this.visibleLength_get(this.string_safeConvert(cell))), 0);
|
|
264
|
+
return maxWidth; // Add some padding
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Applies styling (color, justification) to the table data.
|
|
268
|
+
*
|
|
269
|
+
* @param tableData - The 2D array of raw table data.
|
|
270
|
+
* @param headers - The array of table headers.
|
|
271
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
272
|
+
* @param colWidths - The calculated widths for each column.
|
|
273
|
+
* @param options - Table options for type colors.
|
|
274
|
+
* @returns A 2D array of styled strings.
|
|
275
|
+
*/
|
|
276
|
+
data_applyStyle(tableData, headers, safeColumns, colWidths, options) {
|
|
277
|
+
const styledData = tableData.map((row) => row.map((cell, index) => this.cell_style(cell, index, safeColumns, colWidths, options)));
|
|
278
|
+
const styledHeaders = headers.map((header, index) => this.header_style(header, index, safeColumns, colWidths));
|
|
279
|
+
return [styledHeaders, ...styledData];
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Styles an individual table cell based on its content type and column options.
|
|
283
|
+
*
|
|
284
|
+
* @param cell - The cell content.
|
|
285
|
+
* @param index - The column index of the cell.
|
|
286
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
287
|
+
* @param colWidths - The calculated width for the column.
|
|
288
|
+
* @param options - Table options for type colors.
|
|
289
|
+
* @returns The styled and justified cell string.
|
|
290
|
+
*/
|
|
291
|
+
cell_style(cell, index, safeColumns, colWidths, options) {
|
|
292
|
+
const columnOptions = safeColumns[index] || {};
|
|
293
|
+
const justification = columnOptions.justification || "left";
|
|
294
|
+
const width = colWidths[index]; // This is the target width for the column
|
|
295
|
+
// Use explicit width from column options if available for truncation limit,
|
|
296
|
+
// otherwise use the calculated width (which fits the content anyway).
|
|
297
|
+
// Actually, colWidths[index] comes from columnWidths_calculate which respects columnOptions.width.
|
|
298
|
+
// So 'width' IS the limit if specified.
|
|
299
|
+
let cellString = this.string_safeConvert(cell);
|
|
300
|
+
const rawLength = this.visibleLength_get(cellString);
|
|
301
|
+
// Truncate if necessary (only if explicit width was likely set or calculated width is restrictive)
|
|
302
|
+
// Note: If width comes from content, rawLength <= width.
|
|
303
|
+
// If width comes from columnOptions.width, it might be < rawLength.
|
|
304
|
+
if (columnOptions.width && rawLength > width) {
|
|
305
|
+
const truncateLen = Math.max(0, width - 3);
|
|
306
|
+
cellString = cellString.slice(0, truncateLen) + "...";
|
|
307
|
+
}
|
|
308
|
+
let color = columnOptions.color;
|
|
309
|
+
if (!color && options.typeColors) {
|
|
310
|
+
color = this.color_determine(cell, options.typeColors);
|
|
311
|
+
}
|
|
312
|
+
const chalkColors = chalk;
|
|
313
|
+
const colorFn = color ? chalkColors[color] : undefined;
|
|
314
|
+
const coloredCell = cellString.includes("\u001b")
|
|
315
|
+
? cellString
|
|
316
|
+
: colorFn
|
|
317
|
+
? colorFn(cellString)
|
|
318
|
+
: cellString;
|
|
319
|
+
return this.text_justify(coloredCell, width, justification);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Styles a table header cell.
|
|
323
|
+
*
|
|
324
|
+
* @param header - The header string.
|
|
325
|
+
* @param index - The column index of the header.
|
|
326
|
+
* @param safeColumns - The array of `ColumnOptions`.
|
|
327
|
+
* @param colWidths - The calculated width for the column.
|
|
328
|
+
* @returns The styled and justified header string.
|
|
329
|
+
*/
|
|
330
|
+
header_style(header, index, safeColumns, colWidths) {
|
|
331
|
+
const columnOptions = safeColumns[index] || {};
|
|
332
|
+
const color = columnOptions.color || "white";
|
|
333
|
+
const justification = columnOptions.justification || "left";
|
|
334
|
+
const width = colWidths[index];
|
|
335
|
+
const chalkColors = chalk;
|
|
336
|
+
const colorFn = chalkColors[color] || chalkColors.white;
|
|
337
|
+
return this.text_justify(colorFn.bold(header), width, justification);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Determines the color for a cell based on its type.
|
|
341
|
+
*
|
|
342
|
+
* @param cell - The cell content.
|
|
343
|
+
* @param typeColors - Map of type to color strings.
|
|
344
|
+
* @returns The color string or undefined if no specific color for the type.
|
|
345
|
+
*/
|
|
346
|
+
color_determine(cell, typeColors) {
|
|
347
|
+
if (typeof cell === "number" && typeColors?.number) {
|
|
348
|
+
return typeColors.number;
|
|
349
|
+
}
|
|
350
|
+
if (typeof cell === "string" && typeColors?.string) {
|
|
351
|
+
return typeColors.string;
|
|
352
|
+
}
|
|
353
|
+
if (typeof cell === "boolean" && typeColors?.boolean) {
|
|
354
|
+
return typeColors.boolean;
|
|
355
|
+
}
|
|
356
|
+
if (typeof cell === "object" && cell !== null && typeColors?.object) {
|
|
357
|
+
return typeColors.object;
|
|
358
|
+
}
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Prepares the title string for the table, including justification and truncation.
|
|
363
|
+
*
|
|
364
|
+
* @param title - The Title object.
|
|
365
|
+
* @param width - The total width of the table.
|
|
366
|
+
* @returns The formatted title string.
|
|
367
|
+
*/
|
|
368
|
+
title_prepare(title, width) {
|
|
369
|
+
let { title: titleText, justification = "left" } = title;
|
|
370
|
+
const contentWidth = width - 4; // Accounting for border characters
|
|
371
|
+
if (titleText.length > contentWidth) {
|
|
372
|
+
titleText = titleText.slice(0, contentWidth - 3) + "...";
|
|
373
|
+
}
|
|
374
|
+
switch (justification) {
|
|
375
|
+
case "right":
|
|
376
|
+
titleText = titleText.padStart(contentWidth);
|
|
377
|
+
break;
|
|
378
|
+
case "center":
|
|
379
|
+
const padding = Math.floor((contentWidth - titleText.length) / 2);
|
|
380
|
+
titleText =
|
|
381
|
+
" ".repeat(padding) +
|
|
382
|
+
titleText +
|
|
383
|
+
" ".repeat(contentWidth - titleText.length - padding);
|
|
384
|
+
break;
|
|
385
|
+
case "left":
|
|
386
|
+
default:
|
|
387
|
+
titleText = titleText.padEnd(contentWidth);
|
|
388
|
+
}
|
|
389
|
+
return titleText;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Prepares the `table` library configuration object.
|
|
393
|
+
*
|
|
394
|
+
* @param hasTitle - Whether the table has a title (affects border drawing).
|
|
395
|
+
* @param options - Table options to check for borderless mode.
|
|
396
|
+
* @returns The `TableUserConfig` object.
|
|
397
|
+
*/
|
|
398
|
+
tableConfig_prepare(hasTitle, options) {
|
|
399
|
+
if (options.borderless) {
|
|
400
|
+
return {
|
|
401
|
+
border: getBorderCharacters("void"),
|
|
402
|
+
drawHorizontalLine: () => false,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const borderCharacters = getBorderCharacters("norc");
|
|
406
|
+
const customBorderCharacters = hasTitle
|
|
407
|
+
? {
|
|
408
|
+
...borderCharacters,
|
|
409
|
+
topLeft: "├",
|
|
410
|
+
topRight: "┤",
|
|
411
|
+
}
|
|
412
|
+
: borderCharacters;
|
|
413
|
+
return {
|
|
414
|
+
border: customBorderCharacters,
|
|
415
|
+
drawHorizontalLine: (index, size) => index === 0 || index === 1 || index === size,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Calculates the visible length of a string, accounting for ANSI escape codes.
|
|
420
|
+
*
|
|
421
|
+
* @param str - The string to measure.
|
|
422
|
+
* @returns The visible length of the string.
|
|
423
|
+
*/
|
|
424
|
+
visibleLength_get(str) {
|
|
425
|
+
return str.replace(/\u001b\[[0-9;]*m/g, "").length;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Safely converts any value to a string.
|
|
429
|
+
*
|
|
430
|
+
* @param value - The value to convert.
|
|
431
|
+
* @returns The string representation of the value.
|
|
432
|
+
*/
|
|
433
|
+
string_safeConvert(value) {
|
|
434
|
+
if (value === null || value === undefined) {
|
|
435
|
+
return "";
|
|
436
|
+
}
|
|
437
|
+
if (typeof value === "string") {
|
|
438
|
+
return value;
|
|
439
|
+
}
|
|
440
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
441
|
+
return value.toString();
|
|
442
|
+
}
|
|
443
|
+
if (typeof value === "object") {
|
|
444
|
+
return JSON.stringify(value);
|
|
445
|
+
}
|
|
446
|
+
return String(value);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Justifies text within a given width.
|
|
450
|
+
*
|
|
451
|
+
* @param text - The text to justify.
|
|
452
|
+
* @param width - The total width for justification.
|
|
453
|
+
* @param justification - The justification type ('left', 'center', 'right').
|
|
454
|
+
* @returns The justified text string.
|
|
455
|
+
*/
|
|
456
|
+
text_justify(text, width, justification) {
|
|
457
|
+
const visibleLength = this.visibleLength_get(text);
|
|
458
|
+
const paddingLength = Math.max(0, width - visibleLength);
|
|
459
|
+
switch (justification) {
|
|
460
|
+
case "right":
|
|
461
|
+
return " ".repeat(paddingLength) + text;
|
|
462
|
+
case "center":
|
|
463
|
+
const leftPad = Math.floor(paddingLength / 2);
|
|
464
|
+
const rightPad = paddingLength - leftPad;
|
|
465
|
+
return " ".repeat(leftPad) + text + " ".repeat(rightPad);
|
|
466
|
+
case "left":
|
|
467
|
+
default:
|
|
468
|
+
return text + " ".repeat(paddingLength);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
clear() {
|
|
472
|
+
console.clear();
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Shared Screen singleton for terminal rendering.
|
|
477
|
+
*/
|
|
478
|
+
export const screen = new Screen();
|