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