gizak / termui

Golang terminal dashboard
MIT License
13.11k stars 786 forks source link

Handling input /sys/kbd/<backspace> does not work correctly on macOS #166

Closed ezekg closed 5 years ago

ezekg commented 6 years ago

Example program

package main

import (
    "fmt"

    ui "github.com/gizak/termui"
)

func main() {
    err := ui.Init()
    if err != nil {
        panic(err)
    }
    defer ui.Close()

    ui.Handle("/sys/kbd", func(e ui.Event) {
        fmt.Println("other", e.Data.(ui.EvtKbd))
    })

    ui.Handle("/sys/kbd/<enter>", func(e ui.Event) {
        fmt.Println("enter", e.Data.(ui.EvtKbd))
    })

    ui.Handle("/sys/kbd/<backspace>", func(e ui.Event) {
        fmt.Println("backspace", e.Data.(ui.EvtKbd))
    })

    ui.Handle("/sys/kbd/C-c", func(ui.Event) {
        ui.StopLoop()
    })

    ui.Loop()
}

Expected behavior

For /sys/kbd/<backspace> to listen for backspace events. Pressing a, b, c, backspace, enter on the keyboard should print the following:

other {a}
other {b}
other {c}
backspace {<backspace>}
enter {<enter>}

Actual behavior

Backspace emits a C-8 event instead of <backspace>. Pressing a, b, c, backspace, enter on the keyboard prints the following:

other {a}
other {b}
other {c}
other {C-8}
enter {<enter>}
TACIXAT commented 6 years ago

I get C-8 for backspace on Linux as well.

cjbassi commented 5 years ago

Should be fixed now with 7b48d56e0b4ad4aa2c69674c596ef528143cccda on master. Do note that termui has basically been rewritten up to that point so there's a lot of breaking changes.

Also, <C-8>, along with a bunch of other keys, are guaranteed not to work due to how termbox-go presents keyboard events. Basically, both <C-8> and <Backspace> are represented by the same identifier, so we have to pick which one to use unfortunately.