marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
7.5k stars 259 forks source link

Terminal emulation, either at the top level or as a UI component. (`prompt_toolkit` compatibility!) #1747

Open patrick-kidger opened 3 months ago

patrick-kidger commented 3 months ago

Description

Here's a quick MWE for a program that errors out when ran from Marimo. I'm using prompt_toolkit as a popular example of a library that requires terminal emulation. (I'm using threading just to work around #1746.)

import prompt_toolkit
import threading
t = threading.Thread(target=lambda: prompt_toolkit.prompt("Hello."))
t.start()
t.join()

Context

For context, a major limiting factor of Jupyter -- at least for me! -- has been its lack of support for terminal emulation. This means it is incompatible with a lot of interesting TUI programs, so I just end up never using notebooks at all.

Having recently discovered Marimo, I've been really pleased to see how it fixes so many of my complaints about Jupyter (hidden state, git friendly, etc.). Is there any chance you could add to this list by also supporting terminal emulation?

Example use cases

For a couple of concrete use-cases, I'm a fan of both ptpython for opening embedded shells, and pudb as a debugger that's better than the built-in pdb. Both require that the output be a terminal emulator.

Suggested solution

A quick google turns up XTerm.js. I've not used this / have no preference about implementation whatsoever. But as such my initial impression is that this might be a reasonable ask. (And not a large 'implement a terminal from scratch' kind of project!)

akshayka commented 3 months ago

@patrick-kidger , we added a terminal, and it's available in the latest version of marimo. Thanks for opening this issue!

patrick-kidger commented 3 months ago

Nice! Poking around a bit I've found this PR:

https://github.com/marimo-team/marimo/pull/1786

which I assume is what you're referencing. I can see that this adds a terminal button to the bottom of the webpage.

What's the appropriate way to wire up the terminal to the output of a cell? (So that e.g. the code snippet above works.)

akshayka commented 3 months ago

Sorry, I misunderstood your original issue after pattern matching on xterm.js.

stdin in marimo is indeed not a terminal. What you're asking for should be possible, but it's a nontrivial amount of work on the backend.