feat(foreign): raw stdin, per-cell inputs and interrupt
Persistent Python/Node kernels receive raw program stdin per eval; foreign.session accepts an inputs table and view exposes per-cell stdin. Add session interrupt host API and view control.
This commit is contained in:
1 parent
c85f1a2829
commit
064522a338
9 files changed
+86
-2
No files matched your search
+7
-1
@@ -3552,6 +3552,7 @@ body.notebook-page .wb-source-text { color: var(--nb-text); }
|
||||
<button type="button" id="nb-run-all">Run All</button>
|
||||
<button type="button" id="nb-restart">Restart & Run All</button>
|
||||
<button type="button" id="nb-step">Step</button>
|
||||
<button type="button" id="nb-interrupt">Interrupt</button>
|
||||
<button type="button" id="nb-state">State</button>
|
||||
<button type="button" id="nb-journal">Journal</button>
|
||||
<button type="button" id="nb-clear">Clear outputs</button>
|
||||
@@ -3884,7 +3885,7 @@ body.notebook-page .wb-source-text { color: var(--nb-text); }
|
||||
function staticNotice() {
|
||||
status("静态页面无法真实执行 / static export: no live execution");
|
||||
}
|
||||
["nb-run-all", "nb-restart", "nb-step", "nb-state", "nb-journal",
|
||||
["nb-run-all", "nb-restart", "nb-step", "nb-interrupt", "nb-state", "nb-journal",
|
||||
"nb-clear", "nb-reload", "nb-debug", "exec-clear"].forEach(function (id) {
|
||||
bind(id, staticNotice);
|
||||
});
|
||||
@@ -3908,6 +3909,11 @@ body.notebook-page .wb-source-text { color: var(--nb-text); }
|
||||
document.querySelectorAll(".code-card").forEach(bindClean);
|
||||
bind("nb-run-all", function () { runAll(false); });
|
||||
bind("nb-restart", function () { runAll(true); });
|
||||
bind("nb-interrupt", function () {
|
||||
post("api/session/interrupt", {}).then(function (r) {
|
||||
status(r.ok ? "interrupt sent" : (r.error || "interrupt failed"));
|
||||
});
|
||||
});
|
||||
bind("nb-step", function () {
|
||||
if (!state.persistent && Object.keys(state.cells).length === 0) {
|
||||
status("no cells; Run All runs the document");
|
||||
|
||||
@@ -194,6 +194,11 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
notebook_api::api_run_document(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/interrupt" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_interrupt(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/cell/clear" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_clear_cell(&root.root, body)
|
||||
|
||||
@@ -170,6 +170,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn api_interrupt(root: &Path, body: &str) -> serde_json::Value {
|
||||
with_session(root, body, "interrupted", |s| s.interrupt())
|
||||
}
|
||||
|
||||
pub fn api_clear_cell(root: &Path, body: &str) -> serde_json::Value {
|
||||
let v = body_value(body);
|
||||
let cell = v.get("cell").and_then(|x| x.as_str()).unwrap_or("");
|
||||
|
||||
Reference in new issue
Block a user