更改终端大小时,getmaxyx()返回相同的大小,getch()不返回键码

时间:2019-02-10 06:24:38

标签: go ncurses curses

我遇到了C和Go之间关于ncurses的奇怪问题。

问题在下面

  • 用C和Go实现的相同代码工作方式不同。 Go代码无法正常工作。
    • Go上的getmaxyx()(getmaxy和getmaxx)始终会返回初始大小,即使更改了终端大小也是如此。
    • 更改终端大小时,getch()函数不会返回键码。

我的ncurses C代码如下。

'soome.url/?something=1,2,3,1' => 'soome.url/?'

'soome.url/nothing?nothingtoo?something=1,2,3,1' => 'soome.url/nothing?nothingtoo?'

'soome.url/nothing?something=1,2,3,1' => 'soome.url/nothing?'

我的ncurses验证码如下。

#include <stdio.h>
#include <stdbool.h>

#include <locale.h>
#include <ncursesw/curses.h>

void draw(int count, int ch);

int main(void)
{
    setlocale(LC_ALL, "");

    initscr();

    timeout(50);

    noecho();
    cbreak();
    curs_set(0);

    start_color();

    keypad(stdscr, true);

    int count = 0;
    draw(count, 0);

    for (;;) {
        int ch = getch();
        if (ch < 0) {
            continue;
        }

        count++;
        draw(count, ch);
    }
}

void draw(int count, int ch)
{
    int y, x;
    getmaxyx(stdscr, y, x);

    char s[64];
    sprintf(s, "count=%5d y=%d x=%d ch=%d           ", count, y, x, ch);

    mvwaddstr(stdscr, 1, 1, s);
    wrefresh(stdscr); // 안해도 갱신 되네?
}

代码在启动时会打印一些信息, 并在密钥处理完毕后重新打印

正如我所提到的,只有C打印更新的大小,并在更改终端大小时打印。

0 个答案:

没有答案
相关问题