I am writing a ncurses based program and would like the ability to enter
curses mode, manipulate the screen, and return output through (a possibly
redirected) stdout even when my program’s output is being substituted into
the next commands arguments.

In other shell programs that I have tested my code in (sh, bash, zsh),
command substitution causes stdout to be disconnected from the user’s tty.
I can still accomplish my goals, in the shells mentioned previously, by
opening  /dev/tty for writing. The file descriptor obtained from this
operation is then used when I create a new screen.

In fish, however, the operation fails silently. My example code follows
below. If this code works then my application should run fine from fish.

#define _XOPEN_SOURCE#include <ncurses.h>#include <stdio.h>#include
<stdlib.h>#include <unistd.h>
int main(){
    SCREEN* s = NULL;
    FILE* out = stdout;
    if(!isatty(fileno(stdout))) {
        out = fopen("/dev/tty", "w");
        setbuf(out, NULL);
    }
    s = newterm(NULL, out, stdin);

    printw("test");
    getch();

    endwin();
    delscreen(s);
    puts("/home/matt");
    return 0;}

Consider this example:

echo $(./a.out) # bash, sh, zsh

In bash, zsh, and sh the following happens: curses mode is entered, the
screen is cleared, and the string “test” is printed. After the user presses
a key, the program exits curses mode and outputs “/home/matt” to stdout
which is subsequently printed to the console by echo.

The equivalent in fish:

echo (./a.out) # fish

Does nothing but print a newline to the console.

Any insight would be greatly appreciated! I really enjoy using fish and
would like to get this issue resolved so I can continue to use the shell.

Thank you,
Matthew Mellott

P.S. System information:
Linux osiris 3.8.0-25-generic #37-Ubuntu SMP Thu Jun 6 20:47:07 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux
fish, version 2.0.0
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to