c - 使用 ncurses 调整终端大小和滚动问题

标签 c linux ncurses

我正在使用 ncurses 库在 C 中编程(这是第一次),我有两个问题。我在 ubuntu 上使用默认终端(gnome 终端)。

1) 我需要调整终端的大小。我使用了 resizeter() 和 resize_term(),但它们失败了。

2) 我使用 scrollok() 函数,问题是我丢失了滚动行(当我返回 wscrl() 时,有空行)。

#include <ncurses.h>

int main() {

WINDOW *win, *win2;

int i;
char c;

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

win=newwin(8,20,1,1);
box(win,0,0);
win2=newwin(6,18,2,2);
scrollok(win2,1);
wrefresh(win);
wrefresh(win);

for(i=0;i<15;i++){
    c=wgetch(win2);
    if(c=='u'){
        wscrl(win2,-1);
        wrefresh(win2);
    }
    else{
        wprintw(win2,"%c\n",c);
        wrefresh(win2);
    }
}

delwin(win);
delwin(win2);
endwin();

return 0;
}

最佳答案

  1. 您无法通过 ncurses 调整终端窗口的大小。您提到的功能调整了由 curses 绘制的终端窗口部分的大小。这个想法是当用户从应用程序外部(使用鼠标,可能)。

  2. 这是预期的行为,尽管在 ncurses 和 Unix 标准/POSIX 中的记录很少。 NetBSD's curses docs明确声明:

    If n is positive then stdscr is scrolled up. n lines are lost from the top of stdscr and n blank lines are inserted at the bottom. If n is negative then stdscr is scrolled down. n blank lines are inserted at the top of stdscr and n lines are lost from the bottom.

    因此您必须手动保存输入并在滚动时重新打印。

关于c - 使用 ncurses 调整终端大小和滚动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57318155/

相关文章:

linux - 删除 dos 行尾并再次加入行备份的最佳工具

perl - NCurses 和 Perl,任何指南?

c - 写入标准输入,然后将流移回 1 个位置

python - 如何防止curses应用程序出现故障?

将文件中的一组字符转换为 int

java - 启动器不可执行

linux - 设置 Linux 树命令的默认级别选项

c - 我的 unix-epoch 时间转换器的问题

在 c 中给出意外输出的代码

c - 如何在不在回调函数中使用 pcap_breakloop() 的情况下从 pcap_loop() 或 pcap_dispatch() 返回