Is there a reasonably decent JavaScript library th...
# thinking-together
d
Is there a reasonably decent JavaScript library that allows me to have a reasonably terminal-y experience in the browser, so I can implement a shell? Ideally with history, autocomplete, colors, etc. - and then with the ability to add DOM nodes too, so I can click, show images, etc. Preferably no backend necessary.
e
d
Interesting. It seems to be really close to, well XTerm, i.e. it also uses \033[1 instead of just <b>. I wonder if there is something slightly more webb-y in addition to being a shell
a
I wonder if there is something slightly more webb-y
Sounds like a bug 😝
there is terminal.js, if you must, though
d
It seems like it might be easier to implement it from scratch than to fight with all the xterm / ansi compatibility
k
Personally I try to avoid terminals these days after investing 20 years in them. On the other hand I also try to avoid the web 😅
d
how else would you do a CLI? (Lemme guess, the answer is you'd avoid CLIs)
k
Depends on how you define CLI. We tend to think of CLIs (and even TUIs) as requiring a terminal. But if we notice that modern terminals are all implemented atop a canvas of pixels, then arguably everything I build is a CLI. Some examples: • https://git.sr.ht/~akkartik/driver.love is my current favorite REPL. • https://archive.org/details/akkartik-pensieve-2022-08-29 is a less general CLI for browsing a set of text files using a command palette rather than a scrolling session of commands and responses. It seems like you can get all the behaviors we tend to look for in CLIs with very little code if we give up various intermediate levels of abstraction and just go back to drawing text on a canvas of pixels.
d
Thanks! Interesting thoughts, thanks!
d
tty
and
pty
, the core of terminals, are definitely archaic feeling. It feels even crazier as I watch modern terminals add support for sixel (which is an old hack to push images over those protocols). However, there's a ton of tools that understand how to talk with them, so starting from scratch means reinventing most of the toolchain. My approach right now to building a richer renderer/theme is to map the protocol output to an assumed semantic layer (ie red means bad, green means good, other colors are highlights). Then, themes/config target the semantic layers rather than the ANSI stuff. I figure as long as it works for 95% of the toolchain, I won't have to reinvent the world.
b
An old one but take a look at https://domterm.org/ If you dont care for escape sequences/interative TUIs, just a command->rich response REPL, consider Jupyter, or similar notebooks.
Or DIY on top of CodeMirror (text + syntax hightlight/completions + can embed arbitrary widgets) / ProseMirror (affords structured editing)...
The way autocomplete works in terminals is conceptually even grosser that pty stuff. It's a pile of shell scripts that do completely independent ad-hoc parsing of the commands. There is zero guarantee the flags they complete match the particulas executable you have. Some of these scripts do call the executable itself with special flags to help in the process, but that's by ad-hoc knowledge of particular command's facilities. there is NO standard protocol like "run me with --complete" nor any way to autodetect such support.
@Denny Vrandečić When you say "a shell", do you mean a shell-y experience e.g. some REPL with tab completion, or literally a unix shell with browser frontend? If latter, there is lots of activity now on oil-shell zulip
#shell-gui
channel around its headless mode and building web frontends around it (must join to read, worth it). https://oilshell.zulipchat.com/#narrow/stream/266977-shell-gui
d
I did mean a REPL with tab completion, history etc, not a Unix shell. I think a bit of do it yourself is what my use case is calling for.
k
Do you know what language it's going to run?
d
Something I'm making up myself