A utility library for interacting with JAnim GUI and managing windows via standard input/output
https://github.com/jkjkil4/janim-stdio-interact.git
> English < | ็ฎไฝไธญๆ
A utility library for interacting with JAnim GUI and managing windows via standard input/output
Interact with the JAnim GUI by passing JSON commands via stdio to open and close specific instances.
First, start the janim-stdio-i program:
janim-stdio-i host
For example, to compile a code snippet and build the Timeline within it for display in a preview window, send the following to stdin:
{"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(HelloJAnimExample): pass"}
You will see a preview window open displaying the classic HelloJAnimExample.
[!WARNING]
All commands sent tostdinmust be on a single line. Multi-line commands will be truncated.
Here, "key": "id1" is used for window reuse. If you send an execute command with the same key, the Timeline in the existing window will be replaced without opening a new window.
{"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(RotatingPieExample): ..."}
Sending the command above replaces the HelloJAnimExample in the original window with RotatingPieExample.
[!NOTE]
If a code snippet contains multiple Timelines, the first one is used for the initial build.
> On subsequent rebuilds (replacements), it attempts to find a Timeline with the same name as the previous one; if not found, it defaults to the first one.
If we use a different key, for example:
{"type": "execute", "key": "id2", "source": "from janim.examples import *\nclass A(ArrowPointingExample): ..."}
A new window will open. Essentially, one key corresponds to one window.
In addition to compiling and building Timelines via stdin, information generated by the GUI is returned via stdout. See below for details.
stdin"type": "execute""key": Unique identifier for the window."source": Source code for compilation. If the window corresponding to key already exists, the original Timeline in that window is replaced with the new one.
Example:
{"type": "execute", "key": "id1", "source": "from janim.examples import *\nclass A(HelloJAnimExample): pass"}
"type": "close""key": Unique identifier for the window.key.
Example:
{"type": "close", "key": "id1"}
stdout{"type": "viewer-msg", "key": "...", "from": "...", "janim": { ... }}
| Field | Type | Description |
|---|---|---|
type | string | Fixed as "viewer-msg", identifying the message category |
key | string | Corresponds to the identifier key used during creation |
from | string | Sender source. Possible values: "execute", "close", "gui" |
janim | object | The specific event payload, containing the event type and data |
"from": "execute", it represents the result of the execute command sent to stdin:
"janim": {"type": "error", "reason": "compile-failed"}
"janim": {"type": "error", "reason": "no-timeline"}
"janim": {"type": "error", "reason": "build-failed"}
"janim": {"type": "success"}
When "from": "close", it represents the result of the close command sent to stdin:
"janim": {"type": "error", "reason": "not-found"}
"janim": {"type": "success"}
When "from": "gui", it represents information generated by the GUI:
"janim": {"type": "created"}
"janim": {"type": "rebuilt"}
"janim": {"type": "lineno", "data": <current_line_number>}
"janim": {"type": "close_event"}