@moyarich/console-addon-process-state 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 CHANGED
@@ -2,12 +2,18 @@
2
2
 
3
3
  Track terminal process progress. Interpret OSC progress, working directory, command lifecycle, and notifications without requiring xterm.js.
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-process-state
10
+ npm install @moyarich/console @moyarich/console-addon-process-state 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`, `react@>=18`.
16
+
11
17
  ## Quick start
12
18
 
13
19
  ```tsx
@@ -0,0 +1,19 @@
1
+ import { type ProcessStateTranslations } from "./localization.cjs";
2
+ import { type CSSProperties } from "react";
3
+ import type { ProcessStateController } from "./index.cjs";
4
+
5
+ export interface ConsoleProgressIndicatorOptions {
6
+ locale?: string;
7
+ translations?: ProcessStateTranslations;
8
+ className?: string;
9
+ style?: CSSProperties;
10
+ /** Custom label for the determinate progress mode. */
11
+ format?: (percentage: number, state: number) => string;
12
+ /** Keep the progress strip visible after a clear command. */
13
+ showCleared?: boolean;
14
+ }
15
+ export interface ConsoleProgressIndicatorProps extends ConsoleProgressIndicatorOptions {
16
+ controller: ProcessStateController;
17
+ }
18
+ /** Read-only, optional status strip; it never modifies terminal output or scroll position. */
19
+ export declare function ConsoleProgressIndicator({ controller, className, style, format, showCleared, locale, translations, }: ConsoleProgressIndicatorProps): import("react").JSX.Element | null;
@@ -1,7 +1,10 @@
1
+ import { type ProcessStateTranslations } from "./localization.js";
1
2
  import { type CSSProperties } from "react";
2
- import type { ProcessStateController } from "./index";
3
- import "./ProgressIndicator.css";
3
+ import type { ProcessStateController } from "./index.js";
4
+
4
5
  export interface ConsoleProgressIndicatorOptions {
6
+ locale?: string;
7
+ translations?: ProcessStateTranslations;
5
8
  className?: string;
6
9
  style?: CSSProperties;
7
10
  /** Custom label for the determinate progress mode. */
@@ -13,4 +16,4 @@ export interface ConsoleProgressIndicatorProps extends ConsoleProgressIndicatorO
13
16
  controller: ProcessStateController;
14
17
  }
15
18
  /** Read-only, optional status strip; it never modifies terminal output or scroll position. */
16
- export declare function ConsoleProgressIndicator({ controller, className, style, format, showCleared, }: ConsoleProgressIndicatorProps): import("react").JSX.Element | null;
19
+ export declare function ConsoleProgressIndicator({ controller, className, style, format, showCleared, locale, translations, }: ConsoleProgressIndicatorProps): import("react").JSX.Element | null;
package/dist/index.cjs CHANGED
@@ -3,35 +3,95 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
4
  const jsxRuntime = require("react/jsx-runtime");
5
5
  const consoleCore = require("@moyarich/console-core");
6
+ const cleared$3 = "Progress cleared";
7
+ const working$3 = "Working";
8
+ const error$3 = "Process error";
9
+ const paused$3 = "Paused";
10
+ const progress$3 = "In progress";
11
+ const en = {
12
+ cleared: cleared$3,
13
+ working: working$3,
14
+ error: error$3,
15
+ paused: paused$3,
16
+ progress: progress$3
17
+ };
18
+ const cleared$2 = "Progreso borrado";
19
+ const working$2 = "Trabajando";
20
+ const error$2 = "Error del proceso";
21
+ const paused$2 = "En pausa";
22
+ const progress$2 = "En curso";
23
+ const es = {
24
+ cleared: cleared$2,
25
+ working: working$2,
26
+ error: error$2,
27
+ paused: paused$2,
28
+ progress: progress$2
29
+ };
30
+ const cleared$1 = "Progression effacée";
31
+ const working$1 = "En cours";
32
+ const error$1 = "Erreur du processus";
33
+ const paused$1 = "En pause";
34
+ const progress$1 = "En progression";
35
+ const fr = {
36
+ cleared: cleared$1,
37
+ working: working$1,
38
+ error: error$1,
39
+ paused: paused$1,
40
+ progress: progress$1
41
+ };
42
+ const cleared = "Progresso limpo";
43
+ const working = "Trabalhando";
44
+ const error = "Erro do processo";
45
+ const paused = "Pausado";
46
+ const progress = "Em andamento";
47
+ const pt = {
48
+ cleared,
49
+ working,
50
+ error,
51
+ paused,
52
+ progress
53
+ };
54
+ const locales = { en, es, fr, pt };
55
+ function resolveProcessStateMessages(locale = "en", overrides) {
56
+ const tag = locale.replace(/_/g, "-").toLowerCase();
57
+ return {
58
+ ...en,
59
+ ...locales[tag] ?? locales[tag.split("-")[0]] ?? {},
60
+ ...overrides
61
+ };
62
+ }
6
63
  function ConsoleProgressIndicator({
7
64
  controller,
8
65
  className,
9
66
  style,
10
67
  format,
11
- showCleared = false
68
+ showCleared = false,
69
+ locale = "en",
70
+ translations
12
71
  }) {
13
72
  const state = react.useSyncExternalStore(
14
73
  controller.subscribe,
15
74
  controller.getState,
16
75
  controller.getState
17
76
  );
18
- const progress = state.progress;
19
- if (!progress || progress.state === 0 && !showCleared) return null;
20
- const value = progress.value ?? 0;
21
- const label = progress.state === 0 ? "Progress cleared" : progress.state === 3 ? "Working" : progress.state === 2 ? "Process error" : progress.state === 4 ? "Paused" : "In progress";
22
- const description = progress.state === 0 ? label : progress.state === 3 ? label : format?.(value, progress.state) ?? `${label}: ${value}%`;
77
+ const progress2 = state.progress;
78
+ const labels = resolveProcessStateMessages(locale, translations);
79
+ if (!progress2 || progress2.state === 0 && !showCleared) return null;
80
+ const value = progress2.value ?? 0;
81
+ const label = progress2.state === 0 ? labels.cleared : progress2.state === 3 ? labels.working : progress2.state === 2 ? labels.error : progress2.state === 4 ? labels.paused : labels.progress;
82
+ const description = progress2.state === 0 ? label : progress2.state === 3 ? label : format?.(value, progress2.state) ?? `${label}: ${value}%`;
23
83
  return /* @__PURE__ */ jsxRuntime.jsxs(
24
84
  "div",
25
85
  {
26
86
  className: ["console-progress-indicator", className].filter(Boolean).join(" "),
27
- "data-state": progress.state,
87
+ "data-state": progress2.state,
28
88
  style,
29
89
  role: "status",
30
90
  "aria-live": "polite",
31
91
  "aria-label": description,
32
92
  children: [
33
93
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "console-progress-indicator__label", children: description }),
34
- progress.state !== 0 && /* @__PURE__ */ jsxRuntime.jsx(
94
+ progress2.state !== 0 && /* @__PURE__ */ jsxRuntime.jsx(
35
95
  "div",
36
96
  {
37
97
  className: "console-progress-indicator__track",
@@ -39,12 +99,12 @@ function ConsoleProgressIndicator({
39
99
  "aria-label": label,
40
100
  "aria-valuemin": 0,
41
101
  "aria-valuemax": 100,
42
- "aria-valuenow": progress.state === 3 ? void 0 : value,
102
+ "aria-valuenow": progress2.state === 3 ? void 0 : value,
43
103
  children: /* @__PURE__ */ jsxRuntime.jsx(
44
104
  "div",
45
105
  {
46
106
  className: "console-progress-indicator__fill",
47
- style: { width: `${progress.state === 3 ? 30 : value}%` }
107
+ style: { width: `${progress2.state === 3 ? 30 : value}%` }
48
108
  }
49
109
  )
50
110
  }
@@ -263,3 +323,4 @@ exports.consoleProcessStateService = consoleProcessStateService;
263
323
  exports.createConsoleProcessStateAddon = createConsoleProcessStateAddon;
264
324
  exports.createProcessStateController = createProcessStateController;
265
325
  exports.createProcessStateParser = createProcessStateParser;
326
+ exports.resolveProcessStateMessages = resolveProcessStateMessages;
@@ -0,0 +1,58 @@
1
+ import { type ConsoleProgressIndicatorOptions } from "./ProgressIndicator.cjs";
2
+ export { ConsoleProgressIndicator } from "./ProgressIndicator.cjs";
3
+ export { resolveProcessStateMessages } from "./localization.cjs";
4
+ export type { ProcessStateTranslations } from "./localization.cjs";
5
+ export type { ConsoleProgressIndicatorOptions } from "./ProgressIndicator.cjs";
6
+ import { type ConsoleAddon, type ConsoleProcessControlParser } from "@moyarich/console-core";
7
+ export declare const CONSOLE_PROCESS_STATE_ADDON_ID = "@moyarich/console-addon-process-state";
8
+ export interface ProcessState {
9
+ readonly progress?: {
10
+ readonly state: number;
11
+ readonly value?: number;
12
+ };
13
+ readonly cwd?: string;
14
+ readonly command?: {
15
+ readonly phase: "prompt" | "started" | "executing" | "finished";
16
+ readonly exitCode?: number;
17
+ };
18
+ readonly notifications: readonly {
19
+ readonly title: string;
20
+ readonly message: string;
21
+ }[];
22
+ }
23
+ export type ProcessStateEvent = {
24
+ readonly type: "progress";
25
+ readonly state: number;
26
+ readonly value?: number;
27
+ } | {
28
+ readonly type: "cwd";
29
+ readonly cwd: string;
30
+ } | {
31
+ readonly type: "command";
32
+ readonly phase: "prompt" | "started" | "executing" | "finished";
33
+ readonly exitCode?: number;
34
+ } | {
35
+ readonly type: "notification";
36
+ readonly title: string;
37
+ readonly message: string;
38
+ };
39
+ export interface ProcessStateController {
40
+ getState(): ProcessState;
41
+ getEvents(): readonly ProcessStateEvent[];
42
+ subscribe(listener: () => void): () => void;
43
+ reset(): void;
44
+ apply(event: ProcessStateEvent): void;
45
+ }
46
+ export declare const consoleProcessStateService: import("@moyarich/console-core").ConsoleServiceToken<ProcessStateController>;
47
+ export declare function createProcessStateController(): ProcessStateController;
48
+ /** Stateful OSC decoder; parsed sequences are removed while printable text is preserved. */
49
+ export declare function createProcessStateParser(controller: ProcessStateController): ConsoleProcessControlParser;
50
+ export interface ProcessStateAddon extends ConsoleAddon {
51
+ readonly controller: ProcessStateController;
52
+ }
53
+ export interface ProcessStateAddonOptions {
54
+ controller?: ProcessStateController;
55
+ /** Set to true or provide options to display a compact status strip. Default: headless. */
56
+ indicator?: boolean | ConsoleProgressIndicatorOptions;
57
+ }
58
+ export declare function createConsoleProcessStateAddon(options?: ProcessStateController | ProcessStateAddonOptions): ProcessStateAddon;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { type ConsoleProgressIndicatorOptions } from "./ProgressIndicator";
2
- export { ConsoleProgressIndicator } from "./ProgressIndicator";
3
- export type { ConsoleProgressIndicatorOptions } from "./ProgressIndicator";
1
+ import { type ConsoleProgressIndicatorOptions } from "./ProgressIndicator.js";
2
+ export { ConsoleProgressIndicator } from "./ProgressIndicator.js";
3
+ export { resolveProcessStateMessages } from "./localization.js";
4
+ export type { ProcessStateTranslations } from "./localization.js";
5
+ export type { ConsoleProgressIndicatorOptions } from "./ProgressIndicator.js";
4
6
  import { type ConsoleAddon, type ConsoleProcessControlParser } from "@moyarich/console-core";
5
7
  export declare const CONSOLE_PROCESS_STATE_ADDON_ID = "@moyarich/console-addon-process-state";
6
8
  export interface ProcessState {
package/dist/index.js CHANGED
@@ -1,35 +1,95 @@
1
1
  import { useSyncExternalStore, createElement } from "react";
2
2
  import { jsxs, jsx } from "react/jsx-runtime";
3
3
  import { createConsoleServiceToken, consoleExtensionPoints } from "@moyarich/console-core";
4
+ const cleared$3 = "Progress cleared";
5
+ const working$3 = "Working";
6
+ const error$3 = "Process error";
7
+ const paused$3 = "Paused";
8
+ const progress$3 = "In progress";
9
+ const en = {
10
+ cleared: cleared$3,
11
+ working: working$3,
12
+ error: error$3,
13
+ paused: paused$3,
14
+ progress: progress$3
15
+ };
16
+ const cleared$2 = "Progreso borrado";
17
+ const working$2 = "Trabajando";
18
+ const error$2 = "Error del proceso";
19
+ const paused$2 = "En pausa";
20
+ const progress$2 = "En curso";
21
+ const es = {
22
+ cleared: cleared$2,
23
+ working: working$2,
24
+ error: error$2,
25
+ paused: paused$2,
26
+ progress: progress$2
27
+ };
28
+ const cleared$1 = "Progression effacée";
29
+ const working$1 = "En cours";
30
+ const error$1 = "Erreur du processus";
31
+ const paused$1 = "En pause";
32
+ const progress$1 = "En progression";
33
+ const fr = {
34
+ cleared: cleared$1,
35
+ working: working$1,
36
+ error: error$1,
37
+ paused: paused$1,
38
+ progress: progress$1
39
+ };
40
+ const cleared = "Progresso limpo";
41
+ const working = "Trabalhando";
42
+ const error = "Erro do processo";
43
+ const paused = "Pausado";
44
+ const progress = "Em andamento";
45
+ const pt = {
46
+ cleared,
47
+ working,
48
+ error,
49
+ paused,
50
+ progress
51
+ };
52
+ const locales = { en, es, fr, pt };
53
+ function resolveProcessStateMessages(locale = "en", overrides) {
54
+ const tag = locale.replace(/_/g, "-").toLowerCase();
55
+ return {
56
+ ...en,
57
+ ...locales[tag] ?? locales[tag.split("-")[0]] ?? {},
58
+ ...overrides
59
+ };
60
+ }
4
61
  function ConsoleProgressIndicator({
5
62
  controller,
6
63
  className,
7
64
  style,
8
65
  format,
9
- showCleared = false
66
+ showCleared = false,
67
+ locale = "en",
68
+ translations
10
69
  }) {
11
70
  const state = useSyncExternalStore(
12
71
  controller.subscribe,
13
72
  controller.getState,
14
73
  controller.getState
15
74
  );
16
- const progress = state.progress;
17
- if (!progress || progress.state === 0 && !showCleared) return null;
18
- const value = progress.value ?? 0;
19
- const label = progress.state === 0 ? "Progress cleared" : progress.state === 3 ? "Working" : progress.state === 2 ? "Process error" : progress.state === 4 ? "Paused" : "In progress";
20
- const description = progress.state === 0 ? label : progress.state === 3 ? label : format?.(value, progress.state) ?? `${label}: ${value}%`;
75
+ const progress2 = state.progress;
76
+ const labels = resolveProcessStateMessages(locale, translations);
77
+ if (!progress2 || progress2.state === 0 && !showCleared) return null;
78
+ const value = progress2.value ?? 0;
79
+ const label = progress2.state === 0 ? labels.cleared : progress2.state === 3 ? labels.working : progress2.state === 2 ? labels.error : progress2.state === 4 ? labels.paused : labels.progress;
80
+ const description = progress2.state === 0 ? label : progress2.state === 3 ? label : format?.(value, progress2.state) ?? `${label}: ${value}%`;
21
81
  return /* @__PURE__ */ jsxs(
22
82
  "div",
23
83
  {
24
84
  className: ["console-progress-indicator", className].filter(Boolean).join(" "),
25
- "data-state": progress.state,
85
+ "data-state": progress2.state,
26
86
  style,
27
87
  role: "status",
28
88
  "aria-live": "polite",
29
89
  "aria-label": description,
30
90
  children: [
31
91
  /* @__PURE__ */ jsx("span", { className: "console-progress-indicator__label", children: description }),
32
- progress.state !== 0 && /* @__PURE__ */ jsx(
92
+ progress2.state !== 0 && /* @__PURE__ */ jsx(
33
93
  "div",
34
94
  {
35
95
  className: "console-progress-indicator__track",
@@ -37,12 +97,12 @@ function ConsoleProgressIndicator({
37
97
  "aria-label": label,
38
98
  "aria-valuemin": 0,
39
99
  "aria-valuemax": 100,
40
- "aria-valuenow": progress.state === 3 ? void 0 : value,
100
+ "aria-valuenow": progress2.state === 3 ? void 0 : value,
41
101
  children: /* @__PURE__ */ jsx(
42
102
  "div",
43
103
  {
44
104
  className: "console-progress-indicator__fill",
45
- style: { width: `${progress.state === 3 ? 30 : value}%` }
105
+ style: { width: `${progress2.state === 3 ? 30 : value}%` }
46
106
  }
47
107
  )
48
108
  }
@@ -261,5 +321,6 @@ export {
261
321
  consoleProcessStateService,
262
322
  createConsoleProcessStateAddon,
263
323
  createProcessStateController,
264
- createProcessStateParser
324
+ createProcessStateParser,
325
+ resolveProcessStateMessages
265
326
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "cleared": "Progress cleared",
3
+ "working": "Working",
4
+ "error": "Process error",
5
+ "paused": "Paused",
6
+ "progress": "In progress"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cleared": "Progreso borrado",
3
+ "working": "Trabajando",
4
+ "error": "Error del proceso",
5
+ "paused": "En pausa",
6
+ "progress": "En curso"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cleared": "Progression effacée",
3
+ "working": "En cours",
4
+ "error": "Erreur du processus",
5
+ "paused": "En pause",
6
+ "progress": "En progression"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "cleared": "Progresso limpo",
3
+ "working": "Trabalhando",
4
+ "error": "Erro do processo",
5
+ "paused": "Pausado",
6
+ "progress": "Em andamento"
7
+ }
@@ -0,0 +1,3 @@
1
+ import en from "./locales/en.json";
2
+ export type ProcessStateTranslations = Partial<typeof en>;
3
+ export declare function resolveProcessStateMessages(locale?: string, overrides?: ProcessStateTranslations): typeof en;
@@ -0,0 +1,3 @@
1
+ import en from "./locales/en.json";
2
+ export type ProcessStateTranslations = Partial<typeof en>;
3
+ export declare function resolveProcessStateMessages(locale?: string, overrides?: ProcessStateTranslations): typeof en;
@@ -0,0 +1,67 @@
1
+ /* src/ProgressIndicator.css */
2
+ .console-progress-indicator {
3
+ --_progress-fg: var(
4
+ --console-progress-color,
5
+ var(--console-color-accent, currentColor)
6
+ );
7
+ --_progress-track: var(
8
+ --console-progress-track,
9
+ color-mix(in srgb, currentColor 12%, transparent)
10
+ );
11
+ --_progress-text: var(--console-progress-text, inherit);
12
+ /* This overlay has no layout height: updates cannot resize or scroll the terminal. */
13
+ position: sticky;
14
+ top: 0;
15
+ z-index: 2;
16
+ display: flex;
17
+ justify-content: flex-end;
18
+ align-items: center;
19
+ gap: var(--console-progress-gap, 0.75rem);
20
+ box-sizing: border-box;
21
+ height: 0;
22
+ min-height: 0;
23
+ padding: 0 var(--console-progress-inline-padding, 0.75rem);
24
+ pointer-events: none;
25
+ color: var(--_progress-text);
26
+ font: inherit;
27
+ transform: translateY(var(--console-progress-offset, 0.25rem));
28
+ }
29
+ .console-progress-indicator__label {
30
+ flex: none;
31
+ font-size: 0.8em;
32
+ }
33
+ .console-progress-indicator__track {
34
+ flex: 1;
35
+ height: 0.35rem;
36
+ border-radius: 999px;
37
+ background: var(--_progress-track);
38
+ overflow: hidden;
39
+ }
40
+ .console-progress-indicator__fill {
41
+ height: 100%;
42
+ background: var(--_progress-fg);
43
+ transition: width 120ms linear;
44
+ }
45
+ .console-progress-indicator[data-state="2"] .console-progress-indicator__fill {
46
+ background: var(--console-progress-error, #b42318);
47
+ }
48
+ .console-progress-indicator[data-state="4"] .console-progress-indicator__fill {
49
+ background: var(--console-progress-paused, #a46b00);
50
+ }
51
+ .console-progress-indicator[data-state="3"] .console-progress-indicator__fill {
52
+ animation: console-progress-motion 1.5s ease-in-out infinite alternate;
53
+ }
54
+ @keyframes console-progress-motion {
55
+ from {
56
+ transform: translateX(0);
57
+ }
58
+ to {
59
+ transform: translateX(230%);
60
+ }
61
+ }
62
+ @media (prefers-reduced-motion: reduce) {
63
+ .console-progress-indicator__fill {
64
+ transition: none;
65
+ animation: none !important;
66
+ }
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moyarich/console-addon-process-state",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Observable process state from OSC terminal control sequences",
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
- "development": "./src/index.ts",
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs"
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,15 +27,15 @@
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.1.0",
34
+ "@moyarich/console-core": "^0.2.0",
30
35
  "react": ">=18"
31
36
  },
32
37
  "devDependencies": {
33
- "@moyarich/console-core": "0.1.0",
38
+ "@moyarich/console-core": "0.2.0",
34
39
  "typescript": "^5.9.2",
35
40
  "vite": "^7.1.5",
36
41
  "react": "^19.2.7",
@@ -55,9 +60,13 @@
55
60
  "sideEffects": [
56
61
  "./src/ProgressIndicator.css",
57
62
  "./dist/index.js",
58
- "./dist/index.cjs"
63
+ "./dist/index.cjs",
64
+ "./dist/styles.css"
59
65
  ],
60
66
  "publisher": "moyarich",
61
67
  "author": "Moya Richards",
68
+ "engines": {
69
+ "node": ">=24"
70
+ },
62
71
  "private": false
63
72
  }
@@ -1 +0,0 @@
1
- export {};