@moyarich/console-addon-xterm 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @moyarich/console-addon-xterm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Render terminal output with xterm.js. Use xterm.js for ANSI/VT terminal rendering, append-only streaming, and terminal-sized scrolling.
4
+
5
+ [Documentation and live examples](https://moyarich.github.io/console/)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @moyarich/console @moyarich/console-addon-xterm react
11
+ ```
12
+
13
+ Configure the `@moyarich` scope and authenticate with GitHub Packages as described in the [installation guide](../../../README.md#installation).
14
+
15
+ Required peer dependencies: `@moyarich/console-core@^0.2.0`, `@moyarich/console@^0.2.0`, `react@>=18`.
16
+
17
+ ## Quick start
18
+
19
+ ```tsx
20
+ import { Console } from "@moyarich/console";
21
+ import { createConsoleXtermAddon } from "@moyarich/console-addon-xterm";
22
+
23
+ const addons = [createConsoleXtermAddon()];
24
+
25
+ // Pass your application's terminal output entries to Console.
26
+ <Console mode="terminal" messages={messages} addons={addons} />;
27
+ ```
28
+
29
+ The addon is optional and can be combined with other Console addons. Use terminal mode when passing process output.
30
+
31
+ ## Learn more
32
+
33
+ Explore [runnable package examples](./examples) and the [Console documentation](https://moyarich.github.io/console/) for available settings and integration patterns.
34
+
35
+ Review the [changelog](./CHANGELOG.md) for changes by version and [package metadata](./package.json) for dependency requirements.
36
+
37
+ ## License
38
+
39
+ MIT
@@ -0,0 +1,12 @@
1
+ import { type AddonTranslations } from "./localization.cjs";
2
+ import type { ConsoleStdoutEntry } from "@moyarich/console";
3
+
4
+
5
+ /** Decide when new output can be appended without replaying prior chunks. */
6
+ export declare function isAppendOnly(previous: readonly (ConsoleStdoutEntry | string)[], next: readonly (ConsoleStdoutEntry | string)[]): boolean;
7
+ /** The addon owns terminal creation, updates, and disposal. */
8
+ export declare function XtermOutput({ entries, locale, translations, }: {
9
+ entries: readonly (ConsoleStdoutEntry | string)[];
10
+ locale?: string;
11
+ translations?: AddonTranslations;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { type AddonTranslations } from "./localization.js";
2
+ import type { ConsoleStdoutEntry } from "@moyarich/console";
3
+
4
+
5
+ /** Decide when new output can be appended without replaying prior chunks. */
6
+ export declare function isAppendOnly(previous: readonly (ConsoleStdoutEntry | string)[], next: readonly (ConsoleStdoutEntry | string)[]): boolean;
7
+ /** The addon owns terminal creation, updates, and disposal. */
8
+ export declare function XtermOutput({ entries, locale, translations, }: {
9
+ entries: readonly (ConsoleStdoutEntry | string)[];
10
+ locale?: string;
11
+ translations?: AddonTranslations;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Copyright (c) 2014 The xterm.js authors. All rights reserved.
3
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4
+ * https://github.com/chjj/term.js
5
+ * @license MIT
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+ *
25
+ * Originally forked from (with the author's permission):
26
+ * Fabrice Bellard's javascript vt100 for jslinux:
27
+ * http://bellard.org/jslinux/
28
+ * Copyright (c) 2011 Fabrice Bellard
29
+ * The original design remains. The terminal itself
30
+ * has been extended to include xterm CSI codes, among
31
+ * other features.
32
+ */
33
+
34
+ /**
35
+ * Default styles for xterm.js
36
+ */
37
+
38
+ .xterm {
39
+ cursor: text;
40
+ position: relative;
41
+ user-select: none;
42
+ -ms-user-select: none;
43
+ -webkit-user-select: none;
44
+ }
45
+
46
+ .xterm.focus,
47
+ .xterm:focus {
48
+ outline: none;
49
+ }
50
+
51
+ .xterm .xterm-helpers {
52
+ position: absolute;
53
+ top: 0;
54
+ /**
55
+ * The z-index of the helpers must be higher than the canvases in order for
56
+ * IMEs to appear on top.
57
+ */
58
+ z-index: 5;
59
+ }
60
+
61
+ .xterm .xterm-helper-textarea {
62
+ padding: 0;
63
+ border: 0;
64
+ margin: 0;
65
+ /* Move textarea out of the screen to the far left, so that the cursor is not visible */
66
+ position: absolute;
67
+ opacity: 0;
68
+ left: -9999em;
69
+ top: 0;
70
+ width: 0;
71
+ height: 0;
72
+ z-index: -5;
73
+ /** Prevent wrapping so the IME appears against the textarea at the correct position */
74
+ white-space: nowrap;
75
+ overflow: hidden;
76
+ resize: none;
77
+ }
78
+
79
+ .xterm .composition-view {
80
+ /* TODO: Composition position got messed up somewhere */
81
+ background: #000;
82
+ color: #FFF;
83
+ display: none;
84
+ position: absolute;
85
+ white-space: nowrap;
86
+ z-index: 1;
87
+ }
88
+
89
+ .xterm .composition-view.active {
90
+ display: block;
91
+ }
92
+
93
+ .xterm .xterm-viewport {
94
+ /* On OS X this is required in order for the scroll bar to appear fully opaque */
95
+ background-color: #000;
96
+ overflow-y: scroll;
97
+ cursor: default;
98
+ position: absolute;
99
+ right: 0;
100
+ left: 0;
101
+ top: 0;
102
+ bottom: 0;
103
+ }
104
+
105
+ .xterm .xterm-screen {
106
+ position: relative;
107
+ }
108
+
109
+ .xterm .xterm-screen canvas {
110
+ position: absolute;
111
+ left: 0;
112
+ top: 0;
113
+ }
114
+
115
+ .xterm-char-measure-element {
116
+ display: inline-block;
117
+ visibility: hidden;
118
+ position: absolute;
119
+ top: 0;
120
+ left: -9999em;
121
+ line-height: normal;
122
+ }
123
+
124
+ .xterm.enable-mouse-events {
125
+ /* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
126
+ cursor: default;
127
+ }
128
+
129
+ .xterm.xterm-cursor-pointer,
130
+ .xterm .xterm-cursor-pointer {
131
+ cursor: pointer;
132
+ }
133
+
134
+ .xterm.column-select.focus {
135
+ /* Column selection mode */
136
+ cursor: crosshair;
137
+ }
138
+
139
+ .xterm .xterm-accessibility:not(.debug),
140
+ .xterm .xterm-message {
141
+ position: absolute;
142
+ left: 0;
143
+ top: 0;
144
+ bottom: 0;
145
+ right: 0;
146
+ z-index: 10;
147
+ color: transparent;
148
+ pointer-events: none;
149
+ }
150
+
151
+ .xterm .xterm-accessibility-tree:not(.debug) *::selection {
152
+ color: transparent;
153
+ }
154
+
155
+ .xterm .xterm-accessibility-tree {
156
+ font-family: monospace;
157
+ user-select: text;
158
+ white-space: pre;
159
+ }
160
+
161
+ .xterm .xterm-accessibility-tree > div {
162
+ transform-origin: left;
163
+ width: fit-content;
164
+ }
165
+
166
+ .xterm .live-region {
167
+ position: absolute;
168
+ left: -9999px;
169
+ width: 1px;
170
+ height: 1px;
171
+ overflow: hidden;
172
+ }
173
+
174
+ .xterm-dim {
175
+ /* Dim should not apply to background, so the opacity of the foreground color is applied
176
+ * explicitly in the generated class and reset to 1 here */
177
+ opacity: 1 !important;
178
+ }
179
+
180
+ .xterm-underline-1 { text-decoration: underline; }
181
+ .xterm-underline-2 { text-decoration: double underline; }
182
+ .xterm-underline-3 { text-decoration: wavy underline; }
183
+ .xterm-underline-4 { text-decoration: dotted underline; }
184
+ .xterm-underline-5 { text-decoration: dashed underline; }
185
+
186
+ .xterm-overline {
187
+ text-decoration: overline;
188
+ }
189
+
190
+ .xterm-overline.xterm-underline-1 { text-decoration: overline underline; }
191
+ .xterm-overline.xterm-underline-2 { text-decoration: overline double underline; }
192
+ .xterm-overline.xterm-underline-3 { text-decoration: overline wavy underline; }
193
+ .xterm-overline.xterm-underline-4 { text-decoration: overline dotted underline; }
194
+ .xterm-overline.xterm-underline-5 { text-decoration: overline dashed underline; }
195
+
196
+ .xterm-strikethrough {
197
+ text-decoration: line-through;
198
+ }
199
+
200
+ .xterm-screen .xterm-decoration-container .xterm-decoration {
201
+ z-index: 6;
202
+ position: absolute;
203
+ }
204
+
205
+ .xterm-screen .xterm-decoration-container .xterm-decoration.xterm-decoration-top-layer {
206
+ z-index: 7;
207
+ }
208
+
209
+ .xterm-decoration-overview-ruler {
210
+ z-index: 8;
211
+ position: absolute;
212
+ top: 0;
213
+ right: 0;
214
+ pointer-events: none;
215
+ }
216
+
217
+ .xterm-decoration-top {
218
+ z-index: 2;
219
+ position: relative;
220
+ }
221
+
222
+
223
+
224
+ /* Derived from vs/base/browser/ui/scrollbar/media/scrollbar.css */
225
+
226
+ /* xterm.js customization: Override xterm's cursor style */
227
+ .xterm .xterm-scrollable-element > .scrollbar {
228
+ cursor: default;
229
+ }
230
+
231
+ /* Arrows */
232
+ .xterm .xterm-scrollable-element > .scrollbar > .scra {
233
+ cursor: pointer;
234
+ font-size: 11px !important;
235
+ }
236
+
237
+ .xterm .xterm-scrollable-element > .visible {
238
+ opacity: 1;
239
+
240
+ /* Background rule added for IE9 - to allow clicks on dom node */
241
+ background:rgba(0,0,0,0);
242
+
243
+ transition: opacity 100ms linear;
244
+ /* In front of peek view */
245
+ z-index: 11;
246
+ }
247
+ .xterm .xterm-scrollable-element > .invisible {
248
+ opacity: 0;
249
+ pointer-events: none;
250
+ }
251
+ .xterm .xterm-scrollable-element > .invisible.fade {
252
+ transition: opacity 800ms linear;
253
+ }
254
+
255
+ /* Scrollable Content Inset Shadow */
256
+ .xterm .xterm-scrollable-element > .shadow {
257
+ position: absolute;
258
+ display: none;
259
+ }
260
+ .xterm .xterm-scrollable-element > .shadow.top {
261
+ display: block;
262
+ top: 0;
263
+ left: 3px;
264
+ height: 3px;
265
+ width: 100%;
266
+ box-shadow: var(--vscode-scrollbar-shadow, #000) 0 6px 6px -6px inset;
267
+ }
268
+ .xterm .xterm-scrollable-element > .shadow.left {
269
+ display: block;
270
+ top: 3px;
271
+ left: 0;
272
+ height: 100%;
273
+ width: 3px;
274
+ box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
275
+ }
276
+ .xterm .xterm-scrollable-element > .shadow.top-left-corner {
277
+ display: block;
278
+ top: 0;
279
+ left: 0;
280
+ height: 3px;
281
+ width: 3px;
282
+ }
283
+ .xterm .xterm-scrollable-element > .shadow.top.left {
284
+ box-shadow: var(--vscode-scrollbar-shadow, #000) 6px 0 6px -6px inset;
285
+ }
286
+ .console-panel .console-surface:has(.console-xterm-output) {
287
+ min-height: 0;
288
+ min-width: 0;
289
+ overflow: hidden;
290
+ display: flex;
291
+ flex-direction: column;
292
+ }
293
+
294
+ .console-panel
295
+ .console-surface:has(.console-xterm-output)
296
+ > .console-scroll-end-spacer {
297
+ display: none;
298
+ }
299
+
300
+ .console-xterm-output {
301
+ --_console-xterm-background: var(--console-xterm-background, transparent);
302
+ box-sizing: border-box;
303
+ flex: 1 1 0;
304
+ min-width: 0;
305
+ min-height: 0;
306
+ width: 100%;
307
+ height: 0;
308
+ overflow: hidden;
309
+ background: var(--_console-xterm-background);
310
+ }
311
+
312
+ .console-xterm-output .xterm {
313
+ box-sizing: border-box;
314
+ height: 100%;
315
+ width: 100%;
316
+ padding: var(--console-xterm-padding, 0.5rem);
317
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const consoleCore = require("@moyarich/console-core");
5
+ const react = require("react");
6
+ const xterm = require("@xterm/xterm");
7
+ const terminal$3 = "Terminal output";
8
+ const en = {
9
+ terminal: terminal$3
10
+ };
11
+ const terminal$2 = "Salida del terminal";
12
+ const es = {
13
+ terminal: terminal$2
14
+ };
15
+ const terminal$1 = "Sortie du terminal";
16
+ const fr = {
17
+ terminal: terminal$1
18
+ };
19
+ const terminal = "Saída do terminal";
20
+ const pt = {
21
+ terminal
22
+ };
23
+ const locales = { en, es, fr, pt };
24
+ function resolveAddonMessages(locale = "en", overrides) {
25
+ const tag = locale.replace(/_/g, "-").toLowerCase();
26
+ return {
27
+ ...en,
28
+ ...locales[tag] ?? locales[tag.split("-")[0]] ?? {},
29
+ ...overrides
30
+ };
31
+ }
32
+ function isAppendOnly(previous, next) {
33
+ return previous.length <= next.length && previous.every((entry, i) => {
34
+ const current = next[i];
35
+ return entry === current || typeof entry !== "string" && typeof current !== "string" && current !== void 0 && entry.id === current.id && entry.data === current.data && entry.stream === current.stream;
36
+ });
37
+ }
38
+ function XtermOutput({
39
+ entries,
40
+ locale = "en",
41
+ translations
42
+ }) {
43
+ const labels = resolveAddonMessages(locale, translations);
44
+ const element = react.useRef(null);
45
+ const terminal2 = react.useRef(null);
46
+ const written = react.useRef([]);
47
+ react.useEffect(() => {
48
+ if (!element.current) return;
49
+ const instance = new xterm.Terminal({
50
+ convertEol: true,
51
+ disableStdin: true,
52
+ screenReaderMode: true,
53
+ scrollback: 5e3
54
+ });
55
+ instance.open(element.current);
56
+ const container = element.current;
57
+ const resizeToContainer = () => {
58
+ const screen = instance.element?.querySelector(".xterm-screen");
59
+ if (!screen || !container.isConnected) return;
60
+ const cellWidth = screen.offsetWidth / instance.cols;
61
+ const cellHeight = screen.offsetHeight / instance.rows;
62
+ if (cellWidth <= 0 || cellHeight <= 0) return;
63
+ const xtermElement = instance.element;
64
+ const styles = xtermElement ? getComputedStyle(xtermElement) : null;
65
+ const horizontalPadding = styles ? parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight) : 0;
66
+ const verticalPadding = styles ? parseFloat(styles.paddingTop) + parseFloat(styles.paddingBottom) : 0;
67
+ const cols = Math.max(
68
+ 2,
69
+ Math.floor((container.clientWidth - horizontalPadding) / cellWidth)
70
+ );
71
+ const rows = Math.max(
72
+ 1,
73
+ Math.floor((container.clientHeight - verticalPadding) / cellHeight)
74
+ );
75
+ if (cols !== instance.cols || rows !== instance.rows)
76
+ instance.resize(cols, rows);
77
+ };
78
+ resizeToContainer();
79
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resizeToContainer);
80
+ observer?.observe(container);
81
+ terminal2.current = instance;
82
+ written.current = [];
83
+ return () => {
84
+ observer?.disconnect();
85
+ terminal2.current = null;
86
+ written.current = [];
87
+ instance.dispose();
88
+ };
89
+ }, []);
90
+ react.useEffect(() => {
91
+ const instance = terminal2.current;
92
+ if (!instance) return;
93
+ const appendOnly = isAppendOnly(written.current, entries);
94
+ if (!appendOnly) instance.reset();
95
+ const start = appendOnly ? written.current.length : 0;
96
+ for (let i = start; i < entries.length; i++) {
97
+ const entry = entries[i];
98
+ instance.write(typeof entry === "string" ? entry : entry.data);
99
+ }
100
+ written.current = [...entries];
101
+ }, [entries]);
102
+ return /* @__PURE__ */ jsxRuntime.jsx(
103
+ "div",
104
+ {
105
+ ref: element,
106
+ className: "console-xterm-output",
107
+ "aria-label": labels.terminal
108
+ }
109
+ );
110
+ }
111
+ const CONSOLE_XTERM_ADDON_ID = "@moyarich/console-addon-xterm";
112
+ const xtermOutputRenderer = {
113
+ mode: "terminal",
114
+ render(context) {
115
+ if (context.mode !== "terminal") return void 0;
116
+ return /* @__PURE__ */ jsxRuntime.jsx(XtermOutput, { entries: context.entries });
117
+ }
118
+ };
119
+ function createConsoleXtermAddon(options = {}) {
120
+ return {
121
+ id: CONSOLE_XTERM_ADDON_ID,
122
+ activate(host) {
123
+ host.extensions.register(
124
+ consoleCore.consoleExtensionPoints.outputRenderer,
125
+ {
126
+ ...xtermOutputRenderer,
127
+ render(context) {
128
+ if (context.mode !== "terminal") return void 0;
129
+ return /* @__PURE__ */ jsxRuntime.jsx(XtermOutput, { entries: context.entries, ...options });
130
+ }
131
+ },
132
+ {
133
+ id: `${CONSOLE_XTERM_ADDON_ID}:output-renderer`
134
+ }
135
+ );
136
+ }
137
+ };
138
+ }
139
+ exports.CONSOLE_XTERM_ADDON_ID = CONSOLE_XTERM_ADDON_ID;
140
+ exports.XtermOutput = XtermOutput;
141
+ exports.createConsoleXtermAddon = createConsoleXtermAddon;
142
+ exports.isAppendOnly = isAppendOnly;
143
+ exports.resolveAddonMessages = resolveAddonMessages;
144
+ exports.xtermOutputRenderer = xtermOutputRenderer;
@@ -0,0 +1,11 @@
1
+ import type { AddonTranslations } from "./localization.cjs";
2
+ export { resolveAddonMessages } from "./localization.cjs";
3
+ export type { AddonTranslations } from "./localization.cjs";
4
+ import { type ConsoleAddon, type ConsoleOutputRenderer } from "@moyarich/console-core";
5
+ export declare const CONSOLE_XTERM_ADDON_ID = "@moyarich/console-addon-xterm";
6
+ export declare const xtermOutputRenderer: ConsoleOutputRenderer;
7
+ export declare function createConsoleXtermAddon(options?: {
8
+ locale?: string;
9
+ translations?: AddonTranslations;
10
+ }): ConsoleAddon;
11
+ export { XtermOutput, isAppendOnly } from "./XtermOutput.cjs";
@@ -0,0 +1,11 @@
1
+ import type { AddonTranslations } from "./localization.js";
2
+ export { resolveAddonMessages } from "./localization.js";
3
+ export type { AddonTranslations } from "./localization.js";
4
+ import { type ConsoleAddon, type ConsoleOutputRenderer } from "@moyarich/console-core";
5
+ export declare const CONSOLE_XTERM_ADDON_ID = "@moyarich/console-addon-xterm";
6
+ export declare const xtermOutputRenderer: ConsoleOutputRenderer;
7
+ export declare function createConsoleXtermAddon(options?: {
8
+ locale?: string;
9
+ translations?: AddonTranslations;
10
+ }): ConsoleAddon;
11
+ export { XtermOutput, isAppendOnly } from "./XtermOutput.js";
package/dist/index.js ADDED
@@ -0,0 +1,144 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { consoleExtensionPoints } from "@moyarich/console-core";
3
+ import { useRef, useEffect } from "react";
4
+ import { Terminal } from "@xterm/xterm";
5
+ const terminal$3 = "Terminal output";
6
+ const en = {
7
+ terminal: terminal$3
8
+ };
9
+ const terminal$2 = "Salida del terminal";
10
+ const es = {
11
+ terminal: terminal$2
12
+ };
13
+ const terminal$1 = "Sortie du terminal";
14
+ const fr = {
15
+ terminal: terminal$1
16
+ };
17
+ const terminal = "Saída do terminal";
18
+ const pt = {
19
+ terminal
20
+ };
21
+ const locales = { en, es, fr, pt };
22
+ function resolveAddonMessages(locale = "en", overrides) {
23
+ const tag = locale.replace(/_/g, "-").toLowerCase();
24
+ return {
25
+ ...en,
26
+ ...locales[tag] ?? locales[tag.split("-")[0]] ?? {},
27
+ ...overrides
28
+ };
29
+ }
30
+ function isAppendOnly(previous, next) {
31
+ return previous.length <= next.length && previous.every((entry, i) => {
32
+ const current = next[i];
33
+ return entry === current || typeof entry !== "string" && typeof current !== "string" && current !== void 0 && entry.id === current.id && entry.data === current.data && entry.stream === current.stream;
34
+ });
35
+ }
36
+ function XtermOutput({
37
+ entries,
38
+ locale = "en",
39
+ translations
40
+ }) {
41
+ const labels = resolveAddonMessages(locale, translations);
42
+ const element = useRef(null);
43
+ const terminal2 = useRef(null);
44
+ const written = useRef([]);
45
+ useEffect(() => {
46
+ if (!element.current) return;
47
+ const instance = new Terminal({
48
+ convertEol: true,
49
+ disableStdin: true,
50
+ screenReaderMode: true,
51
+ scrollback: 5e3
52
+ });
53
+ instance.open(element.current);
54
+ const container = element.current;
55
+ const resizeToContainer = () => {
56
+ const screen = instance.element?.querySelector(".xterm-screen");
57
+ if (!screen || !container.isConnected) return;
58
+ const cellWidth = screen.offsetWidth / instance.cols;
59
+ const cellHeight = screen.offsetHeight / instance.rows;
60
+ if (cellWidth <= 0 || cellHeight <= 0) return;
61
+ const xtermElement = instance.element;
62
+ const styles = xtermElement ? getComputedStyle(xtermElement) : null;
63
+ const horizontalPadding = styles ? parseFloat(styles.paddingLeft) + parseFloat(styles.paddingRight) : 0;
64
+ const verticalPadding = styles ? parseFloat(styles.paddingTop) + parseFloat(styles.paddingBottom) : 0;
65
+ const cols = Math.max(
66
+ 2,
67
+ Math.floor((container.clientWidth - horizontalPadding) / cellWidth)
68
+ );
69
+ const rows = Math.max(
70
+ 1,
71
+ Math.floor((container.clientHeight - verticalPadding) / cellHeight)
72
+ );
73
+ if (cols !== instance.cols || rows !== instance.rows)
74
+ instance.resize(cols, rows);
75
+ };
76
+ resizeToContainer();
77
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resizeToContainer);
78
+ observer?.observe(container);
79
+ terminal2.current = instance;
80
+ written.current = [];
81
+ return () => {
82
+ observer?.disconnect();
83
+ terminal2.current = null;
84
+ written.current = [];
85
+ instance.dispose();
86
+ };
87
+ }, []);
88
+ useEffect(() => {
89
+ const instance = terminal2.current;
90
+ if (!instance) return;
91
+ const appendOnly = isAppendOnly(written.current, entries);
92
+ if (!appendOnly) instance.reset();
93
+ const start = appendOnly ? written.current.length : 0;
94
+ for (let i = start; i < entries.length; i++) {
95
+ const entry = entries[i];
96
+ instance.write(typeof entry === "string" ? entry : entry.data);
97
+ }
98
+ written.current = [...entries];
99
+ }, [entries]);
100
+ return /* @__PURE__ */ jsx(
101
+ "div",
102
+ {
103
+ ref: element,
104
+ className: "console-xterm-output",
105
+ "aria-label": labels.terminal
106
+ }
107
+ );
108
+ }
109
+ const CONSOLE_XTERM_ADDON_ID = "@moyarich/console-addon-xterm";
110
+ const xtermOutputRenderer = {
111
+ mode: "terminal",
112
+ render(context) {
113
+ if (context.mode !== "terminal") return void 0;
114
+ return /* @__PURE__ */ jsx(XtermOutput, { entries: context.entries });
115
+ }
116
+ };
117
+ function createConsoleXtermAddon(options = {}) {
118
+ return {
119
+ id: CONSOLE_XTERM_ADDON_ID,
120
+ activate(host) {
121
+ host.extensions.register(
122
+ consoleExtensionPoints.outputRenderer,
123
+ {
124
+ ...xtermOutputRenderer,
125
+ render(context) {
126
+ if (context.mode !== "terminal") return void 0;
127
+ return /* @__PURE__ */ jsx(XtermOutput, { entries: context.entries, ...options });
128
+ }
129
+ },
130
+ {
131
+ id: `${CONSOLE_XTERM_ADDON_ID}:output-renderer`
132
+ }
133
+ );
134
+ }
135
+ };
136
+ }
137
+ export {
138
+ CONSOLE_XTERM_ADDON_ID,
139
+ XtermOutput,
140
+ createConsoleXtermAddon,
141
+ isAppendOnly,
142
+ resolveAddonMessages,
143
+ xtermOutputRenderer
144
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "terminal": "Terminal output"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "terminal": "Salida del terminal"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "terminal": "Sortie du terminal"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "terminal": "Saída do terminal"
3
+ }
@@ -0,0 +1,3 @@
1
+ import en from "./locales/en.json";
2
+ export type AddonTranslations = Partial<typeof en>;
3
+ export declare function resolveAddonMessages(locale?: string, overrides?: AddonTranslations): typeof en;
@@ -0,0 +1,3 @@
1
+ import en from "./locales/en.json";
2
+ export type AddonTranslations = Partial<typeof en>;
3
+ export declare function resolveAddonMessages(locale?: string, overrides?: AddonTranslations): typeof en;
@@ -0,0 +1,33 @@
1
+ /* src/XtermOutput.css */
2
+ .console-panel .console-surface:has(.console-xterm-output) {
3
+ min-height: 0;
4
+ min-width: 0;
5
+ overflow: hidden;
6
+ display: flex;
7
+ flex-direction: column;
8
+ }
9
+
10
+ .console-panel
11
+ .console-surface:has(.console-xterm-output)
12
+ > .console-scroll-end-spacer {
13
+ display: none;
14
+ }
15
+
16
+ .console-xterm-output {
17
+ --_console-xterm-background: var(--console-xterm-background, transparent);
18
+ box-sizing: border-box;
19
+ flex: 1 1 0;
20
+ min-width: 0;
21
+ min-height: 0;
22
+ width: 100%;
23
+ height: 0;
24
+ overflow: hidden;
25
+ background: var(--_console-xterm-background);
26
+ }
27
+
28
+ .console-xterm-output .xterm {
29
+ box-sizing: border-box;
30
+ height: 100%;
31
+ width: 100%;
32
+ padding: var(--console-xterm-padding, 0.5rem);
33
+ }
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@moyarich/console-addon-xterm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Optional xterm.js terminal renderer for Console",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ },
21
+ "./styles.css": "./dist/styles.css"
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "publishConfig": {
27
+ "registry": "https://npm.pkg.github.com"
28
+ },
29
+ "scripts": {
30
+ "build": "vite build && tsc -p tsconfig.build.json && node ../../../scripts/prepare-cjs-types.mjs && node ../../../scripts/prepare-addon-styles.mjs",
31
+ "typecheck": "tsc --noEmit"
32
+ },
33
+ "peerDependencies": {
34
+ "@moyarich/console-core": "^0.2.0",
35
+ "@moyarich/console": "^0.2.0",
36
+ "react": ">=18"
37
+ },
38
+ "dependencies": {
39
+ "@xterm/xterm": "^6.0.0"
40
+ },
41
+ "devDependencies": {
42
+ "@moyarich/console-core": "0.2.0",
43
+ "@moyarich/console": "0.2.0",
44
+ "@types/react": "^19.1.12",
45
+ "react": "^19.2.7",
46
+ "typescript": "^5.9.2",
47
+ "vite": "^7.1.5"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/moyarich/console.git",
52
+ "directory": "packages/addons/xterm"
53
+ },
54
+ "sideEffects": [
55
+ "./src/index.tsx",
56
+ "./src/XtermOutput.css",
57
+ "./dist/index.js",
58
+ "./dist/index.cjs",
59
+ "./dist/styles.css"
60
+ ],
61
+ "publisher": "moyarich",
62
+ "author": "Moya Richards",
63
+ "engines": {
64
+ "node": ">=24"
65
+ },
66
+ "private": false,
67
+ "keywords": [
68
+ "console",
69
+ "addon",
70
+ "xterm"
71
+ ],
72
+ "homepage": "https://moyarich.github.io/console/",
73
+ "bugs": {
74
+ "url": "https://github.com/moyarich/console/issues"
75
+ }
76
+ }