c++ - 使用 curses 库时使用 move() 或 wmove() 时光标不会移动

标签 c++ unix cursor curses

我有这个程序可以将文本文件的前 5 行或更多行打印到 curses 窗口,然后打印一些个性化输入。但是在打印文本文件中的行后,使用 move 或 wmove 时光标不会移动。我在同时使用和 refresh() 后打印了一个词,但它打印在光标所在的最后位置。我尝试了 mvprintw 和 mvwprintw,但那样我根本没有输出。 这是代码的一部分

while (! feof(results_file))
    {
        fgets(line,2048,results_file);
        printw("%s",line);
    }
fclose(results_file);
mvwprintw(results_scrn,num_rows_res,(num_col_res/2) - 2,"Close");
wrefresh(results_scrn);

最佳答案

我怀疑您正试图在窗口边界之外打印。

特别是,我猜这里:

mvwprintw(results_scrn,num_rows_res,(num_col_res/2) - 2,"Close");

...num_rows_resresults_scrn 窗口中的行数 - 但这意味着有效的行坐标范围从 0num_rows_res - 1

如果您尝试在窗口外move()wmove(),光标实际上不会移动;随后的 printw()wprintw() 将在前一个光标位置打印。如果您尝试 mvprintw()mvwprintw(),整个调用将在尝试移动光标时失败,因此它不会打印任何内容全部。

这是一个完整的演示(只是打印到 stdscr,它有 LINES 行和 COLS 列):

#include <stdio.h>
#include <curses.h>

int main(void)
{
    int ch;

    initscr();
    noecho();
    cbreak();

    /* This succeeds: */
    mvprintw(1, 1, ">>>");

    /* This tries to move outside the window, and fails before printing: */
    mvprintw(LINES, COLS / 2, "doesn't print at all");

    /* This tries to move outside the window, and fails: */
    move(LINES, COLS / 2);

    /* This prints at the cursor (which hasn't successfully moved yet): */
    printw("prints at current cursor");

    /* This is inside the window, and works: */
    mvprintw(LINES - 1, COLS / 2, "prints at bottom of screen");

    refresh();
    ch = getch();
    endwin();
    return 0;
}

(事实上,这些函数确实会返回一个结果;如果您检查它,您会发现在失败的情况下它是ERR。)

关于c++ - 使用 curses 库时使用 move() 或 wmove() 时光标不会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7661491/

相关文章:

c++ - 向链表的末尾添加值并从前面删除 C++

c++ - R Makevars 文件没有正确覆盖 g++

linux - UNIX/Linux 中的 keepalive 超时

android - 如何对合并光标进行排序?

html - 删除 tumblr 上的自定义光标

c++ - Win32 API 按钮看起来很新,但它使用旧字体

基于宏函数参数的 C++ 宏函数扩展

linux - 在Mac上执行bash和sh文件而不写扩展名

sockets - socketpair api接口(interface)的典故是什么?

mysql 行比较游标与连接