Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Strange -- Can't read redirected output when using ncurses! #148

Open
skylaner opened this issue Apr 10, 2018 · 1 comment
Open

Strange -- Can't read redirected output when using ncurses! #148

skylaner opened this issue Apr 10, 2018 · 1 comment

Comments

@skylaner
Copy link

Here is a little program I've written:

extern crate ncurses;

use std::io;
use std::io::prelude::*;
use std::process;

fn main() {
    let mut contents = String::new();
    match read_contents(&mut contents) {
        Ok(0) => {
            eprint!("No input!\n");
            process::exit(0);
        },

        Ok(result) => result,

        Err(e) => {
            eprint!("Can't read input: {}\n", e);
            process::exit(1);
        }
    };

    run(&contents);
}

fn read_contents(buf: &mut String) -> io::Result<usize> {
    let mut stdin = io::stdin();

    stdin.read_to_string(buf)
}

fn run(contents: &String) {
    ncurses::initscr();

    ncurses::printw(contents);
    ncurses::refresh();
    ncurses::getch();

    ncurses::endwin();
}

This works fine with keyboard input but when I redirect input from a file or pipe from another program, nothing is output!

If I remove printw and use println! everything works fine.

In short, these won't work:

$ pwd | ./main
$ ./main < main.rs
@jeaye
Copy link
Owner

jeaye commented Apr 19, 2018

Thanks for reporting this. I can't help much, unfortunately, since I haven't used Rust or ncurses in a couple of years. In general, I recommend writing the ncurses code in C to verify everything works there. Then port it to Rust (which is mostly 1:1, since ncurses-rs is so light) and it should remain the same. In cases where behavior changes, take a look at the ncurses wrapping of the C fn to see if there's something wrong. As mentioned, each fn wrapper is just a couple of lines, so it shouldn't be much to take in.

We'll certainly leave this open though, until it's resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants