@loomwork/plugin-renderer-terminal 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +68 -2
- package/dist/defaultRegistry.d.ts +18 -0
- package/dist/defaultRegistry.d.ts.map +1 -0
- package/dist/defaultRegistry.js +89 -0
- package/dist/defaultRegistry.js.map +1 -0
- package/dist/format.d.ts +3 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +30 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/renderBlueprint.d.ts +38 -0
- package/dist/renderBlueprint.d.ts.map +1 -0
- package/dist/renderBlueprint.js +115 -0
- package/dist/renderBlueprint.js.map +1 -0
- package/package.json +54 -3
- package/src/defaultRegistry.ts +118 -0
- package/src/format.ts +26 -0
- package/src/index.ts +6 -0
- package/src/renderBlueprint.ts +165 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @loomwork/plugin-renderer-terminal — draw a Blueprint as plain text
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Renders a Loom `Blueprint` (the widget layout that `blueprint$` builds) to a string, so the same view an
|
|
4
|
+
app shows in a browser can be printed in a terminal, a log or a test snapshot. It walks the blueprint
|
|
5
|
+
with the framework-agnostic `traverseBlueprint` and applies the shared binding-status rules, so
|
|
6
|
+
pending, stale, error and empty widgets read the same way they do in the React and DOM renderers.
|
|
7
|
+
Use it for CLIs, TUIs and golden-file tests of a view.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { MetricCard, StatusBadge, blueprint$, stack } from "@loomwork/blueprint-runtime";
|
|
11
|
+
import { defaultTerminalRegistry, renderBlueprintToString } from "@loomwork/plugin-renderer-terminal";
|
|
12
|
+
|
|
13
|
+
const bp = blueprint$({
|
|
14
|
+
id: "ops",
|
|
15
|
+
title: "Ops Dashboard",
|
|
16
|
+
layout: stack({
|
|
17
|
+
children: [
|
|
18
|
+
StatusBadge({ title: "Phase", binding: { projectionId: "ui", path: "phase" } }),
|
|
19
|
+
MetricCard({ title: "CPU %", binding: { projectionId: "metrics", path: "cpu" }, unit: "%" }),
|
|
20
|
+
],
|
|
21
|
+
}),
|
|
22
|
+
projections: ["ui", "metrics"],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// One projection state per projection id the blueprint names.
|
|
26
|
+
const state = new Map<string, unknown>([
|
|
27
|
+
["ui", { phase: "triaging" }],
|
|
28
|
+
["metrics", { cpu: 87 }],
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
console.log(renderBlueprintToString(bp, state, { registry: defaultTerminalRegistry }));
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Surface
|
|
35
|
+
|
|
36
|
+
- **`renderBlueprintToString(blueprint, stateMap, options?)`** is a one-shot render of values you
|
|
37
|
+
already have.
|
|
38
|
+
- **`TerminalRenderer(projectionRuntime, options?)`** with `render(blueprint, executionId)` reads each
|
|
39
|
+
of the blueprint's projections from a `ProjectionRuntime`, then renders.
|
|
40
|
+
- **`defaultTerminalRegistry`** covers the eight built-in widget kinds. `RendererRegistry` is
|
|
41
|
+
re-exported for registering your own `TerminalWidgetRenderer`, `(widget, value, status?) => string`.
|
|
42
|
+
- **Options.** `registry` and `check`. `check` is a `WidgetValueCheck` you supply to validate a bound
|
|
43
|
+
value; it runs only for widgets whose binding declares a status channel, and a finding renders as the
|
|
44
|
+
error row. Loom validates nothing about the value itself.
|
|
45
|
+
|
|
46
|
+
## Behaviour that surprises people
|
|
47
|
+
|
|
48
|
+
- **Without a `registry` it is kind-blind.** Every widget prints as `title: value`, and an unknown kind
|
|
49
|
+
is not noticed. With a registry, a kind it lacks is prefixed `[kind]` so the gap is visible.
|
|
50
|
+
- **It is not live.** Output is a string for one moment; re-render to update. For live updates use the
|
|
51
|
+
DOM or React renderer.
|
|
52
|
+
- **Layout hints are partly ignored.** Placed grid cells print in reading order (row, then column), and
|
|
53
|
+
a titled layout prints an underlined heading. `Layout.role` and `Layout.id` have no effect on the text.
|
|
54
|
+
- **A widget with no status channel and no `source` renders as it did before status existed.** A
|
|
55
|
+
channel adds the glyphs (`⋯` pending or loading, `~` stale, `✗` error, `○` empty), and `source` adds a
|
|
56
|
+
"(degraded from ...)" suffix to the first line.
|
|
57
|
+
- **A widget withheld for the surface's audience** prints a constant marker, with no title or value.
|
|
58
|
+
|
|
59
|
+
## Status / See also
|
|
60
|
+
|
|
61
|
+
Unpublished for now: inside this repo use `workspace:*`; from a sibling checkout use a `link:` override
|
|
62
|
+
(see [AGENTS.md](../../AGENTS.md)).
|
|
63
|
+
|
|
64
|
+
- [ADR 0097](../../docs/adr/0097-blueprint-ir-2.md), [ADR 0098](../../docs/adr/0098-blueprint-ir-placement-and-titles.md)
|
|
65
|
+
and [ADR 0099](../../docs/adr/0099-blueprint-ir-layout-roles.md): the status matrix, placement, roles.
|
|
66
|
+
- Siblings: [`@loomwork/plugin-renderer-react`](../renderer-react/README.md) and `@loomwork/plugin-renderer-dom`.
|
|
67
|
+
- API reference: section "`@loomwork/plugin-renderer-terminal`" in
|
|
68
|
+
[docs/api-reference.org](../../docs/api-reference.org).
|
|
69
|
+
- Guides: [docs/user-guide.md](../../docs/user-guide.md), [docs/README.md](../../docs/README.md).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BindingStatus, RendererRegistry, type Widget } from "@loomwork/blueprint-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* One widget kind, rendered to a block of text. Multi-line output is the renderer's own.
|
|
4
|
+
*
|
|
5
|
+
* A renderer that returns `""` makes its widget vanish: `renderContainer` filters out empty
|
|
6
|
+
* children, so an empty string is indistinguishable from "nothing here" rather than "rendered,
|
|
7
|
+
* and empty." Return a marker (e.g. `"(empty)"` or `"—"`), never an empty string.
|
|
8
|
+
*/
|
|
9
|
+
export type TerminalWidgetRenderer = (widget: Widget, value: unknown, status?: BindingStatus) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Renderers for the eight kinds `@loomwork/blueprint-runtime` ships. Merge your own on top.
|
|
12
|
+
*
|
|
13
|
+
* Shared, process-wide. Do not `.register()` on it — that mutates it for every consumer,
|
|
14
|
+
* including `@loomwork/sdk` re-exports. Build yours with `defaultTerminalRegistry.merge(mine)`,
|
|
15
|
+
* which returns a new registry.
|
|
16
|
+
*/
|
|
17
|
+
export declare const defaultTerminalRegistry: RendererRegistry<TerminalWidgetRenderer>;
|
|
18
|
+
//# sourceMappingURL=defaultRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultRegistry.d.ts","sourceRoot":"","sources":["../src/defaultRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,gBAAgB,EAAE,KAAK,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAWhG;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,MAAM,CAAC,EAAE,aAAa,KACnB,MAAM,CAAC;AA+EZ;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAAgB,CAAC,sBAAsB,CAShC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultTerminalRegistry = void 0;
|
|
4
|
+
const blueprint_runtime_1 = require("@loomwork/blueprint-runtime");
|
|
5
|
+
const format_1 = require("./format");
|
|
6
|
+
const BAR_CELLS = 20;
|
|
7
|
+
const title = (w) => w.title ?? w.kind;
|
|
8
|
+
const block = (heading, body) => body.includes("\n") ? `${heading}:\n${(0, format_1.indent)(body, " ")}` : `${heading}: ${body}`;
|
|
9
|
+
const metricCard = (w, v) => {
|
|
10
|
+
const unit = typeof w.props.unit === "string" ? ` ${w.props.unit}` : "";
|
|
11
|
+
if (v === null || v === undefined)
|
|
12
|
+
return `${title(w)}: —`;
|
|
13
|
+
const body = (0, format_1.formatValue)(v);
|
|
14
|
+
return body.includes("\n") ? block(`${title(w)}${unit}`, body) : `${title(w)}: ${body}${unit}`;
|
|
15
|
+
};
|
|
16
|
+
const statusBadge = (w, v) => `${title(w)}: [${v === null || v === undefined ? "—" : (0, format_1.formatValue)(v)}]`;
|
|
17
|
+
const progressBar = (w, v) => {
|
|
18
|
+
if (typeof v !== "number" || Number.isNaN(v))
|
|
19
|
+
return `${title(w)}: —`;
|
|
20
|
+
const max = typeof w.props.max === "number" && w.props.max > 0 ? w.props.max : 100;
|
|
21
|
+
const ratio = Math.min(1, Math.max(0, v / max));
|
|
22
|
+
const filled = Math.round(ratio * BAR_CELLS);
|
|
23
|
+
const pct = Math.round(ratio * 100);
|
|
24
|
+
return `${title(w)}: [${"#".repeat(filled)}${"-".repeat(BAR_CELLS - filled)}] ${pct}%`;
|
|
25
|
+
};
|
|
26
|
+
const timeline = (w, v) => {
|
|
27
|
+
if (!Array.isArray(v))
|
|
28
|
+
return block(title(w), (0, format_1.formatValue)(v));
|
|
29
|
+
const maxItems = w.props.maxItems;
|
|
30
|
+
const max = typeof maxItems === "number" && Number.isInteger(maxItems) && maxItems > 0
|
|
31
|
+
? maxItems
|
|
32
|
+
: v.length;
|
|
33
|
+
return block(title(w), (0, format_1.formatValue)(v.slice(0, max)));
|
|
34
|
+
};
|
|
35
|
+
const isRow = (r) => typeof r === "object" && r !== null;
|
|
36
|
+
const dataTable = (w, v) => {
|
|
37
|
+
if (!Array.isArray(v))
|
|
38
|
+
return block(title(w), (0, format_1.formatValue)(v));
|
|
39
|
+
if (v.length === 0)
|
|
40
|
+
return `${title(w)}: (empty)`;
|
|
41
|
+
const objectRows = v.filter(isRow);
|
|
42
|
+
const declared = Array.isArray(w.props.columns) ? w.props.columns : undefined;
|
|
43
|
+
const columns = declared ?? Object.keys(objectRows[0] ?? {});
|
|
44
|
+
if (columns.length === 0)
|
|
45
|
+
return block(title(w), (0, format_1.formatValue)(v));
|
|
46
|
+
const lines = [
|
|
47
|
+
columns.join(" | "),
|
|
48
|
+
...v.map((r) => isRow(r) ? columns.map((c) => String(r[c] ?? "—")).join(" | ") : `[non-row] ${(0, format_1.formatValue)(r)}`),
|
|
49
|
+
];
|
|
50
|
+
return block(title(w), lines.join("\n"));
|
|
51
|
+
};
|
|
52
|
+
const alertCard = (w, v) => {
|
|
53
|
+
const severity = typeof w.props.severity === "string" ? w.props.severity : "info";
|
|
54
|
+
const body = (0, format_1.formatValue)(v);
|
|
55
|
+
return body.includes("\n")
|
|
56
|
+
? block(`${severity.toUpperCase()} ${title(w)}`, body)
|
|
57
|
+
: `${severity.toUpperCase()} ${title(w)}: ${body}`;
|
|
58
|
+
};
|
|
59
|
+
const approvalCard = (w, v) => {
|
|
60
|
+
const approve = typeof w.props.approveLabel === "string" ? w.props.approveLabel : "Approve";
|
|
61
|
+
const reject = typeof w.props.rejectLabel === "string" ? w.props.rejectLabel : "Reject";
|
|
62
|
+
const body = (0, format_1.formatValue)(v);
|
|
63
|
+
return body.includes("\n")
|
|
64
|
+
? block(`${title(w)} (${approve} / ${reject})`, body)
|
|
65
|
+
: `${title(w)}: ${body} (${approve} / ${reject})`;
|
|
66
|
+
};
|
|
67
|
+
const streamingText = (w, v) => {
|
|
68
|
+
if (v !== null && v !== undefined && v !== "")
|
|
69
|
+
return `${title(w)}: ${String(v)}`;
|
|
70
|
+
const placeholder = typeof w.props.placeholder === "string" ? w.props.placeholder : "…";
|
|
71
|
+
return `${title(w)}: ${placeholder}`;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Renderers for the eight kinds `@loomwork/blueprint-runtime` ships. Merge your own on top.
|
|
75
|
+
*
|
|
76
|
+
* Shared, process-wide. Do not `.register()` on it — that mutates it for every consumer,
|
|
77
|
+
* including `@loomwork/sdk` re-exports. Build yours with `defaultTerminalRegistry.merge(mine)`,
|
|
78
|
+
* which returns a new registry.
|
|
79
|
+
*/
|
|
80
|
+
exports.defaultTerminalRegistry = new blueprint_runtime_1.RendererRegistry()
|
|
81
|
+
.register("MetricCard", metricCard)
|
|
82
|
+
.register("StatusBadge", statusBadge)
|
|
83
|
+
.register("ProgressBar", progressBar)
|
|
84
|
+
.register("Timeline", timeline)
|
|
85
|
+
.register("DataTable", dataTable)
|
|
86
|
+
.register("AlertCard", alertCard)
|
|
87
|
+
.register("ApprovalCard", approvalCard)
|
|
88
|
+
.register("StreamingText", streamingText);
|
|
89
|
+
//# sourceMappingURL=defaultRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultRegistry.js","sourceRoot":"","sources":["../src/defaultRegistry.ts"],"names":[],"mappings":";;;AAAA,mEAAgG;AAChG,qCAA+C;AAuB/C,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,MAAM,KAAK,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC;AAEvD,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,IAAY,EAAU,EAAE,CACtD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,MAAM,IAAA,eAAM,EAAC,IAAI,EAAE,MAAM,CAAC,EAA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AG,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgBlD"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Text formatting shared by the kind-blind fallback and the kind-aware default renderers.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.indent = indent;
|
|
5
|
+
exports.formatValue = formatValue;
|
|
6
|
+
function indent(text, pad) {
|
|
7
|
+
return text
|
|
8
|
+
.split("\n")
|
|
9
|
+
.map((line) => (line.length > 0 ? pad + line : line))
|
|
10
|
+
.join("\n");
|
|
11
|
+
}
|
|
12
|
+
function formatValue(value) {
|
|
13
|
+
if (value === null || value === undefined)
|
|
14
|
+
return "—";
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
if (value.length === 0)
|
|
17
|
+
return "(empty)";
|
|
18
|
+
return value
|
|
19
|
+
.map((item) => typeof item === "object" && item !== null
|
|
20
|
+
? `• ${Object.values(item)
|
|
21
|
+
.map(String)
|
|
22
|
+
.join(" · ")}`
|
|
23
|
+
: `• ${String(item)}`)
|
|
24
|
+
.join("\n");
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "object")
|
|
27
|
+
return JSON.stringify(value);
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";AAAA,0FAA0F;;AAE1F,wBAKC;AAED,kCAgBC;AAvBD,SAAgB,MAAM,CAAC,IAAY,EAAE,GAAW;IAC9C,OAAO,IAAI;SACR,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACpD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAgB,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC;IACtD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QACzC,OAAO,KAAK;aACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;YACvC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAA+B,CAAC;iBAChD,GAAG,CAAC,MAAM,CAAC;iBACX,IAAI,CAAC,KAAK,CAAC,EAAE;YAClB,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CACxB;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { renderBlueprintToString, TerminalRenderer } from "./renderBlueprint";
|
|
2
|
+
export type { TerminalRenderOptions, WidgetValueCheck } from "./renderBlueprint";
|
|
3
|
+
export { defaultTerminalRegistry } from "./defaultRegistry";
|
|
4
|
+
export type { TerminalWidgetRenderer } from "./defaultRegistry";
|
|
5
|
+
export { RendererRegistry } from "@loomwork/blueprint-runtime";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RendererRegistry = exports.defaultTerminalRegistry = exports.TerminalRenderer = exports.renderBlueprintToString = void 0;
|
|
4
|
+
var renderBlueprint_1 = require("./renderBlueprint");
|
|
5
|
+
Object.defineProperty(exports, "renderBlueprintToString", { enumerable: true, get: function () { return renderBlueprint_1.renderBlueprintToString; } });
|
|
6
|
+
Object.defineProperty(exports, "TerminalRenderer", { enumerable: true, get: function () { return renderBlueprint_1.TerminalRenderer; } });
|
|
7
|
+
var defaultRegistry_1 = require("./defaultRegistry");
|
|
8
|
+
Object.defineProperty(exports, "defaultTerminalRegistry", { enumerable: true, get: function () { return defaultRegistry_1.defaultTerminalRegistry; } });
|
|
9
|
+
// Re-export so callers can do: import { RendererRegistry } from "@loomwork/plugin-renderer-terminal"
|
|
10
|
+
var blueprint_runtime_1 = require("@loomwork/blueprint-runtime");
|
|
11
|
+
Object.defineProperty(exports, "RendererRegistry", { enumerable: true, get: function () { return blueprint_runtime_1.RendererRegistry; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA8E;AAArE,0HAAA,uBAAuB,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AAElD,qDAA4D;AAAnD,0HAAA,uBAAuB,OAAA;AAEhC,qGAAqG;AACrG,iEAA+D;AAAtD,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Blueprint, RendererRegistry, WidgetValueCheck } from "@loomwork/blueprint-runtime";
|
|
2
|
+
import type { ProjectionRuntime } from "@loomwork/projection-runtime";
|
|
3
|
+
import type { TerminalWidgetRenderer } from "./defaultRegistry";
|
|
4
|
+
/**
|
|
5
|
+
* A caller-supplied value-contract check — the documented slot the canonical status matrix
|
|
6
|
+
* leaves between `error` and `stale` (design §5). loom validates nothing about a bound VALUE
|
|
7
|
+
* itself: what a `Trend` or an `Investigation` must look like is a framework's catalogue
|
|
8
|
+
* vocabulary, not the IR's. A framework plugs its own `checkKindValue` in here and a failure
|
|
9
|
+
* renders as the error row, outranking `stale`, `pending` and `ready` — the value is wrong, so
|
|
10
|
+
* showing it (or a staleness marker about it) would be worse than saying so.
|
|
11
|
+
*
|
|
12
|
+
* Returning `undefined` means "nothing to say"; the normal matrix then applies.
|
|
13
|
+
*/
|
|
14
|
+
export type { WidgetValueCheck };
|
|
15
|
+
export interface TerminalRenderOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Kind-aware renderers. Absent → the kind-blind `title: value` output (unchanged since the
|
|
18
|
+
* plugin shipped). Present → a registered kind renders through its renderer, and a kind the
|
|
19
|
+
* registry LACKS is prefixed `[kind]` so the gap is visible on the surface rather than
|
|
20
|
+
* flattened away. `defaultTerminalRegistry` covers loom's eight built-ins.
|
|
21
|
+
*/
|
|
22
|
+
registry?: RendererRegistry<TerminalWidgetRenderer>;
|
|
23
|
+
/**
|
|
24
|
+
* Value-contract check, run between `error` and `stale` in the canonical matrix, and ONLY for
|
|
25
|
+
* a widget whose binding declares a status channel (a widget with no channel renders exactly
|
|
26
|
+
* as it did under IR 1.0.0, which is a property this option must not break). A delivery
|
|
27
|
+
* `error` already outranks it — there is no value to check when the fetch itself failed.
|
|
28
|
+
*/
|
|
29
|
+
check?: WidgetValueCheck;
|
|
30
|
+
}
|
|
31
|
+
export declare function renderBlueprintToString(blueprint: Blueprint, stateMap: Map<string, unknown>, options?: TerminalRenderOptions): string;
|
|
32
|
+
export declare class TerminalRenderer {
|
|
33
|
+
private readonly projectionRuntime;
|
|
34
|
+
private readonly options;
|
|
35
|
+
constructor(projectionRuntime: ProjectionRuntime, options?: TerminalRenderOptions);
|
|
36
|
+
render(blueprint: Blueprint, executionId: string): string;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=renderBlueprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderBlueprint.d.ts","sourceRoot":"","sources":["../src/renderBlueprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,SAAS,EAET,gBAAgB,EAEhB,gBAAgB,EACjB,MAAM,6BAA6B,CAAC;AAMrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAGhE;;;;;;;;;GASG;AACH,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACpD;;;;;OAKG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAsCD,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,GAAE,qBAA0B,GAClC,MAAM,CA6DR;AAID,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,iBAAiB,EAAE,iBAAiB,EACpC,OAAO,GAAE,qBAA0B;IAGtD,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;CAO1D"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TerminalRenderer = void 0;
|
|
4
|
+
exports.renderBlueprintToString = renderBlueprintToString;
|
|
5
|
+
const blueprint_runtime_1 = require("@loomwork/blueprint-runtime");
|
|
6
|
+
const format_1 = require("./format");
|
|
7
|
+
// The kind-blind rendering: `title: value`, multi-line values indented under the title.
|
|
8
|
+
function renderKindBlind(widget, value) {
|
|
9
|
+
const title = widget.title ?? widget.kind;
|
|
10
|
+
const rendered = (0, format_1.formatValue)(value);
|
|
11
|
+
return rendered.includes("\n")
|
|
12
|
+
? `${title}:\n${(0, format_1.indent)(rendered, " ")}`
|
|
13
|
+
: `${title}: ${rendered}`;
|
|
14
|
+
}
|
|
15
|
+
const isPlaced = (c) => c.row !== undefined || c.rowSpan !== undefined || c.column !== undefined;
|
|
16
|
+
// A text surface has one column, so honouring placement (IR 2.1.0, ADR 0098) means READING
|
|
17
|
+
// order: row, then column. An absent coordinate sorts after every present one, and the sort is
|
|
18
|
+
// stable, so ties keep document order. Only called when a cell is placed — an unplaced grid
|
|
19
|
+
// keeps document order and its output is byte-identical to 2.0.0.
|
|
20
|
+
function readingOrder(cells) {
|
|
21
|
+
const at = (v) => (v === undefined ? Number.POSITIVE_INFINITY : v);
|
|
22
|
+
// When BOTH sides are absent on an axis, `Infinity - Infinity` is NaN — falsy in `||` — so the
|
|
23
|
+
// comparator falls through to the next key instead of reporting a (wrong) tie-breaking order.
|
|
24
|
+
return cells
|
|
25
|
+
.map((c, i) => ({ c, i }))
|
|
26
|
+
.sort((x, y) => at(x.c.row) - at(y.c.row) || at(x.c.column) - at(y.c.column) || x.i - y.i)
|
|
27
|
+
.map(({ c }) => c.child);
|
|
28
|
+
}
|
|
29
|
+
// Renders a blueprint to plain text using the framework-agnostic traverseBlueprint<string>
|
|
30
|
+
// walker — the same tree, a different surface.
|
|
31
|
+
//
|
|
32
|
+
// Without a registry this renderer is KIND-BLIND: it flattens every widget to `title: value`.
|
|
33
|
+
// That is legitimate for a text surface, but it cannot fail on an unknown kind because it never
|
|
34
|
+
// looks, so it degrades SILENTLY. With a registry it looks: a registered kind renders through its
|
|
35
|
+
// renderer and an unregistered one is MARKED. `defaultTerminalRegistry` covers the built-in
|
|
36
|
+
// catalogue, and `catalogCoverage` is how a caller proves theirs does (ADR 0088, ADR 0096).
|
|
37
|
+
function renderBlueprintToString(blueprint, stateMap, options = {}) {
|
|
38
|
+
const registry = options.registry;
|
|
39
|
+
const check = options.check;
|
|
40
|
+
const body = (0, blueprint_runtime_1.traverseBlueprint)(blueprint.layout, stateMap, {
|
|
41
|
+
renderWidget({ widget, value, status, }) {
|
|
42
|
+
// One registry lookup, not two: `get` is a caller-supplied registry's method, so calling
|
|
43
|
+
// it twice per widget is both wasted work and an assumption that it is pure.
|
|
44
|
+
const renderer = registry?.get(widget.kind);
|
|
45
|
+
const inner = () => registry === undefined
|
|
46
|
+
? renderKindBlind(widget, value)
|
|
47
|
+
: renderer
|
|
48
|
+
? renderer(widget, value, status)
|
|
49
|
+
: `[${widget.kind}] ${renderKindBlind(widget, value)}`;
|
|
50
|
+
const title = widget.title ?? widget.kind;
|
|
51
|
+
// The decision is shared (`describeWidgetStatus`); this renderer owns only the text.
|
|
52
|
+
const d = (0, blueprint_runtime_1.describeWidgetStatus)(widget, value, status, check);
|
|
53
|
+
// A malformed `source` is the error placeholder (as DOM and React), never a throw.
|
|
54
|
+
if (d.tag === "invalid")
|
|
55
|
+
return `[Renderer for ${widget.kind} failed]`;
|
|
56
|
+
// IR 2.5.0: withheld for the surface's audience — a constant marker, no title, no value.
|
|
57
|
+
const m = (0, blueprint_runtime_1.describeWidgetFrame)(widget, d).marker;
|
|
58
|
+
if (d.tag === "redacted")
|
|
59
|
+
return m?.text ?? "";
|
|
60
|
+
let text;
|
|
61
|
+
if (d.tag === "inert")
|
|
62
|
+
text = inner();
|
|
63
|
+
else if (d.tag === "error" || d.tag === "empty")
|
|
64
|
+
text = m?.text ?? "";
|
|
65
|
+
else if (d.tag === "stale")
|
|
66
|
+
text = d.hasValue ? `${m?.glyph} ${inner()}` : `${m?.glyph} ${title}: — (${d.message})`;
|
|
67
|
+
else if (d.tag === "pending")
|
|
68
|
+
text = `${m?.glyph} ${inner()}`;
|
|
69
|
+
// `loading`: the same glyph React and loom-ui's Lit base use (ADR 0097 D2).
|
|
70
|
+
else if (d.tag === "loading")
|
|
71
|
+
text = `⋯ ${title}`;
|
|
72
|
+
else
|
|
73
|
+
text = inner();
|
|
74
|
+
if (d.degradedChain) {
|
|
75
|
+
const [first, ...rest] = text.split("\n");
|
|
76
|
+
text = [`${first} (degraded from ${d.degradedChain})`, ...rest].join("\n");
|
|
77
|
+
}
|
|
78
|
+
return text;
|
|
79
|
+
},
|
|
80
|
+
renderContainer({ layout, children, cells }) {
|
|
81
|
+
// `layout.role` (IR 2.2.0, ADR 0099) is ignored on purpose: a role is an interaction hint,
|
|
82
|
+
// and every child under the title, in reading order, is already the whole content.
|
|
83
|
+
// `layout.id` (IR 2.4.0, ADR 0101) is ignored too: a one-shot string has nothing to
|
|
84
|
+
// reconcile, so a container's identity cannot change a byte of it.
|
|
85
|
+
const ordered = cells?.some(isPlaced) ? readingOrder(cells) : children;
|
|
86
|
+
const body = ordered.filter((c) => c.length > 0).join("\n");
|
|
87
|
+
const title = typeof layout.title === "string" && layout.title !== "" ? layout.title : "";
|
|
88
|
+
if (title === "")
|
|
89
|
+
return body;
|
|
90
|
+
const heading = `${title}\n${"─".repeat(title.length)}`;
|
|
91
|
+
return body.length > 0 ? `${heading}\n${body}` : heading;
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
const bar = "═".repeat(Math.max(blueprint.title.length + 2, 24));
|
|
95
|
+
return `${bar}\n ${blueprint.title}\n${bar}\n${body}\n`;
|
|
96
|
+
}
|
|
97
|
+
// Convenience wrapper that pulls each of a blueprint's projections from a
|
|
98
|
+
// ProjectionRuntime for a given execution, then renders to text.
|
|
99
|
+
class TerminalRenderer {
|
|
100
|
+
projectionRuntime;
|
|
101
|
+
options;
|
|
102
|
+
constructor(projectionRuntime, options = {}) {
|
|
103
|
+
this.projectionRuntime = projectionRuntime;
|
|
104
|
+
this.options = options;
|
|
105
|
+
}
|
|
106
|
+
render(blueprint, executionId) {
|
|
107
|
+
const stateMap = new Map();
|
|
108
|
+
for (const projectionId of blueprint.projections) {
|
|
109
|
+
stateMap.set(projectionId, this.projectionRuntime.getState(projectionId, executionId));
|
|
110
|
+
}
|
|
111
|
+
return renderBlueprintToString(blueprint, stateMap, this.options);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.TerminalRenderer = TerminalRenderer;
|
|
115
|
+
//# sourceMappingURL=renderBlueprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderBlueprint.js","sourceRoot":"","sources":["../src/renderBlueprint.ts"],"names":[],"mappings":";;;AAkFA,0DAiEC;AA3ID,mEAIqC;AAGrC,qCAA+C;AA+B/C,wFAAwF;AACxF,SAAS,eAAe,CAAC,MAAc,EAAE,KAAc;IACrD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,KAAK,CAAC,CAAC;IACpC,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC5B,CAAC,CAAC,GAAG,KAAK,MAAM,IAAA,eAAM,EAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;QAC1C,CAAC,CAAC,GAAG,KAAK,KAAK,QAAQ,EAAE,CAAC;AAC9B,CAAC;AAID,MAAM,QAAQ,GAAG,CAAC,CAAgB,EAAW,EAAE,CAC7C,CAAC,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,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;CACF;AAbD,4CAaC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomwork/plugin-renderer-terminal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Terminal/string surface renderer for Loom blueprints — proves multi-surface delivery",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@loomwork/blueprint-runtime": "^0.1.1",
|
|
16
|
+
"@loomwork/projection-runtime": "^0.1.1"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^22.0.0",
|
|
20
|
+
"typescript": "^5.6.3",
|
|
21
|
+
"vitest": "^2.1.8",
|
|
22
|
+
"@loomwork/core": "0.1.1"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/chhetrisushil/loom.git",
|
|
28
|
+
"directory": "plugins/renderer-terminal"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"src",
|
|
33
|
+
"!src/**/*.test.ts",
|
|
34
|
+
"!src/**/*.test.tsx",
|
|
35
|
+
"!src/**/__tests__",
|
|
36
|
+
"!src/**/__fixtures__",
|
|
37
|
+
"!src/**/__snapshots__",
|
|
38
|
+
"!src/**/__golden__",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"NOTICE"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"tag": "next"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build",
|
|
51
|
+
"dev": "tsc --build --watch",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest",
|
|
54
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
55
|
+
"typecheck:tests": "tsc -p tsconfig.test.json"
|
|
56
|
+
}
|
|
6
57
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type BindingStatus, RendererRegistry, type Widget } from "@loomwork/blueprint-runtime";
|
|
2
|
+
import { formatValue, indent } from "./format";
|
|
3
|
+
|
|
4
|
+
// ── Kind-aware terminal renderers for loom's eight built-in widgets ──────────
|
|
5
|
+
//
|
|
6
|
+
// The terminal renderer used to be kind-blind: `title: value` for everything, so it could not
|
|
7
|
+
// fail on a kind it did not know — and could not render a progress bar as anything but a number.
|
|
8
|
+
// ADR 0088 asks the second question of every surface — does it cover the catalogue? — and
|
|
9
|
+
// `defaultRegistry.test.ts` asks it of this one with `catalogCoverage(builtinCatalog, …)`.
|
|
10
|
+
// Adding a kind to `WidgetKind` without a renderer here fails that test.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* One widget kind, rendered to a block of text. Multi-line output is the renderer's own.
|
|
14
|
+
*
|
|
15
|
+
* A renderer that returns `""` makes its widget vanish: `renderContainer` filters out empty
|
|
16
|
+
* children, so an empty string is indistinguishable from "nothing here" rather than "rendered,
|
|
17
|
+
* and empty." Return a marker (e.g. `"(empty)"` or `"—"`), never an empty string.
|
|
18
|
+
*/
|
|
19
|
+
export type TerminalWidgetRenderer = (
|
|
20
|
+
widget: Widget,
|
|
21
|
+
value: unknown,
|
|
22
|
+
status?: BindingStatus
|
|
23
|
+
) => string;
|
|
24
|
+
|
|
25
|
+
const BAR_CELLS = 20;
|
|
26
|
+
|
|
27
|
+
const title = (w: Widget): string => w.title ?? w.kind;
|
|
28
|
+
|
|
29
|
+
const block = (heading: string, body: string): string =>
|
|
30
|
+
body.includes("\n") ? `${heading}:\n${indent(body, " ")}` : `${heading}: ${body}`;
|
|
31
|
+
|
|
32
|
+
const metricCard: TerminalWidgetRenderer = (w, v) => {
|
|
33
|
+
const unit = typeof w.props.unit === "string" ? ` ${w.props.unit}` : "";
|
|
34
|
+
if (v === null || v === undefined) return `${title(w)}: —`;
|
|
35
|
+
const body = formatValue(v);
|
|
36
|
+
return body.includes("\n") ? block(`${title(w)}${unit}`, body) : `${title(w)}: ${body}${unit}`;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const statusBadge: TerminalWidgetRenderer = (w, v) =>
|
|
40
|
+
`${title(w)}: [${v === null || v === undefined ? "—" : formatValue(v)}]`;
|
|
41
|
+
|
|
42
|
+
const progressBar: TerminalWidgetRenderer = (w, v) => {
|
|
43
|
+
if (typeof v !== "number" || Number.isNaN(v)) return `${title(w)}: —`;
|
|
44
|
+
const max = typeof w.props.max === "number" && w.props.max > 0 ? w.props.max : 100;
|
|
45
|
+
const ratio = Math.min(1, Math.max(0, v / max));
|
|
46
|
+
const filled = Math.round(ratio * BAR_CELLS);
|
|
47
|
+
const pct = Math.round(ratio * 100);
|
|
48
|
+
return `${title(w)}: [${"#".repeat(filled)}${"-".repeat(BAR_CELLS - filled)}] ${pct}%`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const timeline: TerminalWidgetRenderer = (w, v) => {
|
|
52
|
+
if (!Array.isArray(v)) return block(title(w), formatValue(v));
|
|
53
|
+
const maxItems = w.props.maxItems;
|
|
54
|
+
const max =
|
|
55
|
+
typeof maxItems === "number" && Number.isInteger(maxItems) && maxItems > 0
|
|
56
|
+
? maxItems
|
|
57
|
+
: v.length;
|
|
58
|
+
return block(title(w), formatValue(v.slice(0, max)));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const isRow = (r: unknown): r is Record<string, unknown> => typeof r === "object" && r !== null;
|
|
62
|
+
|
|
63
|
+
const dataTable: TerminalWidgetRenderer = (w, v) => {
|
|
64
|
+
if (!Array.isArray(v)) return block(title(w), formatValue(v));
|
|
65
|
+
if (v.length === 0) return `${title(w)}: (empty)`;
|
|
66
|
+
const objectRows = v.filter(isRow);
|
|
67
|
+
const declared = Array.isArray(w.props.columns) ? (w.props.columns as string[]) : undefined;
|
|
68
|
+
const columns = declared ?? Object.keys(objectRows[0] ?? {});
|
|
69
|
+
if (columns.length === 0) return block(title(w), formatValue(v));
|
|
70
|
+
const lines = [
|
|
71
|
+
columns.join(" | "),
|
|
72
|
+
...v.map((r) =>
|
|
73
|
+
isRow(r) ? columns.map((c) => String(r[c] ?? "—")).join(" | ") : `[non-row] ${formatValue(r)}`
|
|
74
|
+
),
|
|
75
|
+
];
|
|
76
|
+
return block(title(w), lines.join("\n"));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const alertCard: TerminalWidgetRenderer = (w, v) => {
|
|
80
|
+
const severity = typeof w.props.severity === "string" ? w.props.severity : "info";
|
|
81
|
+
const body = formatValue(v);
|
|
82
|
+
return body.includes("\n")
|
|
83
|
+
? block(`${severity.toUpperCase()} ${title(w)}`, body)
|
|
84
|
+
: `${severity.toUpperCase()} ${title(w)}: ${body}`;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const approvalCard: TerminalWidgetRenderer = (w, v) => {
|
|
88
|
+
const approve = typeof w.props.approveLabel === "string" ? w.props.approveLabel : "Approve";
|
|
89
|
+
const reject = typeof w.props.rejectLabel === "string" ? w.props.rejectLabel : "Reject";
|
|
90
|
+
const body = formatValue(v);
|
|
91
|
+
return body.includes("\n")
|
|
92
|
+
? block(`${title(w)} (${approve} / ${reject})`, body)
|
|
93
|
+
: `${title(w)}: ${body} (${approve} / ${reject})`;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const streamingText: TerminalWidgetRenderer = (w, v) => {
|
|
97
|
+
if (v !== null && v !== undefined && v !== "") return `${title(w)}: ${String(v)}`;
|
|
98
|
+
const placeholder = typeof w.props.placeholder === "string" ? w.props.placeholder : "…";
|
|
99
|
+
return `${title(w)}: ${placeholder}`;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Renderers for the eight kinds `@loomwork/blueprint-runtime` ships. Merge your own on top.
|
|
104
|
+
*
|
|
105
|
+
* Shared, process-wide. Do not `.register()` on it — that mutates it for every consumer,
|
|
106
|
+
* including `@loomwork/sdk` re-exports. Build yours with `defaultTerminalRegistry.merge(mine)`,
|
|
107
|
+
* which returns a new registry.
|
|
108
|
+
*/
|
|
109
|
+
export const defaultTerminalRegistry: RendererRegistry<TerminalWidgetRenderer> =
|
|
110
|
+
new RendererRegistry<TerminalWidgetRenderer>()
|
|
111
|
+
.register("MetricCard", metricCard)
|
|
112
|
+
.register("StatusBadge", statusBadge)
|
|
113
|
+
.register("ProgressBar", progressBar)
|
|
114
|
+
.register("Timeline", timeline)
|
|
115
|
+
.register("DataTable", dataTable)
|
|
116
|
+
.register("AlertCard", alertCard)
|
|
117
|
+
.register("ApprovalCard", approvalCard)
|
|
118
|
+
.register("StreamingText", streamingText);
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Text formatting shared by the kind-blind fallback and the kind-aware default renderers.
|
|
2
|
+
|
|
3
|
+
export function indent(text: string, pad: string): string {
|
|
4
|
+
return text
|
|
5
|
+
.split("\n")
|
|
6
|
+
.map((line) => (line.length > 0 ? pad + line : line))
|
|
7
|
+
.join("\n");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function formatValue(value: unknown): string {
|
|
11
|
+
if (value === null || value === undefined) return "—";
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
if (value.length === 0) return "(empty)";
|
|
14
|
+
return value
|
|
15
|
+
.map((item) =>
|
|
16
|
+
typeof item === "object" && item !== null
|
|
17
|
+
? `• ${Object.values(item as Record<string, unknown>)
|
|
18
|
+
.map(String)
|
|
19
|
+
.join(" · ")}`
|
|
20
|
+
: `• ${String(item)}`
|
|
21
|
+
)
|
|
22
|
+
.join("\n");
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
25
|
+
return String(value);
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { renderBlueprintToString, TerminalRenderer } from "./renderBlueprint";
|
|
2
|
+
export type { TerminalRenderOptions, WidgetValueCheck } from "./renderBlueprint";
|
|
3
|
+
export { defaultTerminalRegistry } from "./defaultRegistry";
|
|
4
|
+
export type { TerminalWidgetRenderer } from "./defaultRegistry";
|
|
5
|
+
// Re-export so callers can do: import { RendererRegistry } from "@loomwork/plugin-renderer-terminal"
|
|
6
|
+
export { RendererRegistry } from "@loomwork/blueprint-runtime";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BindingStatus,
|
|
3
|
+
Blueprint,
|
|
4
|
+
ContainerContext,
|
|
5
|
+
RendererRegistry,
|
|
6
|
+
Widget,
|
|
7
|
+
WidgetValueCheck,
|
|
8
|
+
} from "@loomwork/blueprint-runtime";
|
|
9
|
+
import {
|
|
10
|
+
describeWidgetFrame,
|
|
11
|
+
describeWidgetStatus,
|
|
12
|
+
traverseBlueprint,
|
|
13
|
+
} from "@loomwork/blueprint-runtime";
|
|
14
|
+
import type { ProjectionRuntime } from "@loomwork/projection-runtime";
|
|
15
|
+
import type { TerminalWidgetRenderer } from "./defaultRegistry";
|
|
16
|
+
import { formatValue, indent } from "./format";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A caller-supplied value-contract check — the documented slot the canonical status matrix
|
|
20
|
+
* leaves between `error` and `stale` (design §5). loom validates nothing about a bound VALUE
|
|
21
|
+
* itself: what a `Trend` or an `Investigation` must look like is a framework's catalogue
|
|
22
|
+
* vocabulary, not the IR's. A framework plugs its own `checkKindValue` in here and a failure
|
|
23
|
+
* renders as the error row, outranking `stale`, `pending` and `ready` — the value is wrong, so
|
|
24
|
+
* showing it (or a staleness marker about it) would be worse than saying so.
|
|
25
|
+
*
|
|
26
|
+
* Returning `undefined` means "nothing to say"; the normal matrix then applies.
|
|
27
|
+
*/
|
|
28
|
+
export type { WidgetValueCheck };
|
|
29
|
+
|
|
30
|
+
export interface TerminalRenderOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Kind-aware renderers. Absent → the kind-blind `title: value` output (unchanged since the
|
|
33
|
+
* plugin shipped). Present → a registered kind renders through its renderer, and a kind the
|
|
34
|
+
* registry LACKS is prefixed `[kind]` so the gap is visible on the surface rather than
|
|
35
|
+
* flattened away. `defaultTerminalRegistry` covers loom's eight built-ins.
|
|
36
|
+
*/
|
|
37
|
+
registry?: RendererRegistry<TerminalWidgetRenderer>;
|
|
38
|
+
/**
|
|
39
|
+
* Value-contract check, run between `error` and `stale` in the canonical matrix, and ONLY for
|
|
40
|
+
* a widget whose binding declares a status channel (a widget with no channel renders exactly
|
|
41
|
+
* as it did under IR 1.0.0, which is a property this option must not break). A delivery
|
|
42
|
+
* `error` already outranks it — there is no value to check when the fetch itself failed.
|
|
43
|
+
*/
|
|
44
|
+
check?: WidgetValueCheck;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The kind-blind rendering: `title: value`, multi-line values indented under the title.
|
|
48
|
+
function renderKindBlind(widget: Widget, value: unknown): string {
|
|
49
|
+
const title = widget.title ?? widget.kind;
|
|
50
|
+
const rendered = formatValue(value);
|
|
51
|
+
return rendered.includes("\n")
|
|
52
|
+
? `${title}:\n${indent(rendered, " ")}`
|
|
53
|
+
: `${title}: ${rendered}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type Cells = NonNullable<ContainerContext<string>["cells"]>;
|
|
57
|
+
|
|
58
|
+
const isPlaced = (c: Cells[number]): boolean =>
|
|
59
|
+
c.row !== undefined || c.rowSpan !== undefined || c.column !== undefined;
|
|
60
|
+
|
|
61
|
+
// A text surface has one column, so honouring placement (IR 2.1.0, ADR 0098) means READING
|
|
62
|
+
// order: row, then column. An absent coordinate sorts after every present one, and the sort is
|
|
63
|
+
// stable, so ties keep document order. Only called when a cell is placed — an unplaced grid
|
|
64
|
+
// keeps document order and its output is byte-identical to 2.0.0.
|
|
65
|
+
function readingOrder(cells: Cells): string[] {
|
|
66
|
+
const at = (v: number | undefined) => (v === undefined ? Number.POSITIVE_INFINITY : v);
|
|
67
|
+
// When BOTH sides are absent on an axis, `Infinity - Infinity` is NaN — falsy in `||` — so the
|
|
68
|
+
// comparator falls through to the next key instead of reporting a (wrong) tie-breaking order.
|
|
69
|
+
return cells
|
|
70
|
+
.map((c, i) => ({ c, i }))
|
|
71
|
+
.sort((x, y) => at(x.c.row) - at(y.c.row) || at(x.c.column) - at(y.c.column) || x.i - y.i)
|
|
72
|
+
.map(({ c }) => c.child);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Renders a blueprint to plain text using the framework-agnostic traverseBlueprint<string>
|
|
76
|
+
// walker — the same tree, a different surface.
|
|
77
|
+
//
|
|
78
|
+
// Without a registry this renderer is KIND-BLIND: it flattens every widget to `title: value`.
|
|
79
|
+
// That is legitimate for a text surface, but it cannot fail on an unknown kind because it never
|
|
80
|
+
// looks, so it degrades SILENTLY. With a registry it looks: a registered kind renders through its
|
|
81
|
+
// renderer and an unregistered one is MARKED. `defaultTerminalRegistry` covers the built-in
|
|
82
|
+
// catalogue, and `catalogCoverage` is how a caller proves theirs does (ADR 0088, ADR 0096).
|
|
83
|
+
export function renderBlueprintToString(
|
|
84
|
+
blueprint: Blueprint,
|
|
85
|
+
stateMap: Map<string, unknown>,
|
|
86
|
+
options: TerminalRenderOptions = {}
|
|
87
|
+
): string {
|
|
88
|
+
const registry = options.registry;
|
|
89
|
+
const check = options.check;
|
|
90
|
+
const body = traverseBlueprint<string>(blueprint.layout, stateMap, {
|
|
91
|
+
renderWidget({
|
|
92
|
+
widget,
|
|
93
|
+
value,
|
|
94
|
+
status,
|
|
95
|
+
}: {
|
|
96
|
+
widget: Widget;
|
|
97
|
+
value: unknown;
|
|
98
|
+
status?: BindingStatus;
|
|
99
|
+
}) {
|
|
100
|
+
// One registry lookup, not two: `get` is a caller-supplied registry's method, so calling
|
|
101
|
+
// it twice per widget is both wasted work and an assumption that it is pure.
|
|
102
|
+
const renderer = registry?.get(widget.kind);
|
|
103
|
+
const inner = (): string =>
|
|
104
|
+
registry === undefined
|
|
105
|
+
? renderKindBlind(widget, value)
|
|
106
|
+
: renderer
|
|
107
|
+
? renderer(widget, value, status)
|
|
108
|
+
: `[${widget.kind}] ${renderKindBlind(widget, value)}`;
|
|
109
|
+
const title = widget.title ?? widget.kind;
|
|
110
|
+
// The decision is shared (`describeWidgetStatus`); this renderer owns only the text.
|
|
111
|
+
const d = describeWidgetStatus(widget, value, status, check);
|
|
112
|
+
// A malformed `source` is the error placeholder (as DOM and React), never a throw.
|
|
113
|
+
if (d.tag === "invalid") return `[Renderer for ${widget.kind} failed]`;
|
|
114
|
+
// IR 2.5.0: withheld for the surface's audience — a constant marker, no title, no value.
|
|
115
|
+
const m = describeWidgetFrame(widget, d).marker;
|
|
116
|
+
if (d.tag === "redacted") return m?.text ?? "";
|
|
117
|
+
let text: string;
|
|
118
|
+
if (d.tag === "inert") text = inner();
|
|
119
|
+
else if (d.tag === "error" || d.tag === "empty") text = m?.text ?? "";
|
|
120
|
+
else if (d.tag === "stale")
|
|
121
|
+
text = d.hasValue ? `${m?.glyph} ${inner()}` : `${m?.glyph} ${title}: — (${d.message})`;
|
|
122
|
+
else if (d.tag === "pending") text = `${m?.glyph} ${inner()}`;
|
|
123
|
+
// `loading`: the same glyph React and loom-ui's Lit base use (ADR 0097 D2).
|
|
124
|
+
else if (d.tag === "loading") text = `⋯ ${title}`;
|
|
125
|
+
else text = inner();
|
|
126
|
+
if (d.degradedChain) {
|
|
127
|
+
const [first, ...rest] = text.split("\n");
|
|
128
|
+
text = [`${first} (degraded from ${d.degradedChain})`, ...rest].join("\n");
|
|
129
|
+
}
|
|
130
|
+
return text;
|
|
131
|
+
},
|
|
132
|
+
renderContainer({ layout, children, cells }: ContainerContext<string>) {
|
|
133
|
+
// `layout.role` (IR 2.2.0, ADR 0099) is ignored on purpose: a role is an interaction hint,
|
|
134
|
+
// and every child under the title, in reading order, is already the whole content.
|
|
135
|
+
// `layout.id` (IR 2.4.0, ADR 0101) is ignored too: a one-shot string has nothing to
|
|
136
|
+
// reconcile, so a container's identity cannot change a byte of it.
|
|
137
|
+
const ordered = cells?.some(isPlaced) ? readingOrder(cells) : children;
|
|
138
|
+
const body = ordered.filter((c) => c.length > 0).join("\n");
|
|
139
|
+
const title = typeof layout.title === "string" && layout.title !== "" ? layout.title : "";
|
|
140
|
+
if (title === "") return body;
|
|
141
|
+
const heading = `${title}\n${"─".repeat(title.length)}`;
|
|
142
|
+
return body.length > 0 ? `${heading}\n${body}` : heading;
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const bar = "═".repeat(Math.max(blueprint.title.length + 2, 24));
|
|
147
|
+
return `${bar}\n ${blueprint.title}\n${bar}\n${body}\n`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Convenience wrapper that pulls each of a blueprint's projections from a
|
|
151
|
+
// ProjectionRuntime for a given execution, then renders to text.
|
|
152
|
+
export class TerminalRenderer {
|
|
153
|
+
constructor(
|
|
154
|
+
private readonly projectionRuntime: ProjectionRuntime,
|
|
155
|
+
private readonly options: TerminalRenderOptions = {}
|
|
156
|
+
) {}
|
|
157
|
+
|
|
158
|
+
render(blueprint: Blueprint, executionId: string): string {
|
|
159
|
+
const stateMap = new Map<string, unknown>();
|
|
160
|
+
for (const projectionId of blueprint.projections) {
|
|
161
|
+
stateMap.set(projectionId, this.projectionRuntime.getState(projectionId, executionId));
|
|
162
|
+
}
|
|
163
|
+
return renderBlueprintToString(blueprint, stateMap, this.options);
|
|
164
|
+
}
|
|
165
|
+
}
|