From 6b7c1b16c94bdef3a3b6ebb20727575654cabc51 Mon Sep 17 00:00:00 2001 From: Project516 <138796702+Project516@users.noreply.github.com> Date: Sun, 1 Nov 2026 15:48:23 -0600 Subject: [PATCH] Document javaWebWriteStdin and make it require cheerpjInit first. --- docs/browser.md | 4 ++++ src/browser/api.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/docs/browser.md b/docs/browser.md index 956ca8c..0baf24c 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -37,6 +37,10 @@ and `cjFileBlob(path)` also work. `/files/uploads/` exists for files the page adds there. - The browser console gets whole lines, so two `print` calls and a `println` log one line. A partial line is logged after 100 ms. +- `javaWebWriteStdin(text)` feeds `System.in` (CheerpJ has no such call). A read + waits until the page sends text, and text sent before Java reads it is kept. + `javaWebWriteStdin(null)` ends the input. Nothing is echoed, so the page shows + what the user typed itself. Library mode calls Java from JS, as in CheerpJ's library mode guide. The VM stays up between calls: diff --git a/src/browser/api.ts b/src/browser/api.ts index 88b41a9..b8312c5 100644 --- a/src/browser/api.ts +++ b/src/browser/api.ts @@ -277,6 +277,7 @@ export function cheerpOSRemoveStringFile(path: string) { // Feeds System.in; null ends the input. export function javaWebWriteStdin(data: string | null) { + if (!worker) throw new Error("call cheerpjInit() first"); send({ type: "stdin", data: data === null ? null : new TextEncoder().encode(data) }); }