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

I have met weird problems between C and Go about ncurses.

The problems are below

  • Same code implemented C and Go, works differently. Go code doesn't work intended.
    • getmaxyx() (getmaxy and getmaxx) on Go always returns initial size even after terminal size has been changed.
    • getch() function doesn't return keycode when terminal size is changed.

My C codes for ncurses are below.

#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); // 안해도 갱신 되네?
}

My go codes for ncurses are below.

package main

// #include <stdlib.h>
// #include <locale.h>
// #include <ncursesw/curses.h>
// #cgo LDFLAGS: -lncursesw
import "C"

import "unsafe"
import "fmt"

func main() {
    // C Code : setlocale(LC_ALL, "");
    {
        _s := C.CString("")
        defer C.free(unsafe.Pointer(_s))

        C.setlocale(C.LC_ALL, _s)
    }

    C.initscr()

    C.timeout(50)

    C.noecho()
    C.cbreak()
    C.curs_set(C.int(0))

    C.start_color()

    C.keypad(C.stdscr, C.bool(true))

    var count int = 0
    draw(count, 0)

    for {
        ch := int(C.getch())
        if ch < 0 {
            continue
        }

        count++
        draw(count, ch)
    }
}

func draw(count int, ch int) {
    // C Code : getmaxyx(stdscr, y, x)
    var y, x int
    {
        _y := C.getmaxy(C.stdscr)
        _x := C.getmaxx(C.stdscr)

        y = int(_y)
        x = int(_x)
    }

    var s string
    s = fmt.Sprintf("count=%5d y=%d x=%d ch=%d        ", count, y, x, ch)

    // C Code : mvwaddstr(stdscr, 1, 1, s);
    {
        _s := C.CString(s)
        defer C.free(unsafe.Pointer(_s))

        C.mvwaddstr(C.stdscr, C.int(1), C.int(1), _s)
    }
    C.wrefresh(C.stdscr)
}

The codes print some information when it starts, and re-print when key has been processed

And as I mentioned, only C prints updated size and prints when the terminal size is changed.