AlgoRythm
AlgoRythm

Reputation: 1389

Execute bash commands in a curses window

This question is certain to exist, but I cannot find it anywhere...

I have a (n)curses window which I would like to dedicate to a bash shell (window 2) while concurrently displaying items in Window 1:

+-------------------------------+
|                 |             |
|                 |             |
|    WINDOW 1     |  WINDOW 2   |
|                 |             |
|                 |             |
+-----------------+-------------+

How would I perform this? I need it to accept input and display output as if I had just opened another terminal - and if possible - host is own curses sessions (such as if the dialog command is called)

I am using c.

Upvotes: 1

Views: 1810

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54515

tmux and screen can subdivide the terminal window into panes, which would let you do what you're asking about. Both use low-level features (terminfo or termcap) of ncurses. Doing it yourself at a high level would not be a short project, since you would have to manage the pseudo terminal connection to make bash run, etc.

bash expects to run in a terminal (a "tty", if you prefer), and if you wrap an application around it, making it run in a window, you have to provide connections for its input/output/error, making those act like a terminal. That is what a pseudo-terminal is: a collection of system calls which let a program setup, configure, operate and close connections to a process (such as bash) which need to act like a terminal.

Programs that use pseudo-terminals include (no surprise) terminal emulators, special applications such as screen, luit (e.g., the sys.c file).

Here are a few links to further reading:

Upvotes: 3

Related Questions