Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEY_RESIZE not fired #32

Closed
koojunho opened this issue Jan 16, 2016 · 4 comments
Closed

KEY_RESIZE not fired #32

koojunho opened this issue Jan 16, 2016 · 4 comments
Assignees

Comments

@koojunho
Copy link

This go code doesn't receive KEY_RESIZE, when I resize the terminal window.

package main

import (
    gc "github.com/rthornton128/goncurses"
)

func main() {
    stdscr, _ := gc.Init()
    defer gc.End()

    gc.Echo(false)

    for {
        y, x := stdscr.MaxYX()
        stdscr.Printf("x=%d, y=%d\n", x, y)

        ch := stdscr.GetChar()
        switch ch {
        case gc.KEY_RESIZE:
            stdscr.Println("KEY_RESIZE")
        case 'q':
            return
        }
    }
}

Here is the other version that can get KEY_RESIZE which is written in C.

#include <curses.h>
#include <string.h>

int main()
{
    WINDOW *win = initscr();
    int key;
    while (1) {
        key = wgetch(win);
        if (key == 27) {
            break;
        } else if (key == KEY_RESIZE) {
            clear();
            mvprintw(0, 0, "COLS = %d, LINES = %d", COLS, LINES);
            for (int i = 0; i < COLS; i++)
                mvaddch(1, i, '*');
            refresh();
        }
    }

    endwin();
    return 0;
}
@rthornton128
Copy link
Owner

I've tried to get to the bottom of this one but it appears that it may be a cgo bug.

@rthornton128
Copy link
Owner

After further research this is a result of golang signal handling. Go takes control of all signals so the underlying C code never sees the signal.

An initial work around is to use signal.Notify() for SIGWINCH. You can then manually do resizing.

Be forewarned that ncurses will not play nice with go routines so take extra care.

@rthornton128 rthornton128 self-assigned this Apr 26, 2016
@rthornton128
Copy link
Owner

Looks like I was correct in that using signal.Notify will trap the signal as in C. See issue #34 for the solution.

@koojunho
Copy link
Author

Thank you !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants