调整终端和滚动问题的ncurses [英] Resize terminal and scrolling problem with ncurses
问题描述
我用C编程的ncurses库(这是第一次),我已经两个问题。我在用默认的终端(GNOME终端)的Ubuntu。
1)我需要调整终端。我用resizeter()和resize_term(),但他们失败了。
2)我用scrollok()函数,问题是,我失去了滚动的行(当我回来wscrl(),还有空行)。
的#include< ncurses.h>诠释主(){WINDOW *赢,* WIN2;INT I;
焦炭℃;initscr的();
CBREAK();
NOECHO();赢=为newwin(8,20,1,1);
箱(赢,0,0);
WIN2 =为newwin(6,18,2,2);
scrollok(win2,1);
wrefresh(赢);
wrefresh(赢);对于(I = 0; I&下; 15;我++){
C = wgetch(WIN2);
如果(C =='U'){
wscrl(WIN2,-1);
wrefresh(WIN2);
}
其他{
wprintw(WIN2,%C \\ n,C);
wrefresh(WIN2);
}
}公司的尼克戴尔文(胜利);
公司的尼克戴尔文(WIN2);
endwin();返回0;
}
-
您不能调整从ncurses的终端窗口。该功能你提到调整由诅咒涂在终端窗口的一部分。我们的想法是你赶上
SIGWINCH
信号和通话resizeterm
在处理程序,当用户调整窗口大小的从在应用程序之外的(使用鼠标,可能)。 -
这是预期的行为,但在ncurses的,并在标准的Unix / POSIX不良记录。 NetBSD的诅咒文档状态下,它明确:
如果的 N 的是正的,那么
stdscr上
滚动的。的 N 的线丢失
从stdscr上
的顶部和的 N 的空白
线插入在底部。如果
的 N 的为负,那么stdscr上
向下滚动。的 N 的空白行
插入stdscr上
的顶部和
的 N 的线从底部丢失。
块引用>所以你必须手动保存输入和滚动时重新打印。
I'm programming in C using ncurses libraries (it's the first time) and I've two problems. I'm on ubuntu with the default terminal (gnome terminal).
1) I need to resize the terminal. I used resizeter() and resize_term(), but they fail.
2) I use scrollok() function and the problem is that I lose scrolled lines (when I get back with wscrl(), there are blank lines).
#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;
}
You can't resize the terminal window from ncurses. The functions you mention resize the part of the terminal window that is painted on by curses. The idea is you catch the
SIGWINCH
signal and callresizeterm
in the handler when the user resizes the window from outside the application (using the mouse, probably).This is intended behavior, though poorly documented in ncurses and in the Unix standard/POSIX. NetBSD's curses docs state it explicitly:
If n is positive then
stdscr
is scrolled up. n lines are lost from the top ofstdscr
and n blank lines are inserted at the bottom. If n is negative thenstdscr
is scrolled down. n blank lines are inserted at the top ofstdscr
and n lines are lost from the bottom.So you'll have to manually save input and reprint it when scrolling.
这篇关于调整终端和滚动问题的ncurses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!