numbl 0.4.15 → 0.4.16

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.
@@ -23,6 +23,13 @@ export interface BootMessage {
23
23
  * page is cross-origin isolated (SharedArrayBuffer available).
24
24
  */
25
25
  cancelSAB?: SharedArrayBuffer;
26
+ /**
27
+ * Shared channel for synchronous `input()` (stdin). The worker blocks on it
28
+ * (Atomics.wait) after asking the host for a line via a `request-input`
29
+ * message; the host writes the reply back through it (see syncInputChannel).
30
+ * Only present when the page is cross-origin isolated.
31
+ */
32
+ inputSAB?: SharedArrayBuffer;
26
33
  }
27
34
  export type ToWorker = BootMessage | {
28
35
  type: "writeFile";
@@ -83,6 +90,9 @@ export type FromWorker = {
83
90
  } | {
84
91
  type: "bootError";
85
92
  message: string;
93
+ } | {
94
+ type: "request-input";
95
+ prompt: string;
86
96
  } | {
87
97
  type: "htmlSourceEvent";
88
98
  compId: string;
@@ -27,6 +27,13 @@ export interface NumblSessionOptions {
27
27
  onOutput?: (text: string) => void;
28
28
  /** Boot progress (package downloads, engine start). */
29
29
  onProgress?: (message: string) => void;
30
+ /**
31
+ * Called when running code reaches `input()` and needs a line of input.
32
+ * The execution is blocked until the host calls `provideInput(text)` with
33
+ * the user's response. Requires cross-origin isolation (see `canInput`);
34
+ * without it, `input()` errors instead of calling this.
35
+ */
36
+ onInputRequest?: (prompt: string) => void;
30
37
  /** A uihtml component was created/updated (Data JSON-encoded + markup). */
31
38
  onUihtml?: (compId: string, dataJson: string, html: string) => void;
32
39
  /** Script -> host events (MATLAB `sendEventToHTMLSource`). */
@@ -71,6 +78,19 @@ export interface NumblSession {
71
78
  * run can only be stopped by disposing the session.
72
79
  */
73
80
  readonly canInterrupt: boolean;
81
+ /**
82
+ * Supply the line of input that a pending `onInputRequest` is waiting for.
83
+ * Unblocks the `input()` call in the running code, which resumes with this
84
+ * text. Call exactly once per `onInputRequest`. No-op when `canInput` is
85
+ * false or nothing is waiting.
86
+ */
87
+ provideInput(text: string): void;
88
+ /**
89
+ * Whether `input()` (stdin) works — true only when the page is cross-origin
90
+ * isolated. When false, `input()` in executed code throws instead of
91
+ * calling `onInputRequest`.
92
+ */
93
+ readonly canInput: boolean;
74
94
  /** Terminate the worker. The session is unusable afterwards. */
75
95
  dispose(): void;
76
96
  }