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

Handling the ESCape key #47

Closed
phf opened this issue Apr 16, 2016 · 5 comments
Closed

Handling the ESCape key #47

phf opened this issue Apr 16, 2016 · 5 comments

Comments

@phf
Copy link

phf commented Apr 16, 2016

At first I was confused why your demos all exit on CTRL-C instead of ESC. Then I noticed that any handler I install for KeyEsc will be ignored. I eventually traced this back to gocui hardcoding the termbox.InputAlt input mode in the MainLoop method in gui.go. If I hack the code to set termbox.InputEsc instead, I get the behavior I want. My first instinct is that this should be the application's choice, not gocui's. However, I may be missing something about what gocui needs in order to work. Any hints?

@jroimartin
Copy link
Owner

jroimartin commented Apr 23, 2016

Hi @phf,

On one hand, I hardcoded it to avoid adding "tricky" options to the gocui's API, making it simple for the users.

On the other hand, I chose inputMode := termbox.InputAlt because I think it's more "compatible". From the termbox-go documentation:

    1. Esc input mode. When ESC sequence is in the buffer and it doesn't
    match any known sequence. ESC means KeyEsc. This is the default input
    mode.

    2. Alt input mode. When ESC sequence is in the buffer and it doesn't
    match any known sequence. ESC enables ModAlt modifier for the next
    keyboard event.

I always remember having troubles, depending on the terminal emulator, to make the ALT/META key works. So, you ended up using 'ESC+' or mapping ALT/META to 'ESC+'. The same happens in OSX and, for instance, iTerm2 recommends:

image

So, for example, when you press "ALT+2", it will send ESC+2. To bind this combination in gocui, you can use:

if err := g.SetKeybinding("someView", '2', gocui.ModAlt, someFunc); err != nil {
                return err
}

Because it uses termbox.InputAlt by default. And, this is the rationale to take this decision.

@micronix
Copy link

I'm trying to create an editor interface similar to vim with a normal mode and an insert mode. It feels like it should be easy to do this, but when I bind j in ModAlt mode I have to press Esc every time. What am I missing?

    if err := g.SetKeybinding("main", 'j', gocui.ModAlt, cursorDown); err != nil {
        return err
    }

@jroimartin
Copy link
Owner

jroimartin commented May 12, 2016

@micronix please take a look at my previous comment. There you have the explanation and solution to that.

@jroimartin
Copy link
Owner

Closed due to inactivity.

@gbitten
Copy link
Contributor

gbitten commented Aug 28, 2016

The PR #56 makes the KeyESC binding work correctly.

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

No branches or pull requests

4 participants