mirror of
https://github.com/troglobit/libite.git
synced 2026-11-06 15:50:57 +00:00
initscr(): Use stdout, not stderr, just like other conio.h macros
A program's stderr may have been redirected by the operator. We want to query the size of stdout, even though it is buffered, so add fflush() to handle that. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
3691044007
commit
2534c398ea
1 file changed
+7
-5
@@ -103,11 +103,11 @@ static inline void initscr(int *row, int *col)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Disable echo to terminal while probing */
|
/* Disable echo to terminal while probing */
|
||||||
tcgetattr(STDERR_FILENO, &tc);
|
tcgetattr(STDOUT_FILENO, &tc);
|
||||||
saved = tc;
|
saved = tc;
|
||||||
tc.c_cflag |= (CLOCAL | CREAD);
|
tc.c_cflag |= (CLOCAL | CREAD);
|
||||||
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
tc.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||||
tcsetattr(STDERR_FILENO, TCSANOW, &tc);
|
tcsetattr(STDOUT_FILENO, TCSANOW, &tc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Save cursor pos+attr
|
* Save cursor pos+attr
|
||||||
@@ -115,7 +115,8 @@ static inline void initscr(int *row, int *col)
|
|||||||
* Set cursor at the far bottom,right pos
|
* Set cursor at the far bottom,right pos
|
||||||
* Query term for resulting pos
|
* Query term for resulting pos
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "\e7" "\e[r" "\e[999;999H" "\e[6n");
|
fprintf(stdout, "\e7" "\e[r" "\e[999;999H" "\e[6n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait here for terminal to echo back \e[row,lineR ...
|
* Wait here for terminal to echo back \e[row,lineR ...
|
||||||
@@ -128,10 +129,11 @@ static inline void initscr(int *row, int *col)
|
|||||||
/*
|
/*
|
||||||
* Restore above saved cursor pos+attr
|
* Restore above saved cursor pos+attr
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "\e8");
|
fprintf(stdout, "\e8");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
/* Restore terminal */
|
/* Restore terminal */
|
||||||
tcsetattr(STDERR_FILENO, TCSANOW, &saved);
|
tcsetattr(STDOUT_FILENO, TCSANOW, &saved);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in new issue
Block a user