@moyarich/console-addon-xterm 0.1.0 → 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 +7 -1
- package/dist/XtermOutput.d.cts +12 -0
- package/dist/XtermOutput.d.ts +6 -3
- package/dist/index.cjs +43 -8
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +43 -8
- package/dist/locales/en.json +3 -0
- package/dist/locales/es.json +3 -0
- package/dist/locales/fr.json +3 -0
- package/dist/locales/pt.json +3 -0
- package/dist/localization.d.cts +3 -0
- package/dist/localization.d.ts +3 -0
- package/dist/styles.css +33 -0
- package/package.json +26 -13
package/README.md
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Render terminal output with xterm.js. Use xterm.js for ANSI/VT terminal rendering, append-only streaming, and terminal-sized scrolling.
|
|
4
4
|
|
|
5
|
+
[Documentation and live examples](https://moyarich.github.io/console/)
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
npm install @moyarich/console @moyarich/console-addon-xterm
|
|
10
|
+
npm install @moyarich/console @moyarich/console-addon-xterm react
|
|
9
11
|
```
|
|
10
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
|
+
|
|
11
17
|
## Quick start
|
|
12
18
|
|
|
13
19
|
```tsx
|
|
@@ -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;
|
package/dist/XtermOutput.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { type AddonTranslations } from "./localization.js";
|
|
1
2
|
import type { ConsoleStdoutEntry } from "@moyarich/console";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
|
|
4
5
|
/** Decide when new output can be appended without replaying prior chunks. */
|
|
5
6
|
export declare function isAppendOnly(previous: readonly (ConsoleStdoutEntry | string)[], next: readonly (ConsoleStdoutEntry | string)[]): boolean;
|
|
6
7
|
/** The addon owns terminal creation, updates, and disposal. */
|
|
7
|
-
export declare function XtermOutput({ entries, }: {
|
|
8
|
+
export declare function XtermOutput({ entries, locale, translations, }: {
|
|
8
9
|
entries: readonly (ConsoleStdoutEntry | string)[];
|
|
10
|
+
locale?: string;
|
|
11
|
+
translations?: AddonTranslations;
|
|
9
12
|
}): import("react").JSX.Element;
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,31 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const consoleCore = require("@moyarich/console-core");
|
|
5
5
|
const react = require("react");
|
|
6
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
|
+
}
|
|
7
32
|
function isAppendOnly(previous, next) {
|
|
8
33
|
return previous.length <= next.length && previous.every((entry, i) => {
|
|
9
34
|
const current = next[i];
|
|
@@ -11,10 +36,13 @@ function isAppendOnly(previous, next) {
|
|
|
11
36
|
});
|
|
12
37
|
}
|
|
13
38
|
function XtermOutput({
|
|
14
|
-
entries
|
|
39
|
+
entries,
|
|
40
|
+
locale = "en",
|
|
41
|
+
translations
|
|
15
42
|
}) {
|
|
43
|
+
const labels = resolveAddonMessages(locale, translations);
|
|
16
44
|
const element = react.useRef(null);
|
|
17
|
-
const
|
|
45
|
+
const terminal2 = react.useRef(null);
|
|
18
46
|
const written = react.useRef([]);
|
|
19
47
|
react.useEffect(() => {
|
|
20
48
|
if (!element.current) return;
|
|
@@ -50,17 +78,17 @@ function XtermOutput({
|
|
|
50
78
|
resizeToContainer();
|
|
51
79
|
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resizeToContainer);
|
|
52
80
|
observer?.observe(container);
|
|
53
|
-
|
|
81
|
+
terminal2.current = instance;
|
|
54
82
|
written.current = [];
|
|
55
83
|
return () => {
|
|
56
84
|
observer?.disconnect();
|
|
57
|
-
|
|
85
|
+
terminal2.current = null;
|
|
58
86
|
written.current = [];
|
|
59
87
|
instance.dispose();
|
|
60
88
|
};
|
|
61
89
|
}, []);
|
|
62
90
|
react.useEffect(() => {
|
|
63
|
-
const instance =
|
|
91
|
+
const instance = terminal2.current;
|
|
64
92
|
if (!instance) return;
|
|
65
93
|
const appendOnly = isAppendOnly(written.current, entries);
|
|
66
94
|
if (!appendOnly) instance.reset();
|
|
@@ -76,7 +104,7 @@ function XtermOutput({
|
|
|
76
104
|
{
|
|
77
105
|
ref: element,
|
|
78
106
|
className: "console-xterm-output",
|
|
79
|
-
"aria-label":
|
|
107
|
+
"aria-label": labels.terminal
|
|
80
108
|
}
|
|
81
109
|
);
|
|
82
110
|
}
|
|
@@ -88,13 +116,19 @@ const xtermOutputRenderer = {
|
|
|
88
116
|
return /* @__PURE__ */ jsxRuntime.jsx(XtermOutput, { entries: context.entries });
|
|
89
117
|
}
|
|
90
118
|
};
|
|
91
|
-
function createConsoleXtermAddon() {
|
|
119
|
+
function createConsoleXtermAddon(options = {}) {
|
|
92
120
|
return {
|
|
93
121
|
id: CONSOLE_XTERM_ADDON_ID,
|
|
94
122
|
activate(host) {
|
|
95
123
|
host.extensions.register(
|
|
96
124
|
consoleCore.consoleExtensionPoints.outputRenderer,
|
|
97
|
-
|
|
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
|
+
},
|
|
98
132
|
{
|
|
99
133
|
id: `${CONSOLE_XTERM_ADDON_ID}:output-renderer`
|
|
100
134
|
}
|
|
@@ -106,4 +140,5 @@ exports.CONSOLE_XTERM_ADDON_ID = CONSOLE_XTERM_ADDON_ID;
|
|
|
106
140
|
exports.XtermOutput = XtermOutput;
|
|
107
141
|
exports.createConsoleXtermAddon = createConsoleXtermAddon;
|
|
108
142
|
exports.isAppendOnly = isAppendOnly;
|
|
143
|
+
exports.resolveAddonMessages = resolveAddonMessages;
|
|
109
144
|
exports.xtermOutputRenderer = xtermOutputRenderer;
|
package/dist/index.d.cts
ADDED
|
@@ -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";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type { AddonTranslations } from "./localization.js";
|
|
2
|
+
export { resolveAddonMessages } from "./localization.js";
|
|
3
|
+
export type { AddonTranslations } from "./localization.js";
|
|
1
4
|
import { type ConsoleAddon, type ConsoleOutputRenderer } from "@moyarich/console-core";
|
|
2
5
|
export declare const CONSOLE_XTERM_ADDON_ID = "@moyarich/console-addon-xterm";
|
|
3
6
|
export declare const xtermOutputRenderer: ConsoleOutputRenderer;
|
|
4
|
-
export declare function createConsoleXtermAddon(
|
|
5
|
-
|
|
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
CHANGED
|
@@ -2,6 +2,31 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { consoleExtensionPoints } from "@moyarich/console-core";
|
|
3
3
|
import { useRef, useEffect } from "react";
|
|
4
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
|
+
}
|
|
5
30
|
function isAppendOnly(previous, next) {
|
|
6
31
|
return previous.length <= next.length && previous.every((entry, i) => {
|
|
7
32
|
const current = next[i];
|
|
@@ -9,10 +34,13 @@ function isAppendOnly(previous, next) {
|
|
|
9
34
|
});
|
|
10
35
|
}
|
|
11
36
|
function XtermOutput({
|
|
12
|
-
entries
|
|
37
|
+
entries,
|
|
38
|
+
locale = "en",
|
|
39
|
+
translations
|
|
13
40
|
}) {
|
|
41
|
+
const labels = resolveAddonMessages(locale, translations);
|
|
14
42
|
const element = useRef(null);
|
|
15
|
-
const
|
|
43
|
+
const terminal2 = useRef(null);
|
|
16
44
|
const written = useRef([]);
|
|
17
45
|
useEffect(() => {
|
|
18
46
|
if (!element.current) return;
|
|
@@ -48,17 +76,17 @@ function XtermOutput({
|
|
|
48
76
|
resizeToContainer();
|
|
49
77
|
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(resizeToContainer);
|
|
50
78
|
observer?.observe(container);
|
|
51
|
-
|
|
79
|
+
terminal2.current = instance;
|
|
52
80
|
written.current = [];
|
|
53
81
|
return () => {
|
|
54
82
|
observer?.disconnect();
|
|
55
|
-
|
|
83
|
+
terminal2.current = null;
|
|
56
84
|
written.current = [];
|
|
57
85
|
instance.dispose();
|
|
58
86
|
};
|
|
59
87
|
}, []);
|
|
60
88
|
useEffect(() => {
|
|
61
|
-
const instance =
|
|
89
|
+
const instance = terminal2.current;
|
|
62
90
|
if (!instance) return;
|
|
63
91
|
const appendOnly = isAppendOnly(written.current, entries);
|
|
64
92
|
if (!appendOnly) instance.reset();
|
|
@@ -74,7 +102,7 @@ function XtermOutput({
|
|
|
74
102
|
{
|
|
75
103
|
ref: element,
|
|
76
104
|
className: "console-xterm-output",
|
|
77
|
-
"aria-label":
|
|
105
|
+
"aria-label": labels.terminal
|
|
78
106
|
}
|
|
79
107
|
);
|
|
80
108
|
}
|
|
@@ -86,13 +114,19 @@ const xtermOutputRenderer = {
|
|
|
86
114
|
return /* @__PURE__ */ jsx(XtermOutput, { entries: context.entries });
|
|
87
115
|
}
|
|
88
116
|
};
|
|
89
|
-
function createConsoleXtermAddon() {
|
|
117
|
+
function createConsoleXtermAddon(options = {}) {
|
|
90
118
|
return {
|
|
91
119
|
id: CONSOLE_XTERM_ADDON_ID,
|
|
92
120
|
activate(host) {
|
|
93
121
|
host.extensions.register(
|
|
94
122
|
consoleExtensionPoints.outputRenderer,
|
|
95
|
-
|
|
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
|
+
},
|
|
96
130
|
{
|
|
97
131
|
id: `${CONSOLE_XTERM_ADDON_ID}:output-renderer`
|
|
98
132
|
}
|
|
@@ -105,5 +139,6 @@ export {
|
|
|
105
139
|
XtermOutput,
|
|
106
140
|
createConsoleXtermAddon,
|
|
107
141
|
isAppendOnly,
|
|
142
|
+
resolveAddonMessages,
|
|
108
143
|
xtermOutputRenderer
|
|
109
144
|
};
|
package/dist/styles.css
ADDED
|
@@ -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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moyarich/console-addon-xterm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Optional xterm.js terminal renderer for Console",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,11 +9,16 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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"
|
|
17
22
|
},
|
|
18
23
|
"files": [
|
|
19
24
|
"dist"
|
|
@@ -22,20 +27,20 @@
|
|
|
22
27
|
"registry": "https://npm.pkg.github.com"
|
|
23
28
|
},
|
|
24
29
|
"scripts": {
|
|
25
|
-
"build": "vite build && tsc -p tsconfig.build.json",
|
|
30
|
+
"build": "vite build && tsc -p tsconfig.build.json && node ../../../scripts/prepare-cjs-types.mjs && node ../../../scripts/prepare-addon-styles.mjs",
|
|
26
31
|
"typecheck": "tsc --noEmit"
|
|
27
32
|
},
|
|
28
33
|
"peerDependencies": {
|
|
29
|
-
"@moyarich/console-core": "^0.
|
|
30
|
-
"@moyarich/console": "^0.
|
|
34
|
+
"@moyarich/console-core": "^0.2.0",
|
|
35
|
+
"@moyarich/console": "^0.2.0",
|
|
31
36
|
"react": ">=18"
|
|
32
37
|
},
|
|
33
38
|
"dependencies": {
|
|
34
39
|
"@xterm/xterm": "^6.0.0"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
|
-
"@moyarich/console-core": "0.
|
|
38
|
-
"@moyarich/console": "0.
|
|
42
|
+
"@moyarich/console-core": "0.2.0",
|
|
43
|
+
"@moyarich/console": "0.2.0",
|
|
39
44
|
"@types/react": "^19.1.12",
|
|
40
45
|
"react": "^19.2.7",
|
|
41
46
|
"typescript": "^5.9.2",
|
|
@@ -50,14 +55,22 @@
|
|
|
50
55
|
"./src/index.tsx",
|
|
51
56
|
"./src/XtermOutput.css",
|
|
52
57
|
"./dist/index.js",
|
|
53
|
-
"./dist/index.cjs"
|
|
58
|
+
"./dist/index.cjs",
|
|
59
|
+
"./dist/styles.css"
|
|
54
60
|
],
|
|
55
61
|
"publisher": "moyarich",
|
|
56
62
|
"author": "Moya Richards",
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=24"
|
|
65
|
+
},
|
|
57
66
|
"private": false,
|
|
58
67
|
"keywords": [
|
|
59
68
|
"console",
|
|
60
69
|
"addon",
|
|
61
70
|
"xterm"
|
|
62
|
-
]
|
|
71
|
+
],
|
|
72
|
+
"homepage": "https://moyarich.github.io/console/",
|
|
73
|
+
"bugs": {
|
|
74
|
+
"url": "https://github.com/moyarich/console/issues"
|
|
75
|
+
}
|
|
63
76
|
}
|