4

I would like a solution that allows me to detach a ncurses app to a different terminal emulator window and view the output of standard commands like 'cout' in the current one - for debugging and such.

I've seen a lot of solutions that write to a file and use tail but that seems quite hacky and slow. BTW. I have no idea where to even begin, I'm quite new with ncurses.

niraami
  • 646
  • 8
  • 18
  • Do you want the detaching (and other debug logic) inside the app, or do you want to make a standard ncurses app and have an external solution for detaching and such? – Fabel Feb 23 '17 at 02:26

3 Answers3

1

You can initialize curses in one of two ways:

  • using initscr (which uses the standard input/output), or

  • using newterm (which lets you specify which input/output to use)

For example, the ncurses test-program ditto uses newterm to open output displays on one or more xterm's. Here is a screenshot:

ditto with 3 clients

In principle, you could use the current terminal for input, and display ncurses output on another terminal (though offhand, I don't recall any useful programs which do this — only demos).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

First of all, ncurses uses standard out for it's output so simply using 'cout' will mix up the output. Typically you will want to use standard error ('cerr') instead for debugging and such.

If you don't want to use a simple file and tail (which isn't slow unless your your application is extreme in some way) you can use a named pipe like this:

mkfifo debug-pipe

Then run your application in a new terminal (for example xterm) and redirect error output to the named pipe.

xterm -e "my-application 2> debug-pipe" &

And lastly dump the named pipe in the first terminal (or any terminal).

cat debug-pipe

(By the way, I think I understand what kind of solution you first imagined. If the second terminal emulator could just redirect the standard error to it's own standard error it would simply appear in the first terminal. It would be easy for a terminal emulator to do this, but as far as I know none has that option.)

Fabel
  • 1,711
  • 14
  • 36
  • Can someone please explain why this answer was not useful so I can try to improve it? – Fabel Feb 23 '17 at 02:32
  • With this method, I don't get the normal ncurses output (i.e. the terminal just stays blank). It is working, though, when I just pipe into a normal file. – luator Nov 05 '18 at 11:01
  • @luator It sounds like you redirected stdout instead of stderr (">" instead of "2>"). This method should not affect stdout and thus not the output from ncurses. – Fabel Nov 07 '18 at 01:49
  • I was definitely using `2>`. However, I tried it again today, and now it worked. Maybe it was some other, unrelated issue. – luator Nov 07 '18 at 11:09
-1

Detaching and re-attaching any console session can be achieved using screen or tmux apps.

ezaquarii
  • 1,914
  • 13
  • 15
  • Thanks for the help, but I need some more hints considering both of these have a pretty (horrifyingly) extensive man page, and I've found no info as to how to use them in this way on google - I'm probably searching for the wrong keywords. When the manuals get to thousands of lines RDFM is just not enough xD – niraami Jan 03 '17 at 21:26
  • 1
    Using screen or tmux you can just move the whole session so to say. There is no way to use them to separate the output and "view the output of standard commands like 'cout' in the current one", I don't think. – Fabel Feb 23 '17 at 02:36