重绘整个屏幕的正确方法?
Correct way to repaint entire screen?
我不明白当用户按下 Ctrl-L 或 Ctrl-R 时使用什么函数来重绘屏幕。使用 clearok()
、redrawwin()
或 wrefresh()
和 curscr
作为参数有什么区别?来自 OpenBSD 手册页:
If clearok is called with TRUE as argument, the next call to wrefresh with this window will clear the screen completely and redraw the entire screen from scratch. This is useful when the contents of the screen are uncertain, or in some cases for a more pleasing visual effect. If the win argument to clearok is the global variable curscr, the next call to wrefresh with any window causes the screen to be cleared and repainted from scratch.
...
If the win argument to wrefresh is the global variable curscr, the screen is immediately cleared and repainted from scratch.
...
The wredrawln routine indicates to curses that some screen lines are corrupted and should be thrown away before anything is written over them. It touches the indicated lines (marking them changed). The routine redrawwin() touches the entire window.
"OpenBSD manpages" are ncurses。键绑定无关紧要。
您问了三个功能:
- clearok(),
- redrawwin(),或
- wrefresh() 以 curscr 作为参数?
但它们是不同的:
- 对于
clearok()
,您并不是在告诉 curses 您忘记了屏幕上显示的内容,而是说最好清除它(curses 会这样做),但是
redrawwin()
不是重绘整个屏幕,而是window。如果您的应用程序正在模仿面板库,使一些 windows 重叠并希望 "raise" 一个模糊的 window 在其他之上,则您的应用程序可能会这样做。最后,
- 刷新
curscr
明确告诉 curses 绕过 window 或 stdscr
上的正常打印顺序,然后将 stdscr
的更改应用到 newscr
,并应用 newscr
和 curscr
之间的差异 到curscr
。就 curses 而言,curscr
具有放在物理屏幕上的任何内容。所以当你修改curscr
时,curses会在要求刷新时立即更新物理屏幕。
就其价值而言,curscr
功能早于 ncurses,尽管我不得不指出 source-code to show that. It's mentioned in this changelog entry from 1995:
src/curses/resizwin.c
:
refresh curscr to force screen update in ncurses
通常,当按下 Ctrl+L 或 Ctrl+R 时发生的事情取决于您的 shell 或正在使用的程序,在这种情况下,程序将发送一系列字符,您的终端将在 (终端)将清除您的屏幕。
如何得到这个序列:
#include <curses.h>
#include <term.h>
#include <termios.h>
#include <sys/ioctl.h>
void init_term(void)
{
static struct termios term_new;
setupterm(NULL, 1, NULL);
ioctl(0, TCGETS, &term_new);
}
int main(void)
{
// init the ncurses
init_term();
// get the sequence for "clear" command then print it
printf("%s", tigetstr("clear"));
// and flush the buffer
fflush(stdout);
return (0);
}
我不明白当用户按下 Ctrl-L 或 Ctrl-R 时使用什么函数来重绘屏幕。使用 clearok()
、redrawwin()
或 wrefresh()
和 curscr
作为参数有什么区别?来自 OpenBSD 手册页:
If clearok is called with TRUE as argument, the next call to wrefresh with this window will clear the screen completely and redraw the entire screen from scratch. This is useful when the contents of the screen are uncertain, or in some cases for a more pleasing visual effect. If the win argument to clearok is the global variable curscr, the next call to wrefresh with any window causes the screen to be cleared and repainted from scratch.
...
If the win argument to wrefresh is the global variable curscr, the screen is immediately cleared and repainted from scratch.
...
The wredrawln routine indicates to curses that some screen lines are corrupted and should be thrown away before anything is written over them. It touches the indicated lines (marking them changed). The routine redrawwin() touches the entire window.
"OpenBSD manpages" are ncurses。键绑定无关紧要。
您问了三个功能:
- clearok(),
- redrawwin(),或
- wrefresh() 以 curscr 作为参数?
但它们是不同的:
- 对于
clearok()
,您并不是在告诉 curses 您忘记了屏幕上显示的内容,而是说最好清除它(curses 会这样做),但是 redrawwin()
不是重绘整个屏幕,而是window。如果您的应用程序正在模仿面板库,使一些 windows 重叠并希望 "raise" 一个模糊的 window 在其他之上,则您的应用程序可能会这样做。最后,- 刷新
curscr
明确告诉 curses 绕过 window 或stdscr
上的正常打印顺序,然后将stdscr
的更改应用到newscr
,并应用newscr
和curscr
之间的差异 到curscr
。就 curses 而言,curscr
具有放在物理屏幕上的任何内容。所以当你修改curscr
时,curses会在要求刷新时立即更新物理屏幕。
就其价值而言,curscr
功能早于 ncurses,尽管我不得不指出 source-code to show that. It's mentioned in this changelog entry from 1995:
src/curses/resizwin.c
: refresh curscr to force screen update in ncurses
通常,当按下 Ctrl+L 或 Ctrl+R 时发生的事情取决于您的 shell 或正在使用的程序,在这种情况下,程序将发送一系列字符,您的终端将在 (终端)将清除您的屏幕。
如何得到这个序列:
#include <curses.h>
#include <term.h>
#include <termios.h>
#include <sys/ioctl.h>
void init_term(void)
{
static struct termios term_new;
setupterm(NULL, 1, NULL);
ioctl(0, TCGETS, &term_new);
}
int main(void)
{
// init the ncurses
init_term();
// get the sequence for "clear" command then print it
printf("%s", tigetstr("clear"));
// and flush the buffer
fflush(stdout);
return (0);
}