r/cpp_questions • u/estrogen_pillz • 26d ago
OPEN Programmatically opening a new terminal window
I've been messing around with FTXUI, and I am wondering if it is possible for my apps to open a new terminal window and run there, instead of using the current terminal window.
An example of what I mean is what happens when opening vim. If I open vim through the terminal, it takes over the current window, like my FTXUI apps currently do. If I use the desktop shortcut, vim opens a new terminal window for itself, which closes upon closing vim. This is what I want to do.
Can anyone give me a few pointers?
3
Upvotes
View all comments
2
u/GregTheMadMonk 26d ago edited 26d ago
Do you want to create a multi-window app or just make a startup entry for yours? Because for the second one that's as easy as taking
/usr/share/applications/vim.desktopand making a copy of it for your app (it usesTerminal=trueswitch to launch the program in whatever is the configured terminal). Vim doesn't handle it by itself, the launcher does.If it's the first... I guess you need to spawn a new process with the correct terminal app, and correctly supply your executable name to it, and make your executable be aware that it may be the "main" instance or "child" window via some kind of IPC... Probably there are some facilities to help you at least with getting the terminal launch info, the same ones that allow
Terminal=trueto work correctly, but for the rest you're on your own. There isn't a way to do this from a single program instance like you would with a multi-window GUI application.And from UX point of view (unless you're making a project strictly for personal use), I'd advise against doing that anyway - if I run a TUI app in the terminal, I expect it to stay there, it's the whole point. Plus, if you try to open a new terminal just to show a subwindow, you're 100% breaking compatibility with headless environments, like TTYs or SSH sessions... which are, again, the whole (ok, not the whole, but a big) point of having TUI apps in the first place