使用curses库时使用move()或wmove()时光标不会移动
我有一个程序,它将文本文件的前 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);
I have this program which prints the first 5 lines or more of a text file to a curses window and then prints some personalized input. but after printing the lines from the text file, the cursor wont' move when using move or wmove. I printed a word after using both and refresh() but it is printed in the last position the cursor was in. I tried mvprintw and mvwprintw but that way I got no output at all.
this is a part of the code
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您正在尝试在窗口范围之外打印。
特别是,我猜测这里:
...
num_rows_res
是results_scrn
窗口中的行数 - 但这意味着有效的行坐标范围为0
到num_rows_res - 1
。如果您尝试在窗口外使用
move()
或wmove()
,光标实际上不会移动;后续的printw()
或wprintw()
将在上一个光标位置打印。如果您尝试mvprintw()
或mvwprintw()
,整个调用将在尝试移动光标时失败,因此不会打印任何内容全部。这是一个完整的演示(仅打印到具有
LINES
行和COLS
列的stdscr
):(事实上,函数确实返回结果;如果你检查一下,你会发现失败的情况下是
ERR
。)I suspect that you are trying to print outside the bounds of the window.
In particular, I would guess that here:
...
num_rows_res
is the number of rows in theresults_scrn
window - but that means that the valid row coordinates range from0
tonum_rows_res - 1
.If you try to
move()
orwmove()
outside the window, the cursor will not actually move; a subsequentprintw()
orwprintw()
will print at the previous cursor position. If you try tomvprintw()
ormvwprintw()
, the whole call will fail at the point of trying to move the cursor, and so it won't print anything at all.Here's a complete demonstration (just printing to
stdscr
which hasLINES
rows andCOLS
columns):(In fact the functions do return a result; if you check it, you'll find that it's
ERR
in the cases that fail.)