I'm busy creating an interactive 'tty' TUI program, and I'd now like to open another 'tty' program like less with it's interactive screen. If I try this normally, when starting a process a bunch of different things will happen including: just freezing, program will error with something like 'stdin is not a terminal' or instead (like less) will return text to stdout without opening an interactive 'screen'.

Is this possible? I mean I can control-z, to send my initial program to the background, and then open less - but how could I do this programmatically? Or instead run the program directly?

An example of what I'd like to achieve, is being able to open an interactive less instance from 'within' vim? Perhaps one way to describe this is a child vty process.

I've come across forkpty, however it seems quite low level (a Linux sycall?) and not something I can interact with easily (from say a bash script).

One potential solution is using something like tmux, but if there is something simpler than that would be ideal. I mean if tmux is able to have this functionality, then it should be surely possible - I'm just not sure how it achieves that functionality.

  • 1
    You can create a new tty pair (one "front end", one "back end"). Usually you copy your new back to the original front e.v. handling your own "escapes", and suspension. And if it break/exit, you send a C-C to the old-front. The "complex" way (like tmux) Not much complex but more abstract. It is just copy bytes. -- Or just open normally. just save the screen status and save the screen status), like programs that have a screen interface (e.g. debian installation) but restore normal behaviour (and old screen content) when you exit. Sep 6, 2022 at 15:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.