@bimetal/output-headless 0.0.0-stage → 0.44.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/LICENSE +57 -0
- package/README.md +40 -2
- package/dist/ansi.d.ts +23 -0
- package/dist/ansi.d.ts.map +1 -0
- package/dist/ansi.js +113 -0
- package/dist/ansi.js.map +1 -0
- package/dist/create-controller.d.ts +3 -0
- package/dist/create-controller.d.ts.map +1 -0
- package/dist/create-controller.js +70 -0
- package/dist/create-controller.js.map +1 -0
- package/dist/gliederung.d.ts +15 -0
- package/dist/gliederung.d.ts.map +1 -0
- package/dist/gliederung.js +117 -0
- package/dist/gliederung.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Copyright 2026 Andreas Biederbeck
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
10
|
+
|
|
11
|
+
1. Definitions.
|
|
12
|
+
|
|
13
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
18
|
+
|
|
19
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
20
|
+
|
|
21
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
22
|
+
|
|
23
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
24
|
+
|
|
25
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
26
|
+
|
|
27
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
28
|
+
|
|
29
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
30
|
+
|
|
31
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
32
|
+
|
|
33
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
34
|
+
|
|
35
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
36
|
+
|
|
37
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
38
|
+
|
|
39
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
40
|
+
|
|
41
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
42
|
+
|
|
43
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
44
|
+
|
|
45
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
46
|
+
|
|
47
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
48
|
+
|
|
49
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
50
|
+
|
|
51
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
52
|
+
|
|
53
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
54
|
+
|
|
55
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
56
|
+
|
|
57
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bimetal/output-headless
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The canonical, framework-agnostic controller for **terminal and tool output** (bimetal #537).
|
|
4
|
+
Controller-only: no store, no aggregate, no undo, no domain dependency. Bindings for the five stacks
|
|
5
|
+
are a separate step; every decision (what is collapsed, what stays visible) lives here, a renderer
|
|
6
|
+
only displays the snapshot.
|
|
7
|
+
|
|
8
|
+
- `parseAnsi(text)` turns ANSI SGR (colour, bold, background) into styled spans without control
|
|
9
|
+
characters; every other sequence (cursor, erase, OSC hyperlinks/titles) is dropped. Extended colours
|
|
10
|
+
(`38;5;n`, `38;2;r;g;b`) consume their parameters and stay unnamed (`null`). `stripAnsi(text)` is the
|
|
11
|
+
plain text.
|
|
12
|
+
- `createOutputController({ text, config })` splits the output into named, collapsible sections:
|
|
13
|
+
- `command` — one per command line (`commandPattern`, default `/^\$ \S/`), titled by that line;
|
|
14
|
+
`collapsedCommands` start collapsed. Text before the first command is an `output` section
|
|
15
|
+
(`outputTitle`, default `'Output'`).
|
|
16
|
+
- `group` — a run of at least `minLines` (default 2) consecutive lines matching a group rule, titled
|
|
17
|
+
`"<name> (<count>)"`, collapsed unless the rule says `collapsed: false`.
|
|
18
|
+
- `truncation` — every line matching `truncationPattern` is its own section, never collapsible and
|
|
19
|
+
never swallowed by a collapsed command or group (`snapshot.truncated` says whether there is one).
|
|
20
|
+
|
|
21
|
+
When a group or a marker splits a command, the rest continues in a section of the same kind and
|
|
22
|
+
title with `continuationOf` = the id of the command's first section; all parts collapse together.
|
|
23
|
+
- `snapshot.excerpts` is the "most important first" excerpt: one entry per `excerpts` rule that has
|
|
24
|
+
matches, in rule order, with the matching lines (styled) in input order.
|
|
25
|
+
- `toggle(id)` / `setCollapsed(id, collapsed)` notify only on change; `setText(text)` replaces the
|
|
26
|
+
output and keeps the user's collapse state for sections that still exist (streaming).
|
|
27
|
+
|
|
28
|
+
All line patterns are matched against the text without control characters. `getSnapshot()` is
|
|
29
|
+
identity-stable until something changes (`useSyncExternalStore` contract).
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
const output = createOutputController({
|
|
33
|
+
text: vitestLog,
|
|
34
|
+
config: {
|
|
35
|
+
collapsedCommands: [/^\$ npm ci\b/],
|
|
36
|
+
groups: [{ name: 'passed', pattern: /^\s*✓\s/ }],
|
|
37
|
+
truncationPattern: /\[gekürzt: \d+ Zeichen\]/,
|
|
38
|
+
excerpts: [{ title: 'Failures', pattern: /^\s*FAIL\s/ }],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
package/dist/ansi.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ANSI-Sequenzen → gestaltete Spannen (bimetal #537, Anforderung 1). Nur SGR (`ESC [ … m`) wirkt; jede
|
|
3
|
+
* andere Sequenz (CSI wie Cursor/Zeile löschen, OSC wie Hyperlink/Fenstertitel, DCS/PM/APC, Zwei-Zeichen-
|
|
4
|
+
* Sequenzen) und jedes übrige C0-Steuerzeichen ausser Tab und Zeilenumbruch fällt ohne Rest weg.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnsiColor, AnsiSpan } from './types.js';
|
|
7
|
+
/** Der laufende SGR-Zustand; er gilt über Zeilengrenzen hinweg weiter, wie im Terminal. */
|
|
8
|
+
export interface AnsiStil {
|
|
9
|
+
readonly color: AnsiColor | null;
|
|
10
|
+
readonly background: AnsiColor | null;
|
|
11
|
+
readonly bold: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const GRUNDSTIL: AnsiStil;
|
|
14
|
+
/** Zerlegt `text` ab dem Stil `start`; liefert die Spannen und den Stil am Ende (für die nächste Zeile). */
|
|
15
|
+
export declare function zerlegeAnsi(text: string, start?: AnsiStil): {
|
|
16
|
+
spans: AnsiSpan[];
|
|
17
|
+
stil: AnsiStil;
|
|
18
|
+
};
|
|
19
|
+
/** Text mit ANSI-Sequenzen → gestaltete Spannen ohne Steuerzeichen; nur SGR wirkt, jede andere Sequenz fällt weg. */
|
|
20
|
+
export declare function parseAnsi(text: string): readonly AnsiSpan[];
|
|
21
|
+
/** Der Text ohne jede ANSI-Sequenz (und ohne übrige Steuerzeichen ausser Tab und Zeilenumbruch). */
|
|
22
|
+
export declare function stripAnsi(text: string): string;
|
|
23
|
+
//# sourceMappingURL=ansi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansi.d.ts","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtD,2FAA2F;AAC3F,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,SAAS,EAAE,QAAyD,CAAC;AAyElF,4GAA4G;AAC5G,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,QAAoB,GAAG;IAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAoB5G;AAED,qHAAqH;AACrH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE,CAE3D;AAED,oGAAoG;AACpG,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/dist/ansi.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export const GRUNDSTIL = { color: null, background: null, bold: false };
|
|
2
|
+
const FARBEN = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
|
|
3
|
+
// Die Sequenzarten einzeln, zu einer Alternation verbunden (Reihenfolge = Vorrang): CSI (Parameter,
|
|
4
|
+
// Zwischenzeichen, Endzeichen; Gruppe 1 = Parameter) · OSC bis BEL oder ST (oder Textende) · DCS/SOS/PM/APC bis ST ·
|
|
5
|
+
// Zwei-Zeichen-Sequenzen (ESC + Zwischenzeichen + Endzeichen) · ein verwaistes ESC.
|
|
6
|
+
const CSI = /\x1b\[([0-?]*)[ -/]*[@-~]/;
|
|
7
|
+
const OSC = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\|$)/;
|
|
8
|
+
const ZEICHENKETTE = /\x1b[PX^_][^\x1b]*(?:\x1b\\|$)/;
|
|
9
|
+
const ZWEI_ZEICHEN = /\x1b[ -/]*[0-~]/;
|
|
10
|
+
const SEQUENZ = new RegExp([CSI, OSC, ZEICHENKETTE, ZWEI_ZEICHEN, /\x1b/].map((r) => r.source).join('|'), 'g');
|
|
11
|
+
const STEUERZEICHEN = /[\x00-\x08\x0b-\x1f\x7f]/g;
|
|
12
|
+
/** Hellfarben 90–97 / 100–107: 90 bzw. 100 heisst `gray`, die übrigen tragen die Namen von 31–37. */
|
|
13
|
+
function hell(n) {
|
|
14
|
+
return n === 0 ? 'gray' : FARBEN[n];
|
|
15
|
+
}
|
|
16
|
+
/** Wie viele Folgeparameter eine erweiterte Farbe (38/48/58) verbraucht: `5;n` → 2, `2;r;g;b` → 4, sonst 1. */
|
|
17
|
+
function erweiterteLaenge(art) {
|
|
18
|
+
if (art === 5)
|
|
19
|
+
return 2;
|
|
20
|
+
if (art === 2)
|
|
21
|
+
return 4;
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
/** Ein einfacher SGR-Parameter (ohne Folgeparameter) auf den Stil angewandt. */
|
|
25
|
+
function einfacherParameter(stil, n) {
|
|
26
|
+
if (n === 0)
|
|
27
|
+
return GRUNDSTIL;
|
|
28
|
+
if (n === 1)
|
|
29
|
+
return { ...stil, bold: true };
|
|
30
|
+
if (n === 22)
|
|
31
|
+
return { ...stil, bold: false };
|
|
32
|
+
if (n === 39)
|
|
33
|
+
return { ...stil, color: null };
|
|
34
|
+
if (n === 49)
|
|
35
|
+
return { ...stil, background: null };
|
|
36
|
+
if (n >= 30 && n <= 37)
|
|
37
|
+
return { ...stil, color: FARBEN[n - 30] };
|
|
38
|
+
if (n >= 40 && n <= 47)
|
|
39
|
+
return { ...stil, background: FARBEN[n - 40] };
|
|
40
|
+
if (n >= 90 && n <= 97)
|
|
41
|
+
return { ...stil, color: hell(n - 90) };
|
|
42
|
+
if (n >= 100 && n <= 107)
|
|
43
|
+
return { ...stil, background: hell(n - 100) };
|
|
44
|
+
// Alles andere (blass, kursiv, unterstrichen, blinkend, invers …) gestaltet hier nichts.
|
|
45
|
+
return stil;
|
|
46
|
+
}
|
|
47
|
+
/** Eine erweiterte Farbe hat keinen Namen: 38 löscht die Vorder-, 48 die Hintergrundfarbe, 58 (Unterstrich) nichts. */
|
|
48
|
+
function ohneErweiterteFarbe(stil, kopf) {
|
|
49
|
+
if (kopf === 38)
|
|
50
|
+
return { ...stil, color: null };
|
|
51
|
+
if (kopf === 48)
|
|
52
|
+
return { ...stil, background: null };
|
|
53
|
+
return stil;
|
|
54
|
+
}
|
|
55
|
+
/** Wendet die Parameter einer SGR-Sequenz an. Erweiterte Farben verbrauchen ihre Parameter und bleiben unbenannt. */
|
|
56
|
+
function wendeSgrAn(start, parameter) {
|
|
57
|
+
let stil = start;
|
|
58
|
+
const teile = parameter === '' ? ['0'] : parameter.split(';');
|
|
59
|
+
let i = 0;
|
|
60
|
+
while (i < teile.length) {
|
|
61
|
+
const teil = teile[i];
|
|
62
|
+
if (teil.includes(':')) {
|
|
63
|
+
// Unterparameter-Form (38:5:n, 48:2::r:g:b, 4:3 …) trägt alles in einem Teil.
|
|
64
|
+
stil = ohneErweiterteFarbe(stil, Number(teil.split(':')[0]));
|
|
65
|
+
i += 1;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const n = teil === '' ? 0 : Number(teil);
|
|
69
|
+
const erweitert = n === 38 || n === 48 || n === 58;
|
|
70
|
+
stil = erweitert ? ohneErweiterteFarbe(stil, n) : einfacherParameter(stil, n);
|
|
71
|
+
i += 1 + (erweitert ? erweiterteLaenge(Number(teile[i + 1])) : 0);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return stil;
|
|
75
|
+
}
|
|
76
|
+
function gleicherStil(a, b) {
|
|
77
|
+
return a.color === b.color && a.background === b.background && a.bold === b.bold;
|
|
78
|
+
}
|
|
79
|
+
/** Zerlegt `text` ab dem Stil `start`; liefert die Spannen und den Stil am Ende (für die nächste Zeile). */
|
|
80
|
+
export function zerlegeAnsi(text, start = GRUNDSTIL) {
|
|
81
|
+
const spans = [];
|
|
82
|
+
let stil = start;
|
|
83
|
+
const haenge = (roh) => {
|
|
84
|
+
const stueck = roh.replace(STEUERZEICHEN, '');
|
|
85
|
+
if (stueck === '')
|
|
86
|
+
return;
|
|
87
|
+
const letzte = spans.at(-1);
|
|
88
|
+
if (letzte && gleicherStil(letzte, stil))
|
|
89
|
+
spans[spans.length - 1] = { ...letzte, text: letzte.text + stueck };
|
|
90
|
+
else
|
|
91
|
+
spans.push({ text: stueck, color: stil.color, background: stil.background, bold: stil.bold });
|
|
92
|
+
};
|
|
93
|
+
let pos = 0;
|
|
94
|
+
SEQUENZ.lastIndex = 0;
|
|
95
|
+
for (let m = SEQUENZ.exec(text); m !== null; m = SEQUENZ.exec(text)) {
|
|
96
|
+
haenge(text.slice(pos, m.index));
|
|
97
|
+
pos = m.index + m[0].length;
|
|
98
|
+
// Nur ein CSI mit Endzeichen `m` ist SGR.
|
|
99
|
+
if (m[1] !== undefined && m[0].endsWith('m'))
|
|
100
|
+
stil = wendeSgrAn(stil, m[1]);
|
|
101
|
+
}
|
|
102
|
+
haenge(text.slice(pos));
|
|
103
|
+
return { spans, stil };
|
|
104
|
+
}
|
|
105
|
+
/** Text mit ANSI-Sequenzen → gestaltete Spannen ohne Steuerzeichen; nur SGR wirkt, jede andere Sequenz fällt weg. */
|
|
106
|
+
export function parseAnsi(text) {
|
|
107
|
+
return zerlegeAnsi(text).spans;
|
|
108
|
+
}
|
|
109
|
+
/** Der Text ohne jede ANSI-Sequenz (und ohne übrige Steuerzeichen ausser Tab und Zeilenumbruch). */
|
|
110
|
+
export function stripAnsi(text) {
|
|
111
|
+
return text.replace(SEQUENZ, '').replace(STEUERZEICHEN, '');
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ansi.js.map
|
package/dist/ansi.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansi.js","sourceRoot":"","sources":["../src/ansi.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,SAAS,GAAa,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAElF,MAAM,MAAM,GAAyB,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7G,oGAAoG;AACpG,qHAAqH;AACrH,oFAAoF;AACpF,MAAM,GAAG,GAAG,2BAA2B,CAAC;AACxC,MAAM,GAAG,GAAG,qCAAqC,CAAC;AAClD,MAAM,YAAY,GAAG,gCAAgC,CAAC;AACtD,MAAM,YAAY,GAAG,iBAAiB,CAAC;AACvC,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/G,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD,qGAAqG;AACrG,SAAS,IAAI,CAAC,CAAS;IACrB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC;AACvC,CAAC;AAED,+GAA+G;AAC/G,SAAS,gBAAgB,CAAC,GAAW;IACnC,IAAI,GA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OAAO,KAAK,EAAgB,gBAAgB,EAAE,uBAAuB,EAAkB,MAAM,YAAY,CAAC;AAE1G,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAyD9F"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Der Controller der Ausgabe (bimetal #537): hält Text, Konfiguration und den Klappzustand und liefert
|
|
3
|
+
* einen identitätsstabilen Snapshot (useSyncExternalStore-Vertrag). Jede Entscheidung — was zugeklappt
|
|
4
|
+
* ist, was sichtbar bleibt — fällt hier; ein Binding zeigt nur an.
|
|
5
|
+
*
|
|
6
|
+
* Bewusst ohne `@bimetal/headless-core`: die Familie braucht nur Benachrichtigung und Snapshot-Memo, und
|
|
7
|
+
* ein Import des Kerns setzte dessen gebautes `dist/` voraus, das die Vertragsstufe nicht baut (D-201).
|
|
8
|
+
*/
|
|
9
|
+
import { gliedere } from './gliederung.js';
|
|
10
|
+
export function createOutputController(options = {}) {
|
|
11
|
+
const config = options.config ?? {};
|
|
12
|
+
let text = options.text ?? '';
|
|
13
|
+
let gliederung = gliedere(text, config);
|
|
14
|
+
/** Vom Nutzer gesetzter Klappzustand je `klappKey`; ohne Eintrag gilt die Vorgabe der Konfiguration. */
|
|
15
|
+
const gesetzt = new Map();
|
|
16
|
+
const listeners = new Set();
|
|
17
|
+
let snapshot = null;
|
|
18
|
+
const zugeklappt = (key, vorgabe) => gesetzt.get(key) ?? vorgabe;
|
|
19
|
+
function geaendert() {
|
|
20
|
+
snapshot = null;
|
|
21
|
+
for (const l of listeners)
|
|
22
|
+
l();
|
|
23
|
+
}
|
|
24
|
+
function setze(sectionId, wert) {
|
|
25
|
+
const abschnitt = gliederung.abschnitte.find((a) => a.id === sectionId);
|
|
26
|
+
if (!abschnitt?.collapsible)
|
|
27
|
+
return;
|
|
28
|
+
const jetzt = zugeklappt(abschnitt.klappKey, abschnitt.vorgabe);
|
|
29
|
+
const neu = wert(jetzt);
|
|
30
|
+
if (neu === jetzt)
|
|
31
|
+
return;
|
|
32
|
+
gesetzt.set(abschnitt.klappKey, neu);
|
|
33
|
+
geaendert();
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
getSnapshot() {
|
|
37
|
+
snapshot ??= {
|
|
38
|
+
sections: gliederung.abschnitte.map(({ klappKey, vorgabe, ...a }) => ({
|
|
39
|
+
...a, collapsed: a.collapsible && zugeklappt(klappKey, vorgabe),
|
|
40
|
+
})),
|
|
41
|
+
excerpts: gliederung.excerpts,
|
|
42
|
+
truncated: gliederung.truncated,
|
|
43
|
+
};
|
|
44
|
+
return snapshot;
|
|
45
|
+
},
|
|
46
|
+
subscribe(listener) {
|
|
47
|
+
listeners.add(listener);
|
|
48
|
+
return () => { listeners.delete(listener); };
|
|
49
|
+
},
|
|
50
|
+
setText(neu) {
|
|
51
|
+
if (neu === text)
|
|
52
|
+
return;
|
|
53
|
+
text = neu;
|
|
54
|
+
gliederung = gliedere(text, config);
|
|
55
|
+
// Nachlaufende Ausgabe (Streaming) behält den Klappzustand der Abschnitte, die es weiter gibt.
|
|
56
|
+
const keys = new Set(gliederung.abschnitte.map((a) => a.klappKey));
|
|
57
|
+
for (const key of gesetzt.keys())
|
|
58
|
+
if (!keys.has(key))
|
|
59
|
+
gesetzt.delete(key);
|
|
60
|
+
geaendert();
|
|
61
|
+
},
|
|
62
|
+
toggle(sectionId) { setze(sectionId, (jetzt) => !jetzt); },
|
|
63
|
+
setCollapsed(sectionId, collapsed) { setze(sectionId, () => collapsed); },
|
|
64
|
+
destroy() {
|
|
65
|
+
listeners.clear();
|
|
66
|
+
gesetzt.clear();
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=create-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-controller.js","sourceRoot":"","sources":["../src/create-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ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,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACzE,OAAO;YACL,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { OutputConfig, OutputExcerpt, OutputLine, OutputSection } from './types.js';
|
|
2
|
+
/** Ein Abschnitt ohne Klappzustand: `klappKey` = wessen Zustand gilt, `vorgabe` = anfangs zugeklappt. */
|
|
3
|
+
export interface RohAbschnitt extends Omit<OutputSection, 'collapsed'> {
|
|
4
|
+
readonly klappKey: string;
|
|
5
|
+
readonly vorgabe: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface Gliederung {
|
|
8
|
+
readonly abschnitte: readonly RohAbschnitt[];
|
|
9
|
+
readonly excerpts: readonly OutputExcerpt[];
|
|
10
|
+
readonly truncated: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Zeilen der Eingabe; `\r\n` zählt als Umbruch, ein abschliessender Umbruch eröffnet keine leere Zeile. */
|
|
13
|
+
export declare function zeilenAus(text: string): OutputLine[];
|
|
14
|
+
export declare function gliedere(text: string, config: OutputConfig): Gliederung;
|
|
15
|
+
//# sourceMappingURL=gliederung.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gliederung.d.ts","sourceRoot":"","sources":["../src/gliederung.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAqB,MAAM,YAAY,CAAC;AAE5G,yGAAyG;AACzG,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC;IACpE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,SAAS,YAAY,EAAE,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAWD,4GAA4G;AAC5G,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAUpD;AAiFD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAQvE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gliederung der Ausgabe (bimetal #537, Anforderungen 2–4): Zeilen → benannte Abschnitte (Befehle, Folgen
|
|
3
|
+
* gleichartiger Zeilen, Kürzungsmarken) und der Auszug „das Wichtigste zuerst". Reine Funktion; den
|
|
4
|
+
* Klappzustand hält der Controller.
|
|
5
|
+
*
|
|
6
|
+
* Aufbau in zwei Stufen: erst Blöcke (die Ausgabe vor dem ersten Befehl, dann je Befehl ein Block bis zum
|
|
7
|
+
* nächsten), dann teilt jede Kürzungsmarke und jede Folge ihren Block. Die Marke wird so nie Teil eines
|
|
8
|
+
* zuklappbaren Abschnitts — auch nicht mitten in einem zugeklappten Befehl oder einer Folge. Was vom Block
|
|
9
|
+
* hinter einer Marke oder Folge übrig ist, geht als Fortsetzung weiter und klappt mit seinem Block.
|
|
10
|
+
*/
|
|
11
|
+
import { GRUNDSTIL, zerlegeAnsi } from './ansi.js';
|
|
12
|
+
const BEFEHL_VORGABE = /^\$ \S/;
|
|
13
|
+
/** `RegExp#test` ohne Gedächtnis: ein Muster mit `g`/`y` würde sonst ab `lastIndex` weitersuchen. */
|
|
14
|
+
function trifft(muster, text) {
|
|
15
|
+
if (!muster)
|
|
16
|
+
return false;
|
|
17
|
+
muster.lastIndex = 0;
|
|
18
|
+
return muster.test(text);
|
|
19
|
+
}
|
|
20
|
+
/** Zeilen der Eingabe; `\r\n` zählt als Umbruch, ein abschliessender Umbruch eröffnet keine leere Zeile. */
|
|
21
|
+
export function zeilenAus(text) {
|
|
22
|
+
if (text === '')
|
|
23
|
+
return [];
|
|
24
|
+
const roh = text.split('\n');
|
|
25
|
+
if (roh.length > 1 && roh.at(-1) === '')
|
|
26
|
+
roh.pop();
|
|
27
|
+
let stil = GRUNDSTIL;
|
|
28
|
+
return roh.map((zeile, index) => {
|
|
29
|
+
const ergebnis = zerlegeAnsi(zeile.endsWith('\r') ? zeile.slice(0, -1) : zeile, stil);
|
|
30
|
+
stil = ergebnis.stil;
|
|
31
|
+
return { index, text: ergebnis.spans.map((s) => s.text).join(''), spans: ergebnis.spans };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function bloecke(zeilen, config) {
|
|
35
|
+
const befehl = config.commandPattern ?? BEFEHL_VORGABE;
|
|
36
|
+
const ergebnis = [];
|
|
37
|
+
for (const zeile of zeilen) {
|
|
38
|
+
if (trifft(befehl, zeile.text)) {
|
|
39
|
+
const zu = (config.collapsedCommands ?? []).some((m) => trifft(m, zeile.text));
|
|
40
|
+
ergebnis.push({ kind: 'command', title: zeile.text, vorgabe: zu, lines: [zeile] });
|
|
41
|
+
}
|
|
42
|
+
else if (ergebnis.length === 0) {
|
|
43
|
+
ergebnis.push({ kind: 'output', title: config.outputTitle ?? 'Output', vorgabe: false, lines: [zeile] });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
ergebnis.at(-1).lines.push(zeile);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return ergebnis;
|
|
50
|
+
}
|
|
51
|
+
/** Teilt einen Block an Kürzungsmarken und Folgen. Die Kopfzeile eines Befehls bleibt immer in seinem ersten Teil. */
|
|
52
|
+
function teileBlock(block, config, aus) {
|
|
53
|
+
const regeln = config.groups ?? [];
|
|
54
|
+
const istMarke = (z) => trifft(config.truncationPattern, z.text);
|
|
55
|
+
const regelVon = (z) => (istMarke(z) ? -1 : regeln.findIndex((r) => trifft(r.pattern, z.text)));
|
|
56
|
+
let blockId = null;
|
|
57
|
+
let offen = [];
|
|
58
|
+
const schliesse = () => {
|
|
59
|
+
if (offen.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
const id = `${block.kind}-${offen[0].index}`;
|
|
62
|
+
blockId ??= id;
|
|
63
|
+
aus.push({
|
|
64
|
+
id, kind: block.kind, title: block.title, lines: offen, collapsible: true,
|
|
65
|
+
continuationOf: blockId === id ? null : blockId, klappKey: blockId, vorgabe: block.vorgabe,
|
|
66
|
+
});
|
|
67
|
+
offen = [];
|
|
68
|
+
};
|
|
69
|
+
/** Verarbeitet die Zeile `j` (Marke, Folge oder gewöhnliche Zeile) und liefert den Index der nächsten. */
|
|
70
|
+
const schritt = (zeilen, j) => {
|
|
71
|
+
const zeile = zeilen[j];
|
|
72
|
+
const kopf = j === 0 && block.kind === 'command';
|
|
73
|
+
if (!kopf && istMarke(zeile)) {
|
|
74
|
+
schliesse();
|
|
75
|
+
const id = `truncation-${zeile.index}`;
|
|
76
|
+
aus.push({ id, kind: 'truncation', title: zeile.text, lines: [zeile], collapsible: false, continuationOf: null, klappKey: id, vorgabe: false });
|
|
77
|
+
return j + 1;
|
|
78
|
+
}
|
|
79
|
+
const r = kopf ? -1 : regelVon(zeile);
|
|
80
|
+
if (r < 0) {
|
|
81
|
+
offen.push(zeile);
|
|
82
|
+
return j + 1;
|
|
83
|
+
}
|
|
84
|
+
let ende = j + 1;
|
|
85
|
+
while (ende < zeilen.length && regelVon(zeilen[ende]) === r)
|
|
86
|
+
ende += 1;
|
|
87
|
+
const folge = zeilen.slice(j, ende);
|
|
88
|
+
const regel = regeln[r];
|
|
89
|
+
if (folge.length >= (regel.minLines ?? 2)) {
|
|
90
|
+
schliesse();
|
|
91
|
+
const id = `group-${folge[0].index}`;
|
|
92
|
+
aus.push({
|
|
93
|
+
id, kind: 'group', title: `${regel.name} (${folge.length})`, lines: folge, collapsible: true,
|
|
94
|
+
continuationOf: null, klappKey: id, vorgabe: regel.collapsed ?? true,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
offen.push(...folge);
|
|
99
|
+
}
|
|
100
|
+
return ende;
|
|
101
|
+
};
|
|
102
|
+
let j = 0;
|
|
103
|
+
while (j < block.lines.length)
|
|
104
|
+
j = schritt(block.lines, j);
|
|
105
|
+
schliesse();
|
|
106
|
+
}
|
|
107
|
+
export function gliedere(text, config) {
|
|
108
|
+
const zeilen = zeilenAus(text);
|
|
109
|
+
const abschnitte = [];
|
|
110
|
+
for (const block of bloecke(zeilen, config))
|
|
111
|
+
teileBlock(block, config, abschnitte);
|
|
112
|
+
const excerpts = (config.excerpts ?? [])
|
|
113
|
+
.map((regel) => ({ title: regel.title, lines: zeilen.filter((z) => trifft(regel.pattern, z.text)) }))
|
|
114
|
+
.filter((h) => h.lines.length > 0);
|
|
115
|
+
return { abschnitte, excerpts, truncated: abschnitte.some((a) => a.kind === 'truncation') };
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=gliederung.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gliederung.js","sourceRoot":"","sources":["../src/gliederung.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAenD,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC,qGAAqG;AACrG,SAAS,MAAM,CAAC,MAA0B,EAAE,IAAY;IACtD,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA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AAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3D,SAAS,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,MAAoB;IACzD,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAmB,EAAE,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;QAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IACnF,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;SACrC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;SACpG,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,EAAE,CAAC;AAC9F,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bimetal/output-headless — Controller für Terminal- und Werkzeugausgabe (bimetal #537).
|
|
3
|
+
*
|
|
4
|
+
* - `parseAnsi` / `stripAnsi`: ANSI-SGR → gestaltete Spannen ohne Steuerzeichen (`ansi.ts`).
|
|
5
|
+
* - `createOutputController`: benannte, einklappbare Abschnitte, immer sichtbare Kürzungsmarke, Auszug
|
|
6
|
+
* „das Wichtigste zuerst" (`gliederung.ts`, `create-controller.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Alle Zeilenmuster der Konfiguration werden gegen den Text OHNE Steuerzeichen geprüft.
|
|
9
|
+
* Vertrag: `test-vertrag/packages/output/output-headless/output-controller.test.ts`.
|
|
10
|
+
*/
|
|
11
|
+
export type { AnsiColor, AnsiSpan, OutputLine, OutputSectionKind, OutputSection, OutputGroupRule, OutputExcerptRule, OutputExcerpt, OutputConfig, OutputSnapshot, OutputControllerOptions, OutputController, } from './types.js';
|
|
12
|
+
export { parseAnsi, stripAnsi } from './ansi.js';
|
|
13
|
+
export { createOutputController } from './create-controller.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,YAAY,EACV,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EACrG,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,gBAAgB,GACvF,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typen von @bimetal/output-headless (bimetal #537). Alle Zeilenmuster der Konfiguration werden gegen
|
|
3
|
+
* den Text OHNE Steuerzeichen geprüft.
|
|
4
|
+
*/
|
|
5
|
+
/** Die benannten ANSI-Farben (SGR 30–37 / 40–47, hell 90–97 / 100–107; 90 und 100 heissen `gray`). */
|
|
6
|
+
export type AnsiColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';
|
|
7
|
+
/**
|
|
8
|
+
* Ein Stück Text mit einheitlichem Stil, ohne Steuerzeichen. `null` = keine (benannte) Farbe —
|
|
9
|
+
* erweiterte Farben (38;5;n, 38;2;r;g;b) haben keinen Namen und bleiben `null`.
|
|
10
|
+
*/
|
|
11
|
+
export interface AnsiSpan {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly color: AnsiColor | null;
|
|
14
|
+
readonly background: AnsiColor | null;
|
|
15
|
+
readonly bold: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Eine Zeile der Ausgabe: `index` = Position in der Eingabe (ab 0), `text` ohne Steuerzeichen, `spans` gestaltet. */
|
|
18
|
+
export interface OutputLine {
|
|
19
|
+
readonly index: number;
|
|
20
|
+
readonly text: string;
|
|
21
|
+
readonly spans: readonly AnsiSpan[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Art eines Abschnitts: `output` = Text ausserhalb eines Befehls, `command` = Ausgabe eines Befehls,
|
|
25
|
+
* `group` = Folge gleichartiger Zeilen, `truncation` = die Kürzungsmarke.
|
|
26
|
+
*/
|
|
27
|
+
export type OutputSectionKind = 'output' | 'command' | 'group' | 'truncation';
|
|
28
|
+
export interface OutputSection {
|
|
29
|
+
/** Eindeutig im Snapshot, stabil über toggle/setCollapsed (und über setText, solange der Abschnitt an derselben Zeile beginnt). */
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly kind: OutputSectionKind;
|
|
32
|
+
/** Benannter Titel, ohne Steuerzeichen. */
|
|
33
|
+
readonly title: string;
|
|
34
|
+
readonly lines: readonly OutputLine[];
|
|
35
|
+
readonly collapsed: boolean;
|
|
36
|
+
/** `false` für die Kürzungsmarke — sie bleibt immer sichtbar. */
|
|
37
|
+
readonly collapsible: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Fortsetzung: Teilt eine Folge oder eine Kürzungsmarke einen Befehl (oder die Ausgabe davor), geht er
|
|
40
|
+
* danach in einem eigenen Abschnitt weiter — gleiche Art, gleicher Titel, hier die Id seines ersten
|
|
41
|
+
* Abschnitts (sonst `null`). Alle Teile klappen gemeinsam; ein Renderer kann den Titel der Fortsetzung
|
|
42
|
+
* weglassen.
|
|
43
|
+
*/
|
|
44
|
+
readonly continuationOf: string | null;
|
|
45
|
+
}
|
|
46
|
+
/** Eine Folge von mindestens `minLines` (Vorgabe 2) aufeinanderfolgenden Zeilen, die `pattern` treffen. */
|
|
47
|
+
export interface OutputGroupRule {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly pattern: RegExp;
|
|
50
|
+
readonly minLines?: number;
|
|
51
|
+
/** Anfangs zugeklappt; Vorgabe `true`. */
|
|
52
|
+
readonly collapsed?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Eine Regel des Auszugs „das Wichtigste zuerst". */
|
|
55
|
+
export interface OutputExcerptRule {
|
|
56
|
+
readonly title: string;
|
|
57
|
+
readonly pattern: RegExp;
|
|
58
|
+
}
|
|
59
|
+
/** Ein Auszug: die Zeilen, die die Regel treffen, in der Reihenfolge der Eingabe. */
|
|
60
|
+
export interface OutputExcerpt {
|
|
61
|
+
readonly title: string;
|
|
62
|
+
readonly lines: readonly OutputLine[];
|
|
63
|
+
}
|
|
64
|
+
export interface OutputConfig {
|
|
65
|
+
/** Erste Zeile eines Befehls; Vorgabe `/^\$ \S/`. */
|
|
66
|
+
readonly commandPattern?: RegExp;
|
|
67
|
+
/** Befehle (geprüft an ihrer ersten Zeile), deren Abschnitt anfangs zugeklappt ist. */
|
|
68
|
+
readonly collapsedCommands?: readonly RegExp[];
|
|
69
|
+
readonly groups?: readonly OutputGroupRule[];
|
|
70
|
+
/** Die Zeile der Kürzungsmarke. */
|
|
71
|
+
readonly truncationPattern?: RegExp;
|
|
72
|
+
/** Reihenfolge = Rang im Auszug. */
|
|
73
|
+
readonly excerpts?: readonly OutputExcerptRule[];
|
|
74
|
+
/** Titel der Ausgabe vor dem ersten Befehl; Vorgabe `'Output'`. */
|
|
75
|
+
readonly outputTitle?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface OutputSnapshot {
|
|
78
|
+
readonly sections: readonly OutputSection[];
|
|
79
|
+
/** Je Regel mit Treffern ein Auszug, in der Reihenfolge der Regeln. */
|
|
80
|
+
readonly excerpts: readonly OutputExcerpt[];
|
|
81
|
+
/** Die Ausgabe trägt eine Kürzungsmarke. */
|
|
82
|
+
readonly truncated: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface OutputControllerOptions {
|
|
85
|
+
readonly text?: string;
|
|
86
|
+
readonly config?: OutputConfig;
|
|
87
|
+
}
|
|
88
|
+
/** useSyncExternalStore-Vertrag: `getSnapshot` ist identitätsstabil, bis sich etwas ändert. */
|
|
89
|
+
export interface OutputController {
|
|
90
|
+
getSnapshot(): OutputSnapshot;
|
|
91
|
+
subscribe(listener: () => void): () => void;
|
|
92
|
+
/** Ersetzt die Ausgabe; vom Nutzer auf- oder zugeklappte Abschnitte behalten ihren Zustand, solange es ihre Id noch gibt. */
|
|
93
|
+
setText(text: string): void;
|
|
94
|
+
toggle(sectionId: string): void;
|
|
95
|
+
setCollapsed(sectionId: string, collapsed: boolean): void;
|
|
96
|
+
destroy(): void;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sGAAsG;AACtG,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,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M,IAAI,CAAC;IAC5C,6HAA6H;IAC7H,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1D,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bimetal/output-headless",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.44.0",
|
|
4
|
+
"description": "Canonical, framework-agnostic controller for terminal and tool output (createOutputController): ANSI SGR to styled spans without control characters, named collapsible sections (command boundaries, runs of similar lines), an always-visible truncation marker and a configurable 'most important first' excerpt by line patterns. No domain dependency.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"!**/*.tsbuildinfo"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"dev": "tsc -b --watch",
|
|
23
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"vitest": "^5.0.0",
|
|
28
|
+
"vite": "^8.0.1"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"author": "Andreas Biederbeck",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"terminal",
|
|
35
|
+
"ansi",
|
|
36
|
+
"log",
|
|
37
|
+
"output",
|
|
38
|
+
"headless",
|
|
39
|
+
"controller",
|
|
40
|
+
"framework-agnostic"
|
|
41
|
+
]
|
|
42
|
+
}
|