denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.04k stars 5.23k forks source link

[feature-request] [jupyter] support entering a value inline, with the web standard function `prompt` #22633

Closed NaitLee closed 2 months ago

NaitLee commented 6 months ago

With Jupyter with ipykernel, the notebook has an input box for the Python input function: Screenshot_20240229_200104

In Deno there’s the web standard prompt, for the same purpose as input in my mind, but with Deno as a Jupyter kernel it simply returns null instead: Screenshot_20240229_200743 Same for Jupyter console: Screenshot_20240229_201804

It could be better to put this function in use for Jupyter notebook, just like its behavior in Deno console and web browser :) Screenshot_20240229_200818

zph commented 5 months ago

I'm also interested in this functionality for deno's jupyter kernel.

Problem Statement

Add prompt and input handling in Deno’s Kernel for Jupyter Notebook integration.

The experience should match what happens in a python based Jupyter Notebook when using prompt or input functions.

Code Tracing

Where handler lives in both deno + excxr (the source for deno's jupyter integration)

Deno: https://github.com/denoland/deno/blob/main/cli/tools/jupyter/server.rs#L347 Evcxr: https://github.com/evcxr/evcxr/blob/main/evcxr_jupyter/src/core.rs#L202 and https://github.com/evcxr/evcxr/blob/main/evcxr_jupyter/src/core.rs#L217

Handling allow_stdin is how this is done in Jupyter and the message itself will look like:

{"user_variables":[],"code":"1\n","silent":false,"allow_stdin":true,"store_history":true,"user_expressions":{}} ]

It's beyond my current proficiency in Rust to implement and port over from excxr, but I'm happy to test it out if someone else puts up a PR.