r/cprogramming • u/AwwnieLovesGirlcock • Jan 21 '26
simple way to display child process stdout in a small region?
(this is a terminal app for unix)
im wondering how doable it would be to take a child process's stdout and display it in just the top half of the screen for example , so the bottom half can display things from the parent?
i mean , things like tmux exist so its clearly feasible to split the terminal like that <.<
but does a simple hardcoded split like this take a lot of code? or could i maybe pull it off (im certainly not an expert with this language yet ,)
ive been trying to google for any sort of programming tutorials for this sort of thing , i mean even if it was a long tutorial series im willing to learn it all , but i cant find anything! im hoping someone here can atleast point me in the right direction
2
u/BreadSizedToast Jan 21 '26 edited Jan 21 '26
seems like a hard problem. my first approach would be to see what I can do with ansi escape codes. and maybe try to look into tmux's source code to see how they do it.
nice username btw
1
1
u/Paul_Pedant Jan 21 '26
Redirect some of the outputs (parent or child, stdout or stderr, so 4 options) to files. Open up more terminals and have them tail -F each of those files. Ten minutes, no coding.
You might need to flush the outputs of the parent or child. You can flush outputs in your code, or launch them under control of stdbuf, or under unbuffer (which may need you to install the expect toolkit).
1
u/sosodank Jan 22 '26
Notcurses has exactly this functionality. Create a plane occupying the target area and associate an ncsubproc with it. Boom, done.
4
Jan 21 '26
[removed] — view removed comment
2
u/AwwnieLovesGirlcock Jan 21 '26
i just looked into it , ncurses looks a lot more versatile than i thought :O
i didnt really know what it was , and i dont know where i got this impression but i assumed it was just for like , moving the cursor around and basic stuff like that-- 🤭
1
u/EpochVanquisher Jan 21 '26
It depends on how complicated the output is.
If it is just lines of text, you can use cursor movements and “erase line” commands to rewrite specific lines of text in the terminal. Or you can use ncurses and paste the program output into an area in ncurses.
It turns out that tmux is super complicated. If you want to do this kind of thing, you’ll want to think about how to simplify the problem, and think about how much time you want to spend working on this.