@promptctl/rich-js 0.18.0 → 0.19.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 +9 -7
- package/dist/core/anchor.d.ts +45 -0
- package/dist/core/anchor.js +39 -0
- package/dist/core/ansi.d.ts +65 -0
- package/dist/core/ansi.js +231 -0
- package/dist/core/box.d.ts +145 -0
- package/dist/core/box.js +372 -0
- package/dist/core/cells.d.ts +192 -0
- package/dist/core/cells.js +334 -0
- package/dist/core/clock.d.ts +48 -0
- package/dist/core/clock.js +42 -0
- package/dist/core/color.d.ts +326 -0
- package/dist/core/color.js +1225 -0
- package/dist/core/console.d.ts +196 -0
- package/dist/core/console.js +596 -0
- package/dist/core/easing.d.ts +86 -0
- package/dist/core/easing.js +171 -0
- package/dist/core/emoji.d.ts +24 -0
- package/dist/core/emoji.js +391 -0
- package/dist/core/env.d.ts +16 -0
- package/dist/core/env.js +16 -0
- package/dist/core/export-html.d.ts +59 -0
- package/dist/core/export-html.js +197 -0
- package/dist/core/export-lines.d.ts +130 -0
- package/dist/core/export-lines.js +159 -0
- package/dist/core/export-svg.d.ts +49 -0
- package/dist/core/export-svg.js +213 -0
- package/dist/core/fnv1a.d.ts +10 -0
- package/dist/core/fnv1a.js +17 -0
- package/dist/core/highlighter.d.ts +33 -0
- package/dist/core/highlighter.js +190 -0
- package/dist/core/json.d.ts +27 -0
- package/dist/core/json.js +53 -0
- package/dist/core/markup.d.ts +140 -0
- package/dist/core/markup.js +654 -0
- package/dist/core/measure.d.ts +27 -0
- package/dist/core/measure.js +67 -0
- package/dist/core/memo.d.ts +19 -0
- package/dist/core/memo.js +34 -0
- package/dist/core/oklch.d.ts +161 -0
- package/dist/core/oklch.js +312 -0
- package/dist/core/osc8.d.ts +68 -0
- package/dist/core/osc8.js +78 -0
- package/dist/core/paint.d.ts +107 -0
- package/dist/core/paint.js +150 -0
- package/dist/core/place.d.ts +30 -0
- package/dist/core/place.js +49 -0
- package/dist/core/pretty.d.ts +247 -0
- package/dist/core/pretty.js +906 -0
- package/dist/core/protocol.d.ts +305 -0
- package/dist/core/protocol.js +183 -0
- package/dist/core/render.d.ts +87 -0
- package/dist/core/render.js +105 -0
- package/dist/core/segment.d.ts +162 -0
- package/dist/core/segment.js +488 -0
- package/dist/core/spinnerData.d.ts +12 -0
- package/dist/core/spinnerData.js +117 -0
- package/dist/core/strip.d.ts +152 -0
- package/dist/core/strip.js +326 -0
- package/dist/core/style.d.ts +189 -0
- package/dist/core/style.js +758 -0
- package/dist/core/subscription.d.ts +12 -0
- package/dist/core/subscription.js +12 -0
- package/dist/core/text.d.ts +283 -0
- package/dist/core/text.js +1097 -0
- package/dist/core/wrap.d.ts +46 -0
- package/dist/core/wrap.js +140 -0
- package/dist/host/app.d.ts +133 -0
- package/dist/host/app.js +285 -0
- package/dist/host/host-environment.d.ts +26 -0
- package/dist/host/host-environment.js +44 -0
- package/dist/host/index.d.ts +6 -0
- package/dist/host/index.js +3 -0
- package/dist/host/terminal-host.d.ts +180 -0
- package/dist/host/terminal-host.js +186 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +114 -0
- package/dist/node/prompt.d.ts +34 -0
- package/dist/node/prompt.js +51 -0
- package/dist/node/save.d.ts +18 -0
- package/dist/node/save.js +24 -0
- package/dist/node/terminal-host.d.ts +114 -0
- package/dist/node/terminal-host.js +227 -0
- package/dist/node/traceback.d.ts +38 -0
- package/dist/node/traceback.js +98 -0
- package/dist/renderables/align.d.ts +16 -0
- package/dist/renderables/align.js +26 -0
- package/dist/renderables/columns.d.ts +77 -0
- package/dist/renderables/columns.js +191 -0
- package/dist/renderables/constrain.d.ts +15 -0
- package/dist/renderables/constrain.js +31 -0
- package/dist/renderables/effect.d.ts +98 -0
- package/dist/renderables/effect.js +160 -0
- package/dist/renderables/embed.d.ts +107 -0
- package/dist/renderables/embed.js +160 -0
- package/dist/renderables/flexStrip.d.ts +41 -0
- package/dist/renderables/flexStrip.js +200 -0
- package/dist/renderables/group.d.ts +14 -0
- package/dist/renderables/group.js +22 -0
- package/dist/renderables/layout.d.ts +75 -0
- package/dist/renderables/layout.js +223 -0
- package/dist/renderables/live.d.ts +74 -0
- package/dist/renderables/live.js +188 -0
- package/dist/renderables/markdown.d.ts +38 -0
- package/dist/renderables/markdown.js +587 -0
- package/dist/renderables/padding.d.ts +59 -0
- package/dist/renderables/padding.js +147 -0
- package/dist/renderables/panel.d.ts +114 -0
- package/dist/renderables/panel.js +303 -0
- package/dist/renderables/progress.d.ts +178 -0
- package/dist/renderables/progress.js +362 -0
- package/dist/renderables/progressBar.d.ts +31 -0
- package/dist/renderables/progressBar.js +64 -0
- package/dist/renderables/prompt.d.ts +71 -0
- package/dist/renderables/prompt.js +165 -0
- package/dist/renderables/ratio.d.ts +123 -0
- package/dist/renderables/ratio.js +213 -0
- package/dist/renderables/rule.d.ts +26 -0
- package/dist/renderables/rule.js +86 -0
- package/dist/renderables/spinner.d.ts +57 -0
- package/dist/renderables/spinner.js +103 -0
- package/dist/renderables/status.d.ts +29 -0
- package/dist/renderables/status.js +46 -0
- package/dist/renderables/syntax.d.ts +65 -0
- package/dist/renderables/syntax.js +166 -0
- package/dist/renderables/table.d.ts +232 -0
- package/dist/renderables/table.js +973 -0
- package/dist/renderables/traceback.d.ts +32 -0
- package/dist/renderables/traceback.js +279 -0
- package/dist/renderables/tree.d.ts +76 -0
- package/dist/renderables/tree.js +177 -0
- package/dist/renderables/viewport.d.ts +114 -0
- package/dist/renderables/viewport.js +196 -0
- package/dist/template-bindings/color-funcs.d.ts +109 -0
- package/dist/template-bindings/color-funcs.js +243 -0
- package/dist/template-bindings/helpers.d.ts +26 -0
- package/dist/template-bindings/helpers.js +33 -0
- package/dist/template-bindings/index.d.ts +119 -0
- package/dist/template-bindings/index.js +162 -0
- package/dist/template-bindings/palette-funcs.d.ts +96 -0
- package/dist/template-bindings/palette-funcs.js +145 -0
- package/dist/template-bindings/style-funcs.d.ts +28 -0
- package/dist/template-bindings/style-funcs.js +157 -0
- package/dist/themes/buildPalette.d.ts +57 -0
- package/dist/themes/buildPalette.js +100 -0
- package/dist/themes/colorMath.d.ts +94 -0
- package/dist/themes/colorMath.js +280 -0
- package/dist/themes/colorRef.d.ts +36 -0
- package/dist/themes/colorRef.js +78 -0
- package/dist/themes/data/ansi-tables.d.ts +14 -0
- package/dist/themes/data/ansi-tables.js +49 -0
- package/dist/themes/data/atom-one-dark.d.ts +3 -0
- package/dist/themes/data/atom-one-dark.js +177 -0
- package/dist/themes/data/atom-one-light.d.ts +3 -0
- package/dist/themes/data/atom-one-light.js +177 -0
- package/dist/themes/data/catppuccin-frappe.d.ts +3 -0
- package/dist/themes/data/catppuccin-frappe.js +177 -0
- package/dist/themes/data/catppuccin-latte.d.ts +3 -0
- package/dist/themes/data/catppuccin-latte.js +177 -0
- package/dist/themes/data/catppuccin-macchiato.d.ts +3 -0
- package/dist/themes/data/catppuccin-macchiato.js +177 -0
- package/dist/themes/data/catppuccin-mocha.d.ts +3 -0
- package/dist/themes/data/catppuccin-mocha.js +177 -0
- package/dist/themes/data/cyberpunk.d.ts +17 -0
- package/dist/themes/data/cyberpunk.js +193 -0
- package/dist/themes/data/default.d.ts +3 -0
- package/dist/themes/data/default.js +160 -0
- package/dist/themes/data/dracula.d.ts +3 -0
- package/dist/themes/data/dracula.js +177 -0
- package/dist/themes/data/flexoki.d.ts +3 -0
- package/dist/themes/data/flexoki.js +177 -0
- package/dist/themes/data/gruvbox.d.ts +3 -0
- package/dist/themes/data/gruvbox.js +177 -0
- package/dist/themes/data/index.d.ts +35 -0
- package/dist/themes/data/index.js +64 -0
- package/dist/themes/data/monokai.d.ts +3 -0
- package/dist/themes/data/monokai.js +177 -0
- package/dist/themes/data/nord.d.ts +3 -0
- package/dist/themes/data/nord.js +177 -0
- package/dist/themes/data/rose-pine-dawn.d.ts +3 -0
- package/dist/themes/data/rose-pine-dawn.js +177 -0
- package/dist/themes/data/rose-pine-moon.d.ts +3 -0
- package/dist/themes/data/rose-pine-moon.js +177 -0
- package/dist/themes/data/rose-pine.d.ts +3 -0
- package/dist/themes/data/rose-pine.js +177 -0
- package/dist/themes/data/solarized-dark.d.ts +3 -0
- package/dist/themes/data/solarized-dark.js +177 -0
- package/dist/themes/data/solarized-light.d.ts +3 -0
- package/dist/themes/data/solarized-light.js +177 -0
- package/dist/themes/data/svg-export.d.ts +3 -0
- package/dist/themes/data/svg-export.js +177 -0
- package/dist/themes/data/textual-ansi.d.ts +3 -0
- package/dist/themes/data/textual-ansi.js +160 -0
- package/dist/themes/data/textual-dark.d.ts +3 -0
- package/dist/themes/data/textual-dark.js +160 -0
- package/dist/themes/data/textual-light.d.ts +3 -0
- package/dist/themes/data/textual-light.js +160 -0
- package/dist/themes/data/tokyo-night.d.ts +3 -0
- package/dist/themes/data/tokyo-night.js +177 -0
- package/dist/themes/data/types.d.ts +31 -0
- package/dist/themes/data/types.js +10 -0
- package/dist/themes/palette.d.ts +45 -0
- package/dist/themes/palette.js +71 -0
- package/dist/themes/ramp.d.ts +70 -0
- package/dist/themes/ramp.js +103 -0
- package/dist/themes/registry.d.ts +44 -0
- package/dist/themes/registry.js +105 -0
- package/dist/themes/terminalThemes.d.ts +49 -0
- package/dist/themes/terminalThemes.js +63 -0
- package/dist/themes/transpose.d.ts +87 -0
- package/dist/themes/transpose.js +138 -0
- package/dist/widgets/button.d.ts +45 -0
- package/dist/widgets/button.js +177 -0
- package/dist/widgets/checkbox.d.ts +38 -0
- package/dist/widgets/checkbox.js +135 -0
- package/dist/widgets/dropdown.d.ts +64 -0
- package/dist/widgets/dropdown.js +416 -0
- package/dist/widgets/event-router.d.ts +71 -0
- package/dist/widgets/event-router.js +629 -0
- package/dist/widgets/focus-manager.d.ts +45 -0
- package/dist/widgets/focus-manager.js +191 -0
- package/dist/widgets/hit.d.ts +64 -0
- package/dist/widgets/hit.js +113 -0
- package/dist/widgets/index.d.ts +20 -0
- package/dist/widgets/index.js +14 -0
- package/dist/widgets/ink.d.ts +22 -0
- package/dist/widgets/ink.js +31 -0
- package/dist/widgets/slider.d.ts +54 -0
- package/dist/widgets/slider.js +247 -0
- package/dist/widgets/static-item.d.ts +34 -0
- package/dist/widgets/static-item.js +54 -0
- package/dist/widgets/text-input.d.ts +283 -0
- package/dist/widgets/text-input.js +1174 -0
- package/dist/widgets/themed-widget.d.ts +20 -0
- package/dist/widgets/themed-widget.js +89 -0
- package/dist/widgets/toggle.d.ts +41 -0
- package/dist/widgets/toggle.js +157 -0
- package/dist/widgets/types.d.ts +87 -0
- package/dist/widgets/types.js +30 -0
- package/dist/widgets/widget-app.d.ts +65 -0
- package/dist/widgets/widget-app.js +206 -0
- package/dist/widgets/widget-base.d.ts +42 -0
- package/dist/widgets/widget-base.js +172 -0
- package/package.json +16 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markup — BBCode-inspired markup parser for inline styling.
|
|
3
|
+
* Parses `[bold red]text[/bold red]` into RichText with styled spans.
|
|
4
|
+
*
|
|
5
|
+
* Plugin tags ([LAW:locality-or-seam]): a `MarkupRegistry` lets consumers
|
|
6
|
+
* register tag handlers without forking the parser. When the parser sees
|
|
7
|
+
* `[name attrs...]inner[/name]` and `name` is registered, it parses attrs,
|
|
8
|
+
* renders the inner markup as the child `RichText`, and calls the handler —
|
|
9
|
+
* splicing the `RichText` it returns into the output. The
|
|
10
|
+
* built-in style dialect and the plugin dialect are routed by the registry,
|
|
11
|
+
* which is the single trust boundary between them.
|
|
12
|
+
*
|
|
13
|
+
* Plugin pairs must nest. The built-in dialect admits non-strict nesting
|
|
14
|
+
* (`[bold]a[italic]b[/bold]c[/italic]`) because a style is an annotation and
|
|
15
|
+
* annotations may overlap freely; a plugin tag is a replacement whose handler
|
|
16
|
+
* takes one contiguous `inner`, so an overlapping pair has no slice to hand it
|
|
17
|
+
* and is rejected with a `MarkupSyntaxError`. For the same reason a style tag
|
|
18
|
+
* may not open on one side of a plugin tag and close on the other.
|
|
19
|
+
*/
|
|
20
|
+
import { Style } from "./style.js";
|
|
21
|
+
import { RichText } from "./text.js";
|
|
22
|
+
import type { RenderOptions as DrawOptions } from "./protocol.js";
|
|
23
|
+
export declare class Tag {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly parameters: string | undefined;
|
|
26
|
+
constructor(name: string, parameters?: string);
|
|
27
|
+
toString(): string;
|
|
28
|
+
get markup(): string;
|
|
29
|
+
}
|
|
30
|
+
export declare class MarkupError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A markup string that cannot be parsed, with where it went wrong.
|
|
35
|
+
*
|
|
36
|
+
* [LAW:types-are-the-program] A subclass rather than optional fields on
|
|
37
|
+
* `MarkupError`, because the parent is also what `MarkupRegistry.register`
|
|
38
|
+
* throws, and a registration has no source text to point into. Every error this
|
|
39
|
+
* class describes has a location, so none of its fields is optional and no
|
|
40
|
+
* caller has to ask whether one is present — `instanceof` is the only question.
|
|
41
|
+
*
|
|
42
|
+
* [LAW:one-source-of-truth] The constructor takes the facts the parser holds —
|
|
43
|
+
* the string, the offset of the offending tag, what was open — and derives
|
|
44
|
+
* `line`, `column` and the message from them, so the numbers a caller reads
|
|
45
|
+
* and the caret the message draws cannot disagree.
|
|
46
|
+
*/
|
|
47
|
+
export declare class MarkupSyntaxError extends MarkupError {
|
|
48
|
+
/** The problem alone, with no location, for callers building their own message. */
|
|
49
|
+
readonly reason: string;
|
|
50
|
+
/** The whole markup string that failed, as the caller passed it. */
|
|
51
|
+
readonly markup: string;
|
|
52
|
+
/** Index into `markup` of the tag the parser rejected. */
|
|
53
|
+
readonly offset: number;
|
|
54
|
+
/** 1-based line of `offset`; lines are separated by `\n`. */
|
|
55
|
+
readonly line: number;
|
|
56
|
+
/** 1-based column of `offset` within its line, in UTF-16 code units. */
|
|
57
|
+
readonly column: number;
|
|
58
|
+
/**
|
|
59
|
+
* The opening tags still open at `offset`, outermost first, as written.
|
|
60
|
+
*/
|
|
61
|
+
readonly openTags: readonly string[];
|
|
62
|
+
constructor(reason: string, markup: string, offset: number, openTags: readonly string[]);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Escapes markup characters so they render as literal text.
|
|
66
|
+
*
|
|
67
|
+
* [LAW:one-source-of-truth] The inverse of the two ways the parser reads a
|
|
68
|
+
* backslash run in front of a bracket, over the same `TAG_BODY`: before a tag
|
|
69
|
+
* the run is halved and an odd one left over escapes it, so the run is doubled
|
|
70
|
+
* and one added; before any other bracket one `\[` becomes `[`, so one
|
|
71
|
+
* backslash is added.
|
|
72
|
+
*
|
|
73
|
+
* No bracket in the output can open a tag, whatever it is joined to. A bracket
|
|
74
|
+
* whose tag the text ends before finishing — `[link=x` — is escaped as a tag,
|
|
75
|
+
* because the next fragment's `]` would finish it; when what follows is instead
|
|
76
|
+
* the caller's own tag, a backslash run in front of it renders doubled. A
|
|
77
|
+
* trailing run is doubled for the same reason: `escape("C:\\")` spliced before
|
|
78
|
+
* `[/bold]` would otherwise escape the closing tag, so at the very end of a
|
|
79
|
+
* string it renders doubled. The grammar cannot tell those cases apart, and
|
|
80
|
+
* both choices fail visibly rather than let input open or escape a tag.
|
|
81
|
+
*
|
|
82
|
+
* Rich's `escape` escapes only a finished tag and doubles only a trailing run
|
|
83
|
+
* of one, so input can drop a backslash, escape the closing tag after it, or
|
|
84
|
+
* open a tag across a join. All three are departures on purpose.
|
|
85
|
+
*/
|
|
86
|
+
export declare function escape(text: string): string;
|
|
87
|
+
export interface MarkupTagContext {
|
|
88
|
+
/** Parsed `key=value` attributes from the opening tag. */
|
|
89
|
+
attrs: Record<string, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Inner markup, already parsed (registry-aware) into a `RichText`. It carries
|
|
92
|
+
* no `baseStyle`: that is painted once, under the whole output, so it sits
|
|
93
|
+
* beneath whatever the handler returns.
|
|
94
|
+
*/
|
|
95
|
+
children: RichText;
|
|
96
|
+
/** Raw inner markup text (between the opening tag's `]` and the closing tag's `[`). */
|
|
97
|
+
raw: string;
|
|
98
|
+
}
|
|
99
|
+
export type MarkupTagHandler = (ctx: MarkupTagContext) => RichText;
|
|
100
|
+
export declare class MarkupRegistry {
|
|
101
|
+
private readonly _handlers;
|
|
102
|
+
register(name: string, handler: MarkupTagHandler): void;
|
|
103
|
+
unregister(name: string): void;
|
|
104
|
+
has(name: string): boolean;
|
|
105
|
+
get(name: string): MarkupTagHandler | undefined;
|
|
106
|
+
}
|
|
107
|
+
export declare const globalMarkupRegistry: MarkupRegistry;
|
|
108
|
+
export interface RenderMarkupOptions {
|
|
109
|
+
registry?: MarkupRegistry;
|
|
110
|
+
baseStyle?: string | Style;
|
|
111
|
+
emoji?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Plugin-aware markup render. Always returns a `RichText`. Built-in style
|
|
115
|
+
* tags become spans; registered plugin tags are resolved by their handler,
|
|
116
|
+
* whose returned `RichText` stands in the output where its pair stood, under
|
|
117
|
+
* any style tag that encloses the pair.
|
|
118
|
+
*/
|
|
119
|
+
export declare function renderMarkup(markup: string, options?: RenderMarkupOptions): RichText;
|
|
120
|
+
/**
|
|
121
|
+
* A string as the text it draws, before any highlighting: read as markup
|
|
122
|
+
* unless `markup` is false, its emoji codes replaced either way, as Rich's
|
|
123
|
+
* `render_str` reads one, its `end` the default line end Rich's leaves it.
|
|
124
|
+
* [LAW:single-enforcer]
|
|
125
|
+
*/
|
|
126
|
+
export declare function readStr(source: string, markup: boolean): RichText;
|
|
127
|
+
/**
|
|
128
|
+
* The highlighter a string is drawn with under `settings`: its `highlighter`
|
|
129
|
+
* while `highlight` is not false — Rich's `render_str`, which highlights with
|
|
130
|
+
* `console.highlighter` when `highlight` is true or left to the console.
|
|
131
|
+
* [LAW:single-enforcer]
|
|
132
|
+
*/
|
|
133
|
+
export declare function activeHighlighter(settings: Pick<DrawOptions, "highlight" | "highlighter">): DrawOptions["highlighter"];
|
|
134
|
+
/**
|
|
135
|
+
* A string as the text it draws, the way Rich's `render_str` makes one: read
|
|
136
|
+
* by `readStr` under `markup`, then highlighted by `activeHighlighter`.
|
|
137
|
+
* `print` and every renderable that is handed a string both draw it this way,
|
|
138
|
+
* so a console's settings mean the same thing wherever the string lands.
|
|
139
|
+
*/
|
|
140
|
+
export declare function renderStr(source: string, settings: Pick<DrawOptions, "markup" | "highlight" | "highlighter">): RichText;
|