Hacker News new | ask | show | jobs
by regularfry 1962 days ago
Can you switch mode once the executable's already been launched, though? It's already got its tty, so you'd presumably need to start up the ncurses-capable terminal on demand, switch it in, and play back any meaningful prior output so it's in sync. The page is dead so I can't see how they handle it, but each of those steps is potentially problematic, isn't it?
1 comments

> Can you switch mode once the executable's already been launched, though?

Yes, apps can change terminal mode at any time. The solution the author went with is to have a list of "visual program" names, and when a visual program name is detected, launch it in an external terminal (xterm or Emacs vterm). That is making no attempt to handle mode switches during program execution, it is making a permanent decision before the program starts based on its name.

I think the solution here is to have a visual terminal "widget" that can be embedded into the graphical REPL, and the REPL constantly monitors the output and terminal mode of the subprocess, and when the REPL detects initiation of visual mode, start an embedded visual terminal widget, and then stop the visual terminal widget when it detects visual mode is completed.

On Linux, it is possible for the pty master to be immediately notified of any mode changes in the slave [0], using packet mode and EXTPROC. I don't think that facility exists in most other operating systems.

[0] https://stackoverflow.com/questions/21641754/when-pty-pseudo...

Thanks for the suggestion.

The "widget" you are talking about seems to required some specific support from the host REPL, no? Could SLY do it? Could graphical Emacs do it?

I agree it would need some specific support from the host REPL. There is a terminal emulator for Emacs, vterm, which I assume could provide that "terminal emulator widget" functionality. But you'd probably have to add code to SLY/SLIME/etc to support this. (To be honest I have never used SLY or SLIME, but as far as I know they don't have such a feature already.)

I think the other problem is that it is easy to launch a new buffer in Emacs hosting the terminal emulator. But what I was suggesting was more like embedding a buffer inside an existing one. I don't know if Emacs has that feature, but if it doesn't, again there is no reason why someone couldn't add it. (I don't know if Emacs Lisp is sufficient to implement such a feature or if extensions to the C code would be necessary.)