gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:03 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com