@outfitter/cli 0.1.0-rc.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -32
- package/dist/actions.d.ts +12 -1
- package/dist/actions.js +170 -3
- 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.js +1 -1
- package/dist/colors/index.d.ts +3 -0
- package/dist/colors/index.js +18 -0
- package/dist/command.d.ts +40 -3
- package/dist/command.js +45 -3
- 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 -8
- package/dist/index.js +9 -43
- package/dist/input.d.ts +163 -2
- package/dist/input.js +425 -11
- package/dist/list/index.d.ts +3 -0
- package/dist/list/index.js +9 -0
- package/dist/output.js +1 -1
- package/dist/pagination.d.ts +62 -2
- package/dist/pagination.js +84 -6
- 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 +1 -1
- package/dist/render/colors.js +6 -3
- package/dist/render/date.js +1 -1
- package/dist/render/format-relative.js +1 -1
- package/dist/render/format.js +1 -1
- package/dist/render/heading.d.ts +3 -0
- package/dist/render/heading.js +14 -0
- package/dist/render/index.d.ts +26 -7
- package/dist/render/index.js +160 -26
- package/dist/render/indicators.d.ts +2 -0
- package/dist/render/indicators.js +14 -0
- package/dist/render/json.js +1 -1
- package/dist/render/layout.d.ts +5 -0
- package/dist/render/layout.js +25 -0
- package/dist/render/list.d.ts +2 -2
- package/dist/render/list.js +2 -2
- package/dist/render/markdown.js +4 -4
- package/dist/render/progress.js +1 -1
- package/dist/render/separator.d.ts +3 -0
- package/dist/render/separator.js +14 -0
- package/dist/render/shapes.js +10 -9
- 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 +2 -1
- package/dist/render/table.js +6 -5
- package/dist/render/text.d.ts +1 -1
- package/dist/render/text.js +7 -4
- package/dist/render/tree.d.ts +2 -2
- package/dist/render/tree.js +5 -3
- 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-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-3t2zaenc.d.ts +59 -0
- package/dist/shared/@outfitter/{cli-dds0qqvm.d.ts → cli-4cb5g831.d.ts} +2 -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-74ba31gz.js +134 -0
- package/dist/shared/@outfitter/cli-7gnrb8cr.js +214 -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-8bwaw3pz.js +7 -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-ag0w4pk0.js → cli-9nbyj2bt.js} +60 -21
- package/dist/shared/@outfitter/{cli-azzk8a1d.js → cli-afhjqmg3.js} +7 -3
- 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-bcmcaz1b.js +23 -0
- package/dist/shared/@outfitter/cli-bf3vma4q.js +61 -0
- package/dist/shared/@outfitter/cli-cf1xexgn.d.ts +53 -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-jbj78ac5.js → cli-d9ad0rqj.js} +6 -1
- 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-en6zn6sj.js +1 -0
- package/dist/shared/@outfitter/cli-ep2cvtk8.js +48 -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-j4n8gaf3.js +95 -0
- package/dist/shared/@outfitter/cli-jejfypgf.js +85 -0
- package/dist/shared/@outfitter/{cli-wqc652mx.js → cli-jhcdwvpn.js} +8 -8
- package/dist/shared/@outfitter/{cli-v9mjsvjh.js → cli-jjemfdta.js} +13 -46
- package/dist/shared/@outfitter/cli-kc84wmch.js +267 -0
- package/dist/shared/@outfitter/cli-ktqme80d.js +7 -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-2y3kxew8.d.ts → cli-qj83y5wj.d.ts} +22 -9
- 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-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-n51t773m.d.ts → cli-xsaheemc.d.ts} +44 -4
- package/dist/shared/@outfitter/cli-xvqtqjxk.js +82 -0
- package/dist/shared/@outfitter/cli-y25tt8nc.d.ts +48 -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.js +5 -2
- package/dist/terminal/index.js +6 -2
- 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.js +1 -1
- package/package.json +168 -54
- package/dist/shared/@outfitter/cli-2vs2gxa8.js +0 -429
- package/dist/shared/@outfitter/cli-2yq94zst.d.ts +0 -39
- package/dist/shared/@outfitter/cli-6xc869x1.js +0 -26
- package/dist/shared/@outfitter/cli-7km1e58p.js +0 -85
- package/dist/shared/@outfitter/cli-8r0bnyyx.js +0 -43
- package/dist/shared/@outfitter/cli-afecwfrn.d.ts +0 -13
- package/dist/shared/@outfitter/cli-bt423m6y.js +0 -4
- package/dist/shared/@outfitter/cli-d4fegbad.d.ts +0 -66
- package/dist/shared/@outfitter/cli-e0ecw3x1.js +0 -64
- package/dist/shared/@outfitter/cli-fheaaa6b.js +0 -25
- package/dist/shared/@outfitter/cli-j361wp3g.d.ts +0 -41
- package/dist/shared/@outfitter/cli-p0m2fc51.js +0 -172
- package/dist/shared/@outfitter/cli-tyajr8qa.d.ts +0 -63
- package/dist/shared/@outfitter/cli-zs6jy1am.d.ts +0 -164
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SpinnerStyle } from "./cli-e5ms1y0x";
|
|
2
|
+
import { ListStyle } from "./cli-b0tzqgnf";
|
|
3
|
+
import { BorderStyle } from "./cli-fakncnjp";
|
|
4
|
+
import { PrimitiveId, PrimitiveMeta, ThemeMethodMeta, VariantMeta } from "./cli-qjfc3j11";
|
|
5
|
+
import { Theme } from "./cli-xsaheemc";
|
|
6
|
+
/**
|
|
7
|
+
* Type-safe metadata for all theme methods.
|
|
8
|
+
*
|
|
9
|
+
* Uses `keyof Theme` to ensure every theme method has metadata.
|
|
10
|
+
* Adding a new method to Theme without updating this causes a compile error.
|
|
11
|
+
*/
|
|
12
|
+
declare const THEME_METHOD_META: Record<keyof Theme, ThemeMethodMeta>;
|
|
13
|
+
/**
|
|
14
|
+
* Gets theme methods grouped by category.
|
|
15
|
+
*/
|
|
16
|
+
declare function getThemeMethodsByCategory(): {
|
|
17
|
+
semantic: Array<keyof Theme>;
|
|
18
|
+
utility: Array<keyof Theme>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Type-safe metadata for all border styles.
|
|
22
|
+
*/
|
|
23
|
+
declare const BORDER_STYLE_META: Record<BorderStyle, VariantMeta<BorderStyle>>;
|
|
24
|
+
/**
|
|
25
|
+
* Gets all border styles as an array.
|
|
26
|
+
*/
|
|
27
|
+
declare function getBorderStyles(): BorderStyle[];
|
|
28
|
+
/**
|
|
29
|
+
* Type-safe metadata for all spinner styles.
|
|
30
|
+
*/
|
|
31
|
+
declare const SPINNER_STYLE_META: Record<SpinnerStyle, VariantMeta<SpinnerStyle>>;
|
|
32
|
+
/**
|
|
33
|
+
* Gets all spinner styles as an array.
|
|
34
|
+
*/
|
|
35
|
+
declare function getSpinnerStyles(): SpinnerStyle[];
|
|
36
|
+
/**
|
|
37
|
+
* Type-safe metadata for all list styles.
|
|
38
|
+
*/
|
|
39
|
+
declare const LIST_STYLE_META: Record<ListStyle, VariantMeta<ListStyle>>;
|
|
40
|
+
/**
|
|
41
|
+
* Gets all list styles as an array.
|
|
42
|
+
*/
|
|
43
|
+
declare function getListStyles(): ListStyle[];
|
|
44
|
+
/**
|
|
45
|
+
* Type-safe metadata for all primitives.
|
|
46
|
+
*/
|
|
47
|
+
declare const PRIMITIVE_META: Record<PrimitiveId, PrimitiveMeta>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets all primitive IDs as an array.
|
|
50
|
+
*/
|
|
51
|
+
declare function getPrimitiveIds(): PrimitiveId[];
|
|
52
|
+
/**
|
|
53
|
+
* Gets metadata for a specific primitive.
|
|
54
|
+
*/
|
|
55
|
+
declare function getPrimitiveMeta(id: PrimitiveId): PrimitiveMeta;
|
|
56
|
+
export { THEME_METHOD_META, getThemeMethodsByCategory, BORDER_STYLE_META, getBorderStyles, SPINNER_STYLE_META, getSpinnerStyles, LIST_STYLE_META, getListStyles, PRIMITIVE_META, getPrimitiveIds, getPrimitiveMeta };
|
|
@@ -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 };
|
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
+
init_detection,
|
|
3
4
|
resolveColorEnv,
|
|
4
5
|
supportsColor
|
|
5
|
-
} from "./cli-
|
|
6
|
+
} from "./cli-d9ad0rqj.js";
|
|
7
|
+
import {
|
|
8
|
+
__esm
|
|
9
|
+
} from "./cli-v1tzwxkt.js";
|
|
6
10
|
|
|
7
11
|
// packages/cli/src/render/colors.ts
|
|
8
|
-
var ANSI = {
|
|
9
|
-
reset: "\x1B[0m",
|
|
10
|
-
bold: "\x1B[1m",
|
|
11
|
-
dim: "\x1B[2m",
|
|
12
|
-
italic: "\x1B[3m",
|
|
13
|
-
green: "\x1B[32m",
|
|
14
|
-
yellow: "\x1B[33m",
|
|
15
|
-
red: "\x1B[31m",
|
|
16
|
-
blue: "\x1B[34m",
|
|
17
|
-
cyan: "\x1B[36m",
|
|
18
|
-
magenta: "\x1B[35m",
|
|
19
|
-
white: "\x1B[37m",
|
|
20
|
-
gray: "\x1B[90m"
|
|
21
|
-
};
|
|
22
12
|
function createTheme() {
|
|
23
13
|
const colorEnabled = supportsColor();
|
|
24
14
|
const colorFn = (ansiCode) => (text) => {
|
|
@@ -34,7 +24,16 @@ function createTheme() {
|
|
|
34
24
|
info: colorFn(ANSI.blue),
|
|
35
25
|
primary: colorFn(""),
|
|
36
26
|
secondary: colorFn(ANSI.gray),
|
|
37
|
-
muted: colorFn(ANSI.dim)
|
|
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)
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
function resolveTokenColorEnabled(options) {
|
|
@@ -61,10 +60,18 @@ function createTokens(options) {
|
|
|
61
60
|
warning: "",
|
|
62
61
|
error: "",
|
|
63
62
|
info: "",
|
|
63
|
+
primary: "",
|
|
64
|
+
secondary: "",
|
|
64
65
|
muted: "",
|
|
65
66
|
accent: "",
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
highlight: "",
|
|
68
|
+
link: "",
|
|
69
|
+
destructive: "",
|
|
70
|
+
subtle: "",
|
|
71
|
+
bold: "",
|
|
72
|
+
italic: "",
|
|
73
|
+
underline: "",
|
|
74
|
+
dim: ""
|
|
68
75
|
};
|
|
69
76
|
}
|
|
70
77
|
return {
|
|
@@ -72,10 +79,18 @@ function createTokens(options) {
|
|
|
72
79
|
warning: ANSI.yellow,
|
|
73
80
|
error: ANSI.red,
|
|
74
81
|
info: ANSI.blue,
|
|
82
|
+
primary: "",
|
|
83
|
+
secondary: ANSI.gray,
|
|
75
84
|
muted: ANSI.dim,
|
|
76
85
|
accent: ANSI.cyan,
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
79
94
|
};
|
|
80
95
|
}
|
|
81
96
|
function applyColor(text, color) {
|
|
@@ -85,5 +100,29 @@ function applyColor(text, color) {
|
|
|
85
100
|
const ansiCode = ANSI[color];
|
|
86
101
|
return `${ansiCode}${text}${ANSI.reset}`;
|
|
87
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
|
+
});
|
|
88
127
|
|
|
89
|
-
export { ANSI, createTheme, resolveTokenColorEnabled, createTokens, applyColor };
|
|
128
|
+
export { ANSI, createTheme, resolveTokenColorEnabled, createTokens, applyColor, init_colors };
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
-
ANSI
|
|
4
|
-
|
|
3
|
+
ANSI,
|
|
4
|
+
init_colors
|
|
5
|
+
} from "./cli-9nbyj2bt.js";
|
|
5
6
|
import {
|
|
7
|
+
init_detection,
|
|
6
8
|
supportsColor
|
|
7
|
-
} from "./cli-
|
|
9
|
+
} from "./cli-d9ad0rqj.js";
|
|
8
10
|
|
|
9
11
|
// packages/cli/src/render/markdown.ts
|
|
12
|
+
init_detection();
|
|
13
|
+
init_colors();
|
|
10
14
|
function renderMarkdown(markdown) {
|
|
11
15
|
const colorEnabled = supportsColor();
|
|
12
16
|
let result = markdown;
|
|
@@ -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 };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
TREE_GUIDES,
|
|
4
|
+
renderTree
|
|
5
|
+
} from "./cli-b5c2k0d7.js";
|
|
6
|
+
import {
|
|
7
|
+
getExample
|
|
8
|
+
} from "./cli-xep6v2c0.js";
|
|
9
|
+
import {
|
|
10
|
+
demoSection
|
|
11
|
+
} from "./cli-34fqr7bp.js";
|
|
12
|
+
|
|
13
|
+
// packages/cli/src/demo/renderers/tree.ts
|
|
14
|
+
function renderTreeDemo(config, _theme) {
|
|
15
|
+
const showCode = config.showCode ?? true;
|
|
16
|
+
const lines = [];
|
|
17
|
+
lines.push(demoSection("Basic Tree"));
|
|
18
|
+
lines.push("");
|
|
19
|
+
if (showCode) {
|
|
20
|
+
lines.push('import { renderTree } from "@outfitter/cli/tree";');
|
|
21
|
+
lines.push("");
|
|
22
|
+
}
|
|
23
|
+
const treeData = getExample("treeData", config.examples);
|
|
24
|
+
if (showCode) {
|
|
25
|
+
lines.push("renderTree({");
|
|
26
|
+
lines.push(" src: {");
|
|
27
|
+
lines.push(" components: { Button: null, Input: null },");
|
|
28
|
+
lines.push(" utils: null,");
|
|
29
|
+
lines.push(" },");
|
|
30
|
+
lines.push(" tests: null,");
|
|
31
|
+
lines.push("})");
|
|
32
|
+
lines.push("");
|
|
33
|
+
}
|
|
34
|
+
lines.push(renderTree(treeData));
|
|
35
|
+
lines.push("");
|
|
36
|
+
lines.push(demoSection("Guide Styles"));
|
|
37
|
+
lines.push("");
|
|
38
|
+
const guideDemo = {
|
|
39
|
+
root: {
|
|
40
|
+
child1: {
|
|
41
|
+
leaf: null
|
|
42
|
+
},
|
|
43
|
+
child2: null
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const guideStyles = [
|
|
47
|
+
"single",
|
|
48
|
+
"rounded",
|
|
49
|
+
"heavy",
|
|
50
|
+
"double"
|
|
51
|
+
];
|
|
52
|
+
for (const style of guideStyles) {
|
|
53
|
+
const guide = TREE_GUIDES[style];
|
|
54
|
+
lines.push(`${style.toUpperCase()} (fork: "${guide.fork.trim()}", end: "${guide.end.trim()}")`);
|
|
55
|
+
lines.push("");
|
|
56
|
+
lines.push(renderTree(guideDemo, { guide: style }));
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
lines.push(demoSection("Max Depth"));
|
|
60
|
+
lines.push("");
|
|
61
|
+
const deepTree = {
|
|
62
|
+
level1: {
|
|
63
|
+
level2: {
|
|
64
|
+
level3: {
|
|
65
|
+
level4: null
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (showCode) {
|
|
71
|
+
lines.push("renderTree(tree, { maxDepth: 2 })");
|
|
72
|
+
lines.push("");
|
|
73
|
+
}
|
|
74
|
+
lines.push("Full tree:");
|
|
75
|
+
lines.push(renderTree(deepTree));
|
|
76
|
+
lines.push("");
|
|
77
|
+
lines.push("With maxDepth: 2:");
|
|
78
|
+
lines.push(renderTree(deepTree, { maxDepth: 2 }));
|
|
79
|
+
lines.push("");
|
|
80
|
+
lines.push(demoSection("Custom Labels"));
|
|
81
|
+
lines.push("");
|
|
82
|
+
const fileTree = {
|
|
83
|
+
src: {
|
|
84
|
+
"index.ts": null,
|
|
85
|
+
components: {
|
|
86
|
+
"Button.tsx": null
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"package.json": null
|
|
90
|
+
};
|
|
91
|
+
if (showCode) {
|
|
92
|
+
lines.push("renderTree(tree, {");
|
|
93
|
+
lines.push(" renderLabel: (key, value) => {");
|
|
94
|
+
lines.push(" if (value && typeof value === 'object') {");
|
|
95
|
+
lines.push(" return `\uD83D\uDCC1 ${key}/`;");
|
|
96
|
+
lines.push(" }");
|
|
97
|
+
lines.push(" return `\uD83D\uDCC4 ${key}`;");
|
|
98
|
+
lines.push(" }");
|
|
99
|
+
lines.push("})");
|
|
100
|
+
lines.push("");
|
|
101
|
+
}
|
|
102
|
+
lines.push(renderTree(fileTree, {
|
|
103
|
+
renderLabel: (key, value) => {
|
|
104
|
+
if (value && typeof value === "object") {
|
|
105
|
+
return `\uD83D\uDCC1 ${key}/`;
|
|
106
|
+
}
|
|
107
|
+
return `\uD83D\uDCC4 ${key}`;
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
lines.push("");
|
|
111
|
+
lines.push(demoSection("Usage Notes"));
|
|
112
|
+
lines.push("");
|
|
113
|
+
lines.push("\u2022 Objects become branches with children");
|
|
114
|
+
lines.push("\u2022 null values become leaf nodes (terminal)");
|
|
115
|
+
lines.push("\u2022 Use guide option to change visual style");
|
|
116
|
+
lines.push("\u2022 Use maxDepth to limit rendering depth");
|
|
117
|
+
lines.push("\u2022 Use renderLabel for custom node formatting");
|
|
118
|
+
return lines.join(`
|
|
119
|
+
`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { renderTreeDemo };
|