Ncurses和调整大小窗口 [英] Ncurses and Resizing window

查看:170
本文介绍了Ncurses和调整大小窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在窗口底部输入文本,然后在顶部打印.我做到了但是,当我调整窗口大小时,光标附着在窗口底部,当我键入文本时,符号不会在屏幕上回显.如何解决?

I tried to enter text at the bottom of window and print it on the top. I did this. But when I resize the window, cursor is attached to the bottom of the window and when I type the text, symbols do not echo on the screen. How fix it?

对不起,我的英语.

我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <signal.h>

WINDOW* txt_win;
WINDOW* msg_win;


void sig_winch(int in) {

    struct winsize size;
    ioctl(fileno(stdout), TIOCGWINSZ, (char*) &size);
    resizeterm(size.ws_row, size.ws_col);
    // wprintw(msg_win,"%i, %i", LINES, COLS);
    // wmove(msg_win, 0, 0);
    // wresize(msg_win, LINES - 4, COLS);
    wrefresh(msg_win);
    // mvcur(LINES - 3, 0, LINES - 3, 0);
    // setsyx(LINES - 3, 0);
    // wmove(txt_win, LINES - 3, 0);
    // wresize(txt_win, 3, COLS);
    wrefresh(txt_win);
    echo();

   }

int main() {

        int x = LINES - 1;
        int y = 0;

        if (!initscr())
        {
            fprintf(stderr, "Error initialising ncurses.\n");
            exit(1);
        }

        signal(SIGWINCH, sig_winch);

        initscr();
        curs_set(1);
        refresh();

        char str[256];
                    //   dy   dx         y         x
        msg_win = newwin(LINES - 4, COLS, 0, 0);
        txt_win = newwin(3, COLS,       LINES - 3, 0);
        keypad(txt_win, 1);

        int line = 0;
        while (1) {

            wrefresh(txt_win);
            curs_set(1);
            if (wgetnstr(txt_win, str, 256) == 0) {
                wclear(txt_win);
                curs_set(0);
                waddstr(msg_win, str);
                wrefresh(msg_win);
            }
        }


    getch();

    delwin(txt_win);
    delwin(msg_win);

    endwin();
}

推荐答案

有几个问题:

  • ncurses已处理SIGWINCH,如 resizeterm 手册页.
  • 如果您没有为SIGWINCH添加自己的处理程序,则可以(如果您首次调用keypad(stdscr,TRUE))检查KEY_RESIZE.
  • 您的信号处理程序中使用的功能不安全使用;该程序可能由于多种原因而失败.
  • ncurses already handles SIGWINCH, as noted in the resizeterm manual page.
  • if you did not add your own handler for SIGWINCH, you could (if you first called keypad(stdscr,TRUE)) check for KEY_RESIZE.
  • the functions used in your signal handler are not safe to use; the program could fail for a number of reasons.

KEY_RESIZE ncurses-调整毛刺大小中进行了讨论 .

这篇关于Ncurses和调整大小窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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