搞过 necurses 前辈请教一个问题: 在清除 window 的 border 时,左上角总会残留是什么情况

2016-11-29 22:12:04 +08:00
 laobaozi

在按下方向右键时,光标会先向右移动一位,

x----0        x----o          xx----o      xxxx----o
|    |   ->    |    |   ->	   |    |  ->     |    |
x----o         x----o          X----o         x----o

需要再次按下方向右键才会右移,但是左上角的字符会清理不掉,但是别的方向键没有这个现象,问题出在哪里呢 代码很简单:

#include <ncurses.h>
#include <locale.h>

WINDOW *create_new_window(int height, int width, int start_y, int start_x);
void destroy_window(WINDOW *win);

int main(int argc, char *argv[])
{
    WINDOW *my_win;

    int start_x, start_y, width, height;
    int ch;

    setlocale(LC_ALL, "");
    initscr();
    raw();
    keypad(stdscr, TRUE);
    height = 4;
    width = 8;
    start_y = (LINES - height) / 2;
    start_x = (COLS - width) / 2 + 1;
    printw("按下 F1 退出");
    refresh();

    my_win = create_new_window(height, width, start_y, start_x);
    while((ch = getch()) != KEY_F(1))
    {

        switch (ch)
        {
            case KEY_UP:
                destroy_window(my_win);
                my_win = create_new_window(height, width, --start_y, start_x);
                break;
            case KEY_RIGHT:
                destroy_window(my_win);
                my_win = create_new_window(height, width, start_y, ++start_x);
                break;
            case KEY_DOWN:
                destroy_window(my_win);
                my_win = create_new_window(height, width, ++start_y, start_x);
                break;
            case KEY_LEFT:
                destroy_window(my_win);
                my_win = create_new_window(height, width, start_y, --start_x);
                break;
        }
    }

    endwin();
    return 0;

}

WINDOW *create_new_window(int height, int width, int start_y, int start_x)
{
    WINDOW *window;
    window = newwin(height, width, start_y, start_x);

    wborder(window, '|', '|', '-', '-', 'x', 'o', 'x', 'o');

    wrefresh(window);
    return window;
}


void destroy_window(WINDOW *window)
{
    wborder(window, 1, 1, 1, 1, 1, 1, 1, 1);
    wrefresh(window);
    delwin(window);
}
1738 次点击
所在节点    C
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/324210

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX