调整终端和滚动问题的ncurses [英] Resize terminal and scrolling problem with ncurses

查看:151
本文介绍了调整终端和滚动问题的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;
}


解决方案

  1. 您不能调整从ncurses的终端窗口。该功能你提到调整由诅咒涂在终端窗口的一部分。我们的想法是你赶上 SIGWINCH 信号和通话 resizeterm 在处理程序,当用户调整窗口大小的从在应用程序之外的(使用鼠标,可能)。


  2. 这是预期的行为,但在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;
}

解决方案

  1. 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 call resizeterm in the handler when the user resizes the window from outside the application (using the mouse, probably).

  2. 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 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.

    So you'll have to manually save input and reprint it when scrolling.

这篇关于调整终端和滚动问题的ncurses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆