@outfitter/cli 0.1.0-rc.1 → 0.1.0-rc.3
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 +21 -32
- package/dist/actions.js +1 -1
- package/dist/borders/index.d.ts +3 -0
- package/dist/borders/index.js +13 -0
- package/dist/box/index.d.ts +4 -0
- package/dist/box/index.js +13 -0
- package/dist/cli.d.ts +2 -103
- package/dist/cli.js +4 -51
- package/dist/colors/index.d.ts +3 -0
- package/dist/colors/index.js +18 -0
- package/dist/command.d.ts +3 -37
- package/dist/command.js +5 -1
- package/dist/demo/index.d.ts +78 -0
- package/dist/demo/index.js +148 -0
- package/dist/demo/registry.d.ts +7 -0
- package/dist/demo/registry.js +28 -0
- package/dist/demo/renderers/borders.d.ts +7 -0
- package/dist/demo/renderers/borders.js +17 -0
- package/dist/demo/renderers/box.d.ts +7 -0
- package/dist/demo/renderers/box.js +18 -0
- package/dist/demo/renderers/colors.d.ts +7 -0
- package/dist/demo/renderers/colors.js +18 -0
- package/dist/demo/renderers/indicators.d.ts +7 -0
- package/dist/demo/renderers/indicators.js +17 -0
- package/dist/demo/renderers/list.d.ts +7 -0
- package/dist/demo/renderers/list.js +19 -0
- package/dist/demo/renderers/markdown.d.ts +7 -0
- package/dist/demo/renderers/markdown.js +18 -0
- package/dist/demo/renderers/progress.d.ts +7 -0
- package/dist/demo/renderers/progress.js +17 -0
- package/dist/demo/renderers/spinner.d.ts +7 -0
- package/dist/demo/renderers/spinner.js +19 -0
- package/dist/demo/renderers/table.d.ts +7 -0
- package/dist/demo/renderers/table.js +19 -0
- package/dist/demo/renderers/text.d.ts +7 -0
- package/dist/demo/renderers/text.js +16 -0
- package/dist/demo/renderers/tree.d.ts +7 -0
- package/dist/demo/renderers/tree.js +18 -0
- package/dist/demo/section.d.ts +5 -0
- package/dist/demo/section.js +23 -0
- package/dist/demo/templates.d.ts +4 -0
- package/dist/demo/templates.js +10 -0
- package/dist/demo/types.d.ts +3 -0
- package/dist/demo/types.js +8 -0
- package/dist/index.d.ts +5 -607
- package/dist/index.js +10 -44
- package/dist/input.d.ts +9 -123
- package/dist/input.js +2 -3
- package/dist/list/index.d.ts +3 -0
- package/dist/list/index.js +9 -0
- package/dist/output.d.ts +2 -68
- package/dist/output.js +4 -150
- package/dist/pagination.d.ts +1 -34
- package/dist/pagination.js +1 -1
- package/dist/preset/full.d.ts +14 -0
- package/dist/preset/full.js +41 -0
- package/dist/preset/standard.d.ts +11 -0
- package/dist/preset/standard.js +30 -0
- package/dist/prompt/confirm.d.ts +4 -0
- package/dist/prompt/confirm.js +9 -0
- package/dist/prompt/group.d.ts +4 -0
- package/dist/prompt/group.js +9 -0
- package/dist/prompt/index.d.ts +7 -0
- package/dist/prompt/index.js +32 -0
- package/dist/prompt/select.d.ts +4 -0
- package/dist/prompt/select.js +11 -0
- package/dist/prompt/text.d.ts +4 -0
- package/dist/prompt/text.js +11 -0
- package/dist/prompt/types.d.ts +3 -0
- package/dist/prompt/types.js +8 -0
- package/dist/prompt/validators.d.ts +2 -0
- package/dist/prompt/validators.js +8 -0
- package/dist/render/borders.d.ts +2 -0
- package/dist/render/borders.js +15 -0
- package/dist/render/box.d.ts +3 -0
- package/dist/render/box.js +23 -0
- package/dist/render/colors.d.ts +2 -0
- package/dist/render/colors.js +20 -0
- package/dist/render/date.d.ts +2 -0
- package/dist/render/date.js +12 -0
- package/dist/render/format-relative.d.ts +2 -0
- package/dist/render/format-relative.js +8 -0
- package/dist/render/format.d.ts +2 -0
- package/dist/render/format.js +10 -0
- package/dist/render/heading.d.ts +3 -0
- package/dist/render/heading.js +14 -0
- package/dist/render/index.d.ts +32 -0
- package/dist/render/index.js +235 -0
- package/dist/render/indicators.d.ts +2 -0
- package/dist/render/indicators.js +14 -0
- package/dist/render/json.d.ts +2 -0
- package/dist/render/json.js +10 -0
- package/dist/render/layout.d.ts +5 -0
- package/dist/render/layout.js +25 -0
- package/dist/render/list.d.ts +2 -0
- package/dist/render/list.js +8 -0
- package/dist/render/markdown.d.ts +2 -0
- package/dist/render/markdown.js +10 -0
- package/dist/render/progress.d.ts +2 -0
- package/dist/render/progress.js +8 -0
- package/dist/render/separator.d.ts +3 -0
- package/dist/render/separator.js +14 -0
- package/dist/render/shapes.d.ts +2 -0
- package/dist/render/shapes.js +35 -0
- package/dist/render/spinner.d.ts +2 -0
- package/dist/render/spinner.js +12 -0
- package/dist/render/stack.d.ts +3 -0
- package/dist/render/stack.js +38 -0
- package/dist/render/table.d.ts +3 -0
- package/dist/render/table.js +12 -0
- package/dist/render/text.d.ts +2 -0
- package/dist/render/text.js +27 -0
- package/dist/render/tree.d.ts +2 -0
- package/dist/render/tree.js +10 -0
- package/dist/render/types.d.ts +2 -0
- package/dist/render/types.js +1 -0
- package/dist/shared/@outfitter/cli-0ggcy7fa.js +20 -0
- package/dist/shared/@outfitter/cli-0psys2vm.js +7 -0
- package/dist/shared/@outfitter/cli-1bghjef6.js +352 -0
- package/dist/shared/@outfitter/cli-1kwbnt86.d.ts +45 -0
- package/dist/shared/@outfitter/cli-2g8bx1aq.d.ts +50 -0
- package/dist/shared/@outfitter/cli-33e97cjs.d.ts +42 -0
- package/dist/shared/@outfitter/cli-34fqr7bp.js +37 -0
- package/dist/shared/@outfitter/cli-3b7ed3rm.d.ts +97 -0
- package/dist/shared/@outfitter/cli-3dxmmy4c.d.ts +20 -0
- package/dist/shared/@outfitter/cli-3f12z5kf.d.ts +83 -0
- package/dist/shared/@outfitter/cli-3hp8qwx3.js +11 -0
- package/dist/shared/@outfitter/cli-3t2zaenc.d.ts +59 -0
- package/dist/shared/@outfitter/cli-4cb5g831.d.ts +147 -0
- package/dist/shared/@outfitter/cli-4w2a1rfy.d.ts +23 -0
- package/dist/shared/@outfitter/cli-4x6pqnez.js +20 -0
- package/dist/shared/@outfitter/cli-671sxkhj.js +146 -0
- package/dist/shared/@outfitter/cli-6bztk73z.d.ts +51 -0
- package/dist/shared/@outfitter/cli-6fxffp8k.js +1 -0
- package/dist/shared/@outfitter/cli-6j9qynm8.js +118 -0
- package/dist/shared/@outfitter/cli-6m988kh0.d.ts +61 -0
- package/dist/shared/@outfitter/cli-72kg550t.d.ts +53 -0
- package/dist/shared/@outfitter/cli-74ba31gz.js +134 -0
- package/dist/shared/@outfitter/cli-7gnrb8cr.js +214 -0
- package/dist/shared/@outfitter/cli-7na6p4fs.d.ts +59 -0
- package/dist/shared/@outfitter/cli-7nm6edvh.d.ts +17 -0
- package/dist/shared/@outfitter/cli-85fg2vr5.js +123 -0
- package/dist/shared/@outfitter/cli-8a8xrzhy.js +20 -0
- package/dist/shared/@outfitter/cli-8aa1vhdn.d.ts +119 -0
- package/dist/shared/@outfitter/cli-8bwaw3pz.js +7 -0
- package/dist/shared/@outfitter/cli-8j5k6mr3.js +71 -0
- package/dist/shared/@outfitter/cli-8rx4g3s5.d.ts +41 -0
- package/dist/shared/@outfitter/cli-8xsmsbbd.d.ts +223 -0
- package/dist/shared/@outfitter/cli-96b2p4td.d.ts +56 -0
- package/dist/shared/@outfitter/cli-9khk3cbq.d.ts +190 -0
- package/dist/shared/@outfitter/cli-9mtjjykw.js +67 -0
- package/dist/shared/@outfitter/cli-9nbyj2bt.js +128 -0
- package/dist/shared/@outfitter/cli-a4q87517.d.ts +64 -0
- package/dist/shared/@outfitter/cli-afhjqmg3.js +63 -0
- package/dist/shared/@outfitter/cli-an9j0h80.js +117 -0
- package/dist/shared/@outfitter/cli-ay411nbr.js +122 -0
- package/dist/shared/@outfitter/cli-b0tzqgnf.d.ts +132 -0
- package/dist/shared/@outfitter/cli-b5c2k0d7.js +39 -0
- package/dist/shared/@outfitter/cli-b5epywry.js +1 -0
- package/dist/shared/@outfitter/cli-bc17qeh2.js +19 -0
- package/dist/shared/@outfitter/cli-bcmcaz1b.js +23 -0
- package/dist/shared/@outfitter/cli-bf3vma4q.js +61 -0
- package/dist/shared/@outfitter/cli-c8q4f71g.js +144 -0
- package/dist/shared/@outfitter/cli-c9knfqn5.d.ts +30 -0
- package/dist/shared/@outfitter/cli-cf1xexgn.d.ts +53 -0
- package/dist/shared/@outfitter/cli-cf2s94s1.d.ts +42 -0
- package/dist/shared/@outfitter/cli-cs45xd6q.js +59 -0
- package/dist/shared/@outfitter/cli-d7jpshq5.d.ts +128 -0
- package/dist/shared/@outfitter/cli-d9ad0rqj.js +75 -0
- package/dist/shared/@outfitter/cli-daw296mv.js +61 -0
- package/dist/shared/@outfitter/cli-e5ms1y0x.d.ts +91 -0
- package/dist/shared/@outfitter/cli-e73v3qqy.d.ts +93 -0
- package/dist/shared/@outfitter/cli-efy6jfcj.js +52 -0
- package/dist/shared/@outfitter/cli-en6zn6sj.js +1 -0
- package/dist/shared/@outfitter/cli-ep2cvtk8.js +48 -0
- package/dist/shared/@outfitter/cli-evx7qcp1.d.ts +300 -0
- package/dist/shared/@outfitter/cli-f75h8e94.js +7 -0
- package/dist/shared/@outfitter/cli-fakncnjp.d.ts +106 -0
- package/dist/shared/@outfitter/cli-feb5j90n.js +94 -0
- package/dist/shared/@outfitter/cli-h20jc0bs.d.ts +66 -0
- package/dist/shared/@outfitter/cli-hnpbqmc8.d.ts +328 -0
- package/dist/shared/@outfitter/cli-j19a91ck.js +30 -0
- package/dist/shared/@outfitter/cli-j4n8gaf3.js +95 -0
- package/dist/shared/@outfitter/cli-jejfypgf.js +85 -0
- package/dist/shared/@outfitter/cli-jhcdwvpn.js +135 -0
- package/dist/shared/@outfitter/cli-jjemfdta.js +85 -0
- package/dist/shared/@outfitter/cli-kc84wmch.js +267 -0
- package/dist/shared/@outfitter/cli-ktqme80d.js +7 -0
- package/dist/shared/@outfitter/cli-mhamvbty.d.ts +34 -0
- package/dist/shared/@outfitter/cli-mq0jp15z.js +1 -0
- package/dist/shared/@outfitter/cli-mymyavvj.d.ts +26 -0
- package/dist/shared/@outfitter/cli-n17gt1dz.js +19 -0
- package/dist/shared/@outfitter/cli-n9dbh0hp.js +51 -0
- package/dist/shared/@outfitter/cli-nvvc92c8.js +128 -0
- package/dist/shared/@outfitter/cli-p1m5dhrs.js +169 -0
- package/dist/shared/@outfitter/cli-p38sfxyk.js +25 -0
- package/dist/shared/@outfitter/cli-p3dqm1vd.js +22 -0
- package/dist/shared/@outfitter/cli-p9j1phge.js +20 -0
- package/dist/shared/@outfitter/cli-pkxmzavm.js +62 -0
- package/dist/shared/@outfitter/cli-q8r6jarq.d.ts +24 -0
- package/dist/shared/@outfitter/cli-qj83y5wj.d.ts +71 -0
- package/dist/shared/@outfitter/cli-qjfc3j11.d.ts +112 -0
- package/dist/shared/@outfitter/cli-qp4cbhqr.js +70 -0
- package/dist/shared/@outfitter/cli-s0kkx9m1.d.ts +164 -0
- package/dist/shared/@outfitter/cli-snxj55n6.js +43 -0
- package/dist/shared/@outfitter/cli-swwxvjvm.d.ts +24 -0
- package/dist/shared/@outfitter/cli-sx67mmfx.d.ts +98 -0
- package/dist/shared/@outfitter/cli-tarpsa8a.js +30 -0
- package/dist/shared/@outfitter/cli-thvzhjd1.js +126 -0
- package/dist/shared/@outfitter/cli-tqewy503.d.ts +36 -0
- package/dist/shared/@outfitter/cli-ttt7r0j7.d.ts +253 -0
- package/dist/shared/@outfitter/cli-tvw1xrdj.js +20 -0
- package/dist/shared/@outfitter/cli-v1tzwxkt.js +32 -0
- package/dist/shared/@outfitter/cli-vd60dj65.js +1 -0
- package/dist/shared/@outfitter/cli-vp88gxev.js +279 -0
- package/dist/shared/@outfitter/cli-vstbkzky.d.ts +74 -0
- package/dist/shared/@outfitter/cli-vtg0sqk2.d.ts +54 -0
- package/dist/shared/@outfitter/cli-w5y3xepp.js +20 -0
- package/dist/shared/@outfitter/cli-x4cavvc0.js +1 -0
- package/dist/shared/@outfitter/cli-xep6v2c0.js +52 -0
- package/dist/shared/@outfitter/cli-xg5y5fhk.js +86 -0
- package/dist/shared/@outfitter/cli-xsaheemc.d.ts +248 -0
- package/dist/shared/@outfitter/cli-xvqtqjxk.js +82 -0
- package/dist/shared/@outfitter/cli-y25tt8nc.d.ts +48 -0
- package/dist/shared/@outfitter/cli-zact3325.js +152 -0
- package/dist/shared/@outfitter/cli-zx598p8q.d.ts +26 -0
- package/dist/streaming/ansi.d.ts +2 -0
- package/dist/streaming/ansi.js +8 -0
- package/dist/streaming/index.d.ts +4 -0
- package/dist/streaming/index.js +17 -0
- package/dist/streaming/spinner.d.ts +3 -0
- package/dist/streaming/spinner.js +10 -0
- package/dist/streaming/writer.d.ts +2 -0
- package/dist/streaming/writer.js +9 -0
- package/dist/table/index.d.ts +4 -0
- package/dist/table/index.js +13 -0
- package/dist/terminal/detection.d.ts +2 -0
- package/dist/terminal/detection.js +23 -0
- package/dist/terminal/index.d.ts +2 -0
- package/dist/terminal/index.js +24 -0
- package/dist/theme/context.d.ts +9 -0
- package/dist/theme/context.js +14 -0
- package/dist/theme/create.d.ts +8 -0
- package/dist/theme/create.js +12 -0
- package/dist/theme/index.d.ts +17 -0
- package/dist/theme/index.js +42 -0
- package/dist/theme/presets/bold.d.ts +8 -0
- package/dist/theme/presets/bold.js +12 -0
- package/dist/theme/presets/default.d.ts +8 -0
- package/dist/theme/presets/default.js +11 -0
- package/dist/theme/presets/index.d.ts +12 -0
- package/dist/theme/presets/index.js +24 -0
- package/dist/theme/presets/minimal.d.ts +8 -0
- package/dist/theme/presets/minimal.js +12 -0
- package/dist/theme/presets/rounded.d.ts +8 -0
- package/dist/theme/presets/rounded.js +12 -0
- package/dist/theme/resolve.d.ts +8 -0
- package/dist/theme/resolve.js +11 -0
- package/dist/theme/types.d.ts +7 -0
- package/dist/theme/types.js +1 -0
- package/dist/tree/index.d.ts +3 -0
- package/dist/tree/index.js +11 -0
- package/dist/types.d.ts +1 -252
- package/dist/types.js +1 -1
- package/package.json +228 -20
- package/dist/shared/@outfitter/cli-4yy82cmp.js +0 -20
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { BoxOptions } from "./cli-8xsmsbbd";
|
|
2
|
+
import { LayoutContext, WidthMode } from "./cli-2g8bx1aq";
|
|
3
|
+
/**
|
|
4
|
+
* Gets the current terminal width.
|
|
5
|
+
*
|
|
6
|
+
* Returns `process.stdout.columns` if available, otherwise falls back to 80
|
|
7
|
+
* (standard terminal width).
|
|
8
|
+
*
|
|
9
|
+
* @returns Terminal width in characters
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { getTerminalWidth } from "@outfitter/cli/render";
|
|
14
|
+
*
|
|
15
|
+
* const width = getTerminalWidth();
|
|
16
|
+
* console.log(`Terminal is ${width} columns wide`);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function getTerminalWidth(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Calculates box overhead (borders + padding) for each axis.
|
|
22
|
+
*
|
|
23
|
+
* Returns the total character/line count consumed by borders and padding,
|
|
24
|
+
* separate from content.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Box options (padding, borders)
|
|
27
|
+
* @returns Object with horizontal and vertical overhead
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { getBoxOverhead } from "@outfitter/cli/render";
|
|
32
|
+
*
|
|
33
|
+
* const overhead = getBoxOverhead({ padding: 1, border: "single" });
|
|
34
|
+
* // { horizontal: 4, vertical: 2 }
|
|
35
|
+
* // horizontal: left border (1) + left padding (1) + right padding (1) + right border (1)
|
|
36
|
+
* // vertical: top border (1) + bottom border (1)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function getBoxOverhead(options: BoxOptions): {
|
|
40
|
+
horizontal: number;
|
|
41
|
+
vertical: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Calculates available content width inside a box.
|
|
45
|
+
*
|
|
46
|
+
* Accounts for borders and padding to determine how much space remains
|
|
47
|
+
* for content. Use this to size nested components appropriately.
|
|
48
|
+
*
|
|
49
|
+
* @param options - Box options (width, padding, borders)
|
|
50
|
+
* @returns Available width in characters for content
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { getContentWidth, createBox, renderProgress } from "@outfitter/cli/render";
|
|
55
|
+
*
|
|
56
|
+
* const boxOpts = { width: 40, padding: 1, border: "single" };
|
|
57
|
+
* const available = getContentWidth(boxOpts); // → 36
|
|
58
|
+
*
|
|
59
|
+
* const progress = renderProgress(0.5, { width: available });
|
|
60
|
+
* const box = createBox(progress, boxOpts);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function getContentWidth(options: BoxOptions): number;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves a width mode to a concrete character width.
|
|
66
|
+
*
|
|
67
|
+
* Width modes allow flexible sizing relative to terminal or container:
|
|
68
|
+
* - `"text"` → 0 (content-sized, no constraint)
|
|
69
|
+
* - `"full"` → terminal width
|
|
70
|
+
* - `"container"` → container width (requires context)
|
|
71
|
+
* - `number` → fixed width
|
|
72
|
+
* - `"${number}%"` → percentage of container/terminal
|
|
73
|
+
*
|
|
74
|
+
* @param mode - Width specification
|
|
75
|
+
* @param ctx - Layout context for container-relative modes
|
|
76
|
+
* @returns Resolved width in characters
|
|
77
|
+
* @throws Error if "container" mode used without context
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { resolveWidth, createLayoutContext } from "@outfitter/cli/render";
|
|
82
|
+
*
|
|
83
|
+
* resolveWidth("full"); // → 120 (terminal width)
|
|
84
|
+
* resolveWidth(50); // → 50
|
|
85
|
+
* resolveWidth("50%"); // → 60 (half of terminal)
|
|
86
|
+
*
|
|
87
|
+
* const ctx = createLayoutContext({ width: 80, padding: 1 });
|
|
88
|
+
* resolveWidth("50%", ctx); // → 38 (half of context width)
|
|
89
|
+
* resolveWidth("container", ctx); // → 76 (context width)
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function resolveWidth(mode: WidthMode, ctx?: LayoutContext): number;
|
|
93
|
+
/**
|
|
94
|
+
* Creates a layout context from box options.
|
|
95
|
+
*
|
|
96
|
+
* Layout contexts propagate width information through nested components,
|
|
97
|
+
* enabling relative sizing like `"50%"` or `"container"`.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Box options defining the container
|
|
100
|
+
* @param parent - Parent context for chained calculations
|
|
101
|
+
* @returns New layout context with calculated content width
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { createLayoutContext, resolveWidth, createBox } from "@outfitter/cli/render";
|
|
106
|
+
*
|
|
107
|
+
* // Outer container
|
|
108
|
+
* const outerOpts = { width: 80, padding: 1 };
|
|
109
|
+
* const outerCtx = createLayoutContext(outerOpts);
|
|
110
|
+
* // outerCtx.width = 76 (80 - 4 overhead)
|
|
111
|
+
*
|
|
112
|
+
* // Nested component at 50% width
|
|
113
|
+
* const innerWidth = resolveWidth("50%", outerCtx);
|
|
114
|
+
* const innerOpts = { width: innerWidth, padding: 1 };
|
|
115
|
+
* const innerCtx = createLayoutContext(innerOpts, outerCtx);
|
|
116
|
+
* // innerCtx.width = 34 (38 - 4 overhead)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function createLayoutContext(options: BoxOptions, parent?: LayoutContext): LayoutContext;
|
|
120
|
+
/**
|
|
121
|
+
* Vertical alignment for horizontal layout.
|
|
122
|
+
*/
|
|
123
|
+
type Alignment = "top" | "center" | "bottom";
|
|
124
|
+
/**
|
|
125
|
+
* Options for horizontal layout.
|
|
126
|
+
*/
|
|
127
|
+
interface HorizontalLayoutOptions {
|
|
128
|
+
/** Gap (in characters) between blocks */
|
|
129
|
+
gap?: number;
|
|
130
|
+
/** Vertical alignment of blocks */
|
|
131
|
+
align?: Alignment;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Options for vertical layout.
|
|
135
|
+
*/
|
|
136
|
+
interface VerticalLayoutOptions {
|
|
137
|
+
/** Gap (in lines) between blocks */
|
|
138
|
+
gap?: number;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Joins multiple text blocks horizontally (side by side).
|
|
142
|
+
*
|
|
143
|
+
* Handles blocks of different heights by aligning them according
|
|
144
|
+
* to the `align` option. Blocks are padded to maintain alignment.
|
|
145
|
+
*
|
|
146
|
+
* @param blocks - Array of text blocks to join
|
|
147
|
+
* @param options - Layout options
|
|
148
|
+
* @returns Combined string with blocks side by side
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import { joinHorizontal } from "@outfitter/cli/render";
|
|
153
|
+
* import { renderBox } from "@outfitter/cli/render";
|
|
154
|
+
*
|
|
155
|
+
* const left = renderBox({ content: "Left", borderStyle: "single" });
|
|
156
|
+
* const right = renderBox({ content: "Right", borderStyle: "single" });
|
|
157
|
+
*
|
|
158
|
+
* console.log(joinHorizontal([left, right], { gap: 2 }));
|
|
159
|
+
* // ┌──────┐ ┌───────┐
|
|
160
|
+
* // │ Left │ │ Right │
|
|
161
|
+
* // └──────┘ └───────┘
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function joinHorizontal(blocks: string[], options?: HorizontalLayoutOptions): string;
|
|
165
|
+
/**
|
|
166
|
+
* Joins multiple text blocks vertically (stacked).
|
|
167
|
+
*
|
|
168
|
+
* @param blocks - Array of text blocks to stack
|
|
169
|
+
* @param options - Layout options
|
|
170
|
+
* @returns Combined string with blocks stacked
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* import { joinVertical, renderHeading, renderSeparator } from "@outfitter/cli/render";
|
|
175
|
+
*
|
|
176
|
+
* const heading = renderHeading("Section Title");
|
|
177
|
+
* const separator = renderSeparator({ width: 20 });
|
|
178
|
+
* const content = "Some content here.";
|
|
179
|
+
*
|
|
180
|
+
* console.log(joinVertical([heading, separator, content], { gap: 1 }));
|
|
181
|
+
* // SECTION TITLE
|
|
182
|
+
* // =============
|
|
183
|
+
* //
|
|
184
|
+
* // ────────────────────
|
|
185
|
+
* //
|
|
186
|
+
* // Some content here.
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
declare function joinVertical(blocks: string[], options?: VerticalLayoutOptions): string;
|
|
190
|
+
export { getTerminalWidth, getBoxOverhead, getContentWidth, resolveWidth, createLayoutContext, Alignment, HorizontalLayoutOptions, VerticalLayoutOptions, joinHorizontal, joinVertical };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
SPINNERS,
|
|
4
|
+
getSpinnerFrame,
|
|
5
|
+
renderSpinner
|
|
6
|
+
} from "./cli-n9dbh0hp.js";
|
|
7
|
+
import {
|
|
8
|
+
SPINNER_STYLE_META,
|
|
9
|
+
getSpinnerStyles
|
|
10
|
+
} from "./cli-kc84wmch.js";
|
|
11
|
+
import {
|
|
12
|
+
getExample
|
|
13
|
+
} from "./cli-xep6v2c0.js";
|
|
14
|
+
import {
|
|
15
|
+
demoSection
|
|
16
|
+
} from "./cli-34fqr7bp.js";
|
|
17
|
+
|
|
18
|
+
// packages/cli/src/demo/renderers/spinner.ts
|
|
19
|
+
function renderSpinnerDemo(config, theme) {
|
|
20
|
+
const showCode = config.showCode ?? true;
|
|
21
|
+
const showDescriptions = config.showDescriptions ?? true;
|
|
22
|
+
const lines = [];
|
|
23
|
+
lines.push(demoSection("Spinner Styles"));
|
|
24
|
+
lines.push("");
|
|
25
|
+
if (showCode) {
|
|
26
|
+
lines.push('import { renderSpinner, SPINNERS } from "@outfitter/cli/render";');
|
|
27
|
+
lines.push("");
|
|
28
|
+
}
|
|
29
|
+
const message = getExample("spinnerMessage", config.examples);
|
|
30
|
+
const styles = getSpinnerStyles();
|
|
31
|
+
for (const style of styles) {
|
|
32
|
+
const meta = SPINNER_STYLE_META[style];
|
|
33
|
+
const spinner = SPINNERS[style];
|
|
34
|
+
lines.push(`${meta.label.toUpperCase()} (${style})`);
|
|
35
|
+
if (showDescriptions) {
|
|
36
|
+
lines.push(theme.muted(meta.description));
|
|
37
|
+
}
|
|
38
|
+
const frameDisplay = spinner.frames.join(" ");
|
|
39
|
+
lines.push(` Frames: ${frameDisplay}`);
|
|
40
|
+
lines.push(` Interval: ${spinner.interval}ms`);
|
|
41
|
+
const output = renderSpinner(style, message);
|
|
42
|
+
lines.push(` Example: ${output}`);
|
|
43
|
+
lines.push("");
|
|
44
|
+
}
|
|
45
|
+
lines.push(demoSection("Usage"));
|
|
46
|
+
lines.push("");
|
|
47
|
+
if (showCode) {
|
|
48
|
+
lines.push("// Static render (for logs/non-TTY)");
|
|
49
|
+
lines.push(`renderSpinner("dots", "${message}");`);
|
|
50
|
+
lines.push("");
|
|
51
|
+
lines.push("// Get frame at specific time");
|
|
52
|
+
lines.push('getSpinnerFrame("dots", 0); // First frame');
|
|
53
|
+
lines.push('getSpinnerFrame("dots", 160); // Third frame');
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
56
|
+
lines.push("Frame progression (dots style):");
|
|
57
|
+
const dotSpinner = SPINNERS.dots;
|
|
58
|
+
for (let i = 0;i < Math.min(5, dotSpinner.frames.length); i++) {
|
|
59
|
+
const elapsed = i * dotSpinner.interval;
|
|
60
|
+
const frame = getSpinnerFrame("dots", elapsed);
|
|
61
|
+
lines.push(` ${elapsed}ms \u2192 ${frame}`);
|
|
62
|
+
}
|
|
63
|
+
return lines.join(`
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { renderSpinnerDemo };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
init_detection,
|
|
4
|
+
resolveColorEnv,
|
|
5
|
+
supportsColor
|
|
6
|
+
} from "./cli-d9ad0rqj.js";
|
|
7
|
+
import {
|
|
8
|
+
__esm
|
|
9
|
+
} from "./cli-v1tzwxkt.js";
|
|
10
|
+
|
|
11
|
+
// packages/cli/src/render/colors.ts
|
|
12
|
+
function createTheme() {
|
|
13
|
+
const colorEnabled = supportsColor();
|
|
14
|
+
const colorFn = (ansiCode) => (text) => {
|
|
15
|
+
if (!colorEnabled) {
|
|
16
|
+
return text;
|
|
17
|
+
}
|
|
18
|
+
return `${ansiCode}${text}${ANSI.reset}`;
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
success: colorFn(ANSI.green),
|
|
22
|
+
warning: colorFn(ANSI.yellow),
|
|
23
|
+
error: colorFn(ANSI.red),
|
|
24
|
+
info: colorFn(ANSI.blue),
|
|
25
|
+
primary: colorFn(""),
|
|
26
|
+
secondary: colorFn(ANSI.gray),
|
|
27
|
+
muted: colorFn(ANSI.dim),
|
|
28
|
+
accent: colorFn(ANSI.cyan),
|
|
29
|
+
highlight: colorFn(ANSI.bold),
|
|
30
|
+
link: colorFn(`${ANSI.cyan}${ANSI.underline}`),
|
|
31
|
+
destructive: colorFn(ANSI.brightRed),
|
|
32
|
+
subtle: colorFn(`${ANSI.dim}${ANSI.gray}`),
|
|
33
|
+
bold: colorFn(ANSI.bold),
|
|
34
|
+
italic: colorFn(ANSI.italic),
|
|
35
|
+
underline: colorFn(ANSI.underline),
|
|
36
|
+
dim: colorFn(ANSI.dim)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function resolveTokenColorEnabled(options) {
|
|
40
|
+
if (options?.colorLevel === 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (options?.forceColor === true) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (options?.colorLevel !== undefined) {
|
|
47
|
+
return options.colorLevel > 0;
|
|
48
|
+
}
|
|
49
|
+
const env = resolveColorEnv({ forceColorFirst: true });
|
|
50
|
+
if (env !== undefined) {
|
|
51
|
+
return env;
|
|
52
|
+
}
|
|
53
|
+
return process.stdout.isTTY ?? false;
|
|
54
|
+
}
|
|
55
|
+
function createTokens(options) {
|
|
56
|
+
const colorEnabled = resolveTokenColorEnabled(options);
|
|
57
|
+
if (!colorEnabled) {
|
|
58
|
+
return {
|
|
59
|
+
success: "",
|
|
60
|
+
warning: "",
|
|
61
|
+
error: "",
|
|
62
|
+
info: "",
|
|
63
|
+
primary: "",
|
|
64
|
+
secondary: "",
|
|
65
|
+
muted: "",
|
|
66
|
+
accent: "",
|
|
67
|
+
highlight: "",
|
|
68
|
+
link: "",
|
|
69
|
+
destructive: "",
|
|
70
|
+
subtle: "",
|
|
71
|
+
bold: "",
|
|
72
|
+
italic: "",
|
|
73
|
+
underline: "",
|
|
74
|
+
dim: ""
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
success: ANSI.green,
|
|
79
|
+
warning: ANSI.yellow,
|
|
80
|
+
error: ANSI.red,
|
|
81
|
+
info: ANSI.blue,
|
|
82
|
+
primary: "",
|
|
83
|
+
secondary: ANSI.gray,
|
|
84
|
+
muted: ANSI.dim,
|
|
85
|
+
accent: ANSI.cyan,
|
|
86
|
+
highlight: ANSI.bold,
|
|
87
|
+
link: `${ANSI.cyan}${ANSI.underline}`,
|
|
88
|
+
destructive: ANSI.brightRed,
|
|
89
|
+
subtle: `${ANSI.dim}${ANSI.gray}`,
|
|
90
|
+
bold: ANSI.bold,
|
|
91
|
+
italic: ANSI.italic,
|
|
92
|
+
underline: ANSI.underline,
|
|
93
|
+
dim: ANSI.dim
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function applyColor(text, color) {
|
|
97
|
+
if (!supportsColor()) {
|
|
98
|
+
return text;
|
|
99
|
+
}
|
|
100
|
+
const ansiCode = ANSI[color];
|
|
101
|
+
return `${ansiCode}${text}${ANSI.reset}`;
|
|
102
|
+
}
|
|
103
|
+
var ANSI;
|
|
104
|
+
var init_colors = __esm(() => {
|
|
105
|
+
init_detection();
|
|
106
|
+
ANSI = {
|
|
107
|
+
reset: "\x1B[0m",
|
|
108
|
+
bold: "\x1B[1m",
|
|
109
|
+
dim: "\x1B[2m",
|
|
110
|
+
italic: "\x1B[3m",
|
|
111
|
+
underline: "\x1B[4m",
|
|
112
|
+
green: "\x1B[32m",
|
|
113
|
+
yellow: "\x1B[33m",
|
|
114
|
+
red: "\x1B[31m",
|
|
115
|
+
blue: "\x1B[34m",
|
|
116
|
+
cyan: "\x1B[36m",
|
|
117
|
+
magenta: "\x1B[35m",
|
|
118
|
+
white: "\x1B[37m",
|
|
119
|
+
gray: "\x1B[90m",
|
|
120
|
+
brightCyan: "\x1B[96m",
|
|
121
|
+
brightRed: "\x1B[91m",
|
|
122
|
+
brightYellow: "\x1B[93m",
|
|
123
|
+
brightGreen: "\x1B[92m",
|
|
124
|
+
brightBlue: "\x1B[94m"
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export { ANSI, createTheme, resolveTokenColorEnabled, createTokens, applyColor, init_colors };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Result, ValidationError } from "@outfitter/contracts";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a date range with start and end dates.
|
|
4
|
+
*/
|
|
5
|
+
interface DateRange {
|
|
6
|
+
/** Start of the range (inclusive, at 00:00:00.000) */
|
|
7
|
+
start: Date;
|
|
8
|
+
/** End of the range (inclusive, at 23:59:59.999) */
|
|
9
|
+
end: Date;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns a new Date set to the start of the day (00:00:00.000).
|
|
13
|
+
*
|
|
14
|
+
* @param date - The date to adjust
|
|
15
|
+
* @returns A new Date object at 00:00:00.000 on the same day
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* startOfDay(new Date("2024-06-15T14:30:00Z"))
|
|
20
|
+
* // Returns 2024-06-15T00:00:00.000 (local time)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function startOfDay(date: Date): Date;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a new Date set to the end of the day (23:59:59.999).
|
|
26
|
+
*
|
|
27
|
+
* @param date - The date to adjust
|
|
28
|
+
* @returns A new Date object at 23:59:59.999 on the same day
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* endOfDay(new Date("2024-06-15T14:30:00Z"))
|
|
33
|
+
* // Returns 2024-06-15T23:59:59.999 (local time)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function endOfDay(date: Date): Date;
|
|
37
|
+
/**
|
|
38
|
+
* Parses date range strings into structured DateRange.
|
|
39
|
+
*
|
|
40
|
+
* Supported formats:
|
|
41
|
+
* - `"today"` - Current day (00:00:00 to 23:59:59)
|
|
42
|
+
* - `"yesterday"` - Previous day
|
|
43
|
+
* - `"last week"` - Last 7 days
|
|
44
|
+
* - `"last month"` - Last 30 days
|
|
45
|
+
* - `"2024-01-01..2024-12-31"` - Explicit range
|
|
46
|
+
* - `"2024-01-01"` - Single day
|
|
47
|
+
*
|
|
48
|
+
* @param input - The date range string to parse
|
|
49
|
+
* @returns Result containing DateRange on success, or ValidationError on failure
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* parseDateRange("today")
|
|
54
|
+
* // Ok({ start: today 00:00, end: today 23:59:59 })
|
|
55
|
+
*
|
|
56
|
+
* parseDateRange("2024-01-01..2024-12-31")
|
|
57
|
+
* // Ok({ start: 2024-01-01 00:00, end: 2024-12-31 23:59:59 })
|
|
58
|
+
*
|
|
59
|
+
* parseDateRange("invalid")
|
|
60
|
+
* // Err(ValidationError)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function parseDateRange(input: string): Result<DateRange, InstanceType<typeof ValidationError>>;
|
|
64
|
+
export { DateRange, startOfDay, endOfDay, parseDateRange };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
ANSI,
|
|
4
|
+
init_colors
|
|
5
|
+
} from "./cli-9nbyj2bt.js";
|
|
6
|
+
import {
|
|
7
|
+
init_detection,
|
|
8
|
+
supportsColor
|
|
9
|
+
} from "./cli-d9ad0rqj.js";
|
|
10
|
+
|
|
11
|
+
// packages/cli/src/render/markdown.ts
|
|
12
|
+
init_detection();
|
|
13
|
+
init_colors();
|
|
14
|
+
function renderMarkdown(markdown) {
|
|
15
|
+
const colorEnabled = supportsColor();
|
|
16
|
+
let result = markdown;
|
|
17
|
+
result = result.replace(/```(\w*)\n([\s\S]*?)```/g, (_match, _lang, code) => {
|
|
18
|
+
const trimmed = code.trimEnd();
|
|
19
|
+
if (colorEnabled) {
|
|
20
|
+
return `${ANSI.dim}${trimmed}${ANSI.reset}`;
|
|
21
|
+
}
|
|
22
|
+
return trimmed;
|
|
23
|
+
});
|
|
24
|
+
result = result.replace(/^(#{1,6})\s+(.+)$/gm, (_match, _hashes, text) => {
|
|
25
|
+
if (colorEnabled) {
|
|
26
|
+
return `${ANSI.bold}${text}${ANSI.reset}`;
|
|
27
|
+
}
|
|
28
|
+
return text;
|
|
29
|
+
});
|
|
30
|
+
result = result.replace(/\*\*(.+?)\*\*/g, (_match, text) => {
|
|
31
|
+
if (colorEnabled) {
|
|
32
|
+
return `${ANSI.bold}${text}${ANSI.reset}`;
|
|
33
|
+
}
|
|
34
|
+
return text;
|
|
35
|
+
});
|
|
36
|
+
result = result.replace(/__(.+?)__/g, (_match, text) => {
|
|
37
|
+
if (colorEnabled) {
|
|
38
|
+
return `${ANSI.bold}${text}${ANSI.reset}`;
|
|
39
|
+
}
|
|
40
|
+
return text;
|
|
41
|
+
});
|
|
42
|
+
result = result.replace(/(?<!\*)\*([^*]+)\*(?!\*)/g, (_match, text) => {
|
|
43
|
+
if (colorEnabled) {
|
|
44
|
+
return `${ANSI.italic}${text}${ANSI.reset}`;
|
|
45
|
+
}
|
|
46
|
+
return text;
|
|
47
|
+
});
|
|
48
|
+
result = result.replace(/(?<!_)_([^_]+)_(?!_)/g, (_match, text) => {
|
|
49
|
+
if (colorEnabled) {
|
|
50
|
+
return `${ANSI.italic}${text}${ANSI.reset}`;
|
|
51
|
+
}
|
|
52
|
+
return text;
|
|
53
|
+
});
|
|
54
|
+
result = result.replace(/`([^`]+)`/g, (_match, text) => {
|
|
55
|
+
if (colorEnabled) {
|
|
56
|
+
return `${ANSI.cyan}${text}${ANSI.reset}`;
|
|
57
|
+
}
|
|
58
|
+
return text;
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { renderMarkdown };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
getStringWidth,
|
|
4
|
+
init_text,
|
|
5
|
+
padText,
|
|
6
|
+
truncateText
|
|
7
|
+
} from "./cli-jjemfdta.js";
|
|
8
|
+
import {
|
|
9
|
+
getBorderCharacters,
|
|
10
|
+
init_borders
|
|
11
|
+
} from "./cli-85fg2vr5.js";
|
|
12
|
+
|
|
13
|
+
// packages/cli/src/render/table.ts
|
|
14
|
+
init_borders();
|
|
15
|
+
init_text();
|
|
16
|
+
function renderTable(data, options) {
|
|
17
|
+
if (data.length === 0) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
const allKeys = new Set;
|
|
21
|
+
for (const row of data) {
|
|
22
|
+
for (const key of Object.keys(row)) {
|
|
23
|
+
allKeys.add(key);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const keys = Array.from(allKeys);
|
|
27
|
+
const headers = options?.headers ?? {};
|
|
28
|
+
const getHeader = (key) => headers[key] ?? key;
|
|
29
|
+
const columnWidths = {};
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
const headerWidth = getStringWidth(getHeader(key));
|
|
32
|
+
let maxDataWidth = 0;
|
|
33
|
+
for (const row of data) {
|
|
34
|
+
const value = row[key];
|
|
35
|
+
const strValue = value === undefined || value === null ? "" : String(value);
|
|
36
|
+
const width = getStringWidth(strValue);
|
|
37
|
+
if (width > maxDataWidth) {
|
|
38
|
+
maxDataWidth = width;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const optionWidth = options?.columnWidths?.[key];
|
|
42
|
+
columnWidths[key] = optionWidth ?? Math.max(headerWidth, maxDataWidth);
|
|
43
|
+
}
|
|
44
|
+
const compact = options?.compact ?? false;
|
|
45
|
+
const borderStyle = compact ? "none" : options?.border ?? "single";
|
|
46
|
+
const chars = getBorderCharacters(borderStyle);
|
|
47
|
+
const hasBorders = borderStyle !== "none";
|
|
48
|
+
return hasBorders ? renderWithBorders(data, keys, columnWidths, getHeader, chars) : renderCompact(data, keys, columnWidths, getHeader);
|
|
49
|
+
}
|
|
50
|
+
function renderWithBorders(data, keys, columnWidths, getHeader, chars) {
|
|
51
|
+
const lines = [];
|
|
52
|
+
const colWidthsForBorder = keys.map((k) => (columnWidths[k] ?? 0) + 2);
|
|
53
|
+
lines.push(drawHorizontalBorder(chars, colWidthsForBorder, "top"));
|
|
54
|
+
lines.push(drawDataRow(keys.map((k) => getHeader(k)), keys.map((k) => columnWidths[k] ?? 0), chars.vertical));
|
|
55
|
+
lines.push(drawHorizontalBorder(chars, colWidthsForBorder, "middle"));
|
|
56
|
+
for (const row of data) {
|
|
57
|
+
const values = keys.map((k) => {
|
|
58
|
+
const value = row[k];
|
|
59
|
+
let strValue = value === undefined || value === null ? "" : String(value);
|
|
60
|
+
const width = columnWidths[k] ?? 0;
|
|
61
|
+
if (getStringWidth(strValue) > width) {
|
|
62
|
+
strValue = truncateText(strValue, width);
|
|
63
|
+
}
|
|
64
|
+
return strValue;
|
|
65
|
+
});
|
|
66
|
+
lines.push(drawDataRow(values, keys.map((k) => columnWidths[k] ?? 0), chars.vertical));
|
|
67
|
+
}
|
|
68
|
+
lines.push(drawHorizontalBorder(chars, colWidthsForBorder, "bottom"));
|
|
69
|
+
return lines.join(`
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
function renderCompact(data, keys, columnWidths, getHeader) {
|
|
73
|
+
const lines = [];
|
|
74
|
+
const headerValues = keys.map((k) => {
|
|
75
|
+
const header = getHeader(k);
|
|
76
|
+
const width = columnWidths[k] ?? 0;
|
|
77
|
+
return padText(header, width);
|
|
78
|
+
});
|
|
79
|
+
lines.push(headerValues.join(" "));
|
|
80
|
+
for (const row of data) {
|
|
81
|
+
const values = keys.map((k) => {
|
|
82
|
+
const value = row[k];
|
|
83
|
+
let strValue = value === undefined || value === null ? "" : String(value);
|
|
84
|
+
const width = columnWidths[k] ?? 0;
|
|
85
|
+
if (getStringWidth(strValue) > width) {
|
|
86
|
+
strValue = truncateText(strValue, width);
|
|
87
|
+
}
|
|
88
|
+
return padText(strValue, width);
|
|
89
|
+
});
|
|
90
|
+
lines.push(values.join(" "));
|
|
91
|
+
}
|
|
92
|
+
return lines.join(`
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
function drawHorizontalBorder(chars, colWidths, position) {
|
|
96
|
+
const positionChars = {
|
|
97
|
+
top: { left: chars.topLeft, right: chars.topRight, cross: chars.topT },
|
|
98
|
+
middle: { left: chars.leftT, right: chars.rightT, cross: chars.cross },
|
|
99
|
+
bottom: {
|
|
100
|
+
left: chars.bottomLeft,
|
|
101
|
+
right: chars.bottomRight,
|
|
102
|
+
cross: chars.bottomT
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const { left, right, cross } = positionChars[position];
|
|
106
|
+
const segments = colWidths.map((w) => chars.horizontal.repeat(w));
|
|
107
|
+
return `${left}${segments.join(cross)}${right}`;
|
|
108
|
+
}
|
|
109
|
+
function drawDataRow(values, widths, vertical) {
|
|
110
|
+
const cells = values.map((value, i) => {
|
|
111
|
+
const width = widths[i] ?? 0;
|
|
112
|
+
return ` ${padText(value, width)} `;
|
|
113
|
+
});
|
|
114
|
+
return `${vertical}${cells.join(vertical)}${vertical}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { renderTable };
|