0

what I am trying to do and the problem

I am trying to use nonblocking ncurses getch() and output data to stdout. The problem is that cnurses also writes to stdout. It writes [?1l>[?1h=[17;1H[?1049l[23;0;0t tens of thousands of times.

What I have tried

I tried the answer from this similar question, however I need to use the nodelay-function which only allows WINDOWs but not SCREENs.

I tried to temporarely disable stdout with two solutions from here, however it had no effect

source code

#include <ncurses.h>
#include <iostream>
using namespace std;
int get_input(void)
{
    WINDOW *w = initscr();
    raw();
    nodelay(w, TRUE);
    keypad(stdscr, TRUE);
    cbreak();
    noecho();
    int input = getch();
    endwin();
    return input;
}
int main(){
    while(true){
        int input = get_input();
        if(input != -1){
            cout<<input;
            exit(0);
        }
    }
}

compile on linux with g++ -lncurses file.cpp

onflante
  • 80
  • 5
  • 2
    Usually with ncurses, you init the ncurses system once, you use ncurses throughout your program for both input and output, and when done you end ncurses and end your program. This code has the init-use-end in a loop. – Eljay Feb 21 '21 at 12:59
  • Does this answer your question? [Ncurses and Linux pipeline](https://stackoverflow.com/questions/8371877/ncurses-and-linux-pipeline) – Thomas Dickey Feb 21 '21 at 17:03

0 Answers0