ncurses WINDOW* 在控制台调整大小后消失

ncurses WINDOW* disappears after console resize

所以,假设我们有一个

WINDOW *main_win=newwin(50, 80, 1, 0); // 50 rows, 80 columns
WINDOW *status_win=newwin(3, 100, 51, 0); // Status bar
WINDOW *interaction_bar=newwin(1, 200, 0, 0);

我有一个函数可以在上面打印字符串 (mvwaddstr),它按计划工作。但是在将终端的大小调整到特别 <50 列并将其调整回 >53 列之后,status_win 就神奇地消失了。 wclearwrefresh 不会在其上渲染任何内容。

我测试过类似的东西

delwin(main_win);
delwin(status_win);
delwin(interaciton_bar);
main_win=newwin(50, 80, 1, 0);
status_win=newwin(3, 100, 51, 0);
interaction_bar=newwin(1, 200, 0, 0);

令人惊讶的是,status_win 被渲染回来了。但是有一个问题。

我使用 int ch = wgetch(main_win); 获取键盘输入。它可以通过某种方式读取 'w'、'a'、's'、'd' 等键,但是当涉及到 KEY_LEFT 和 KEY_RIGHT 等键时,我的控制台刚开始抖动,似乎没有被处理。

关于消失 window(可能缩小到 1x1,这不是“神奇地消失”)。如 manual page:

When resizing windows, resize_term recursively adjusts subwindows, keeping them within the updated parent window's limits. If a top-level window happens to extend to the screen's limits, then on resizing the window, resize_term will keep the window extending to the corresponding limit, regardless of whether the screen has shrunk or grown.

关于“开始抖动”,如果您的 window 没有启用 keypad(如在给定的代码片段中),那么光标键将被视为一个字符序列,而不是比单个代码:

The keypad option enables the keypad of the user's terminal. If enabled (bf is TRUE), the user can press a function key (such as an arrow key) and wgetch(3x) returns a single value representing the function key, as in KEY_LEFT. If disabled (bf is FALSE), curses does not treat function keys specially and the program has to interpret the escape sequences itself. If the keypad in the terminal can be turned on (made to transmit) and off (made to work locally), turning on this option causes the terminal keypad to be turned on when wgetch(3x) is called. The default value for keypad is FALSE.