Changed some events to use angle brackets

This commit is contained in:
Caleb Bassi 2018-03-06 16:44:33 -08:00
parent 35e79f132b
commit 481a4dd1a1
3 changed files with 41 additions and 20 deletions

View File

@ -90,7 +90,7 @@ func setupGrid() {
func keyBinds() {
// quits
ui.On("q", "C-c", func(e ui.Event) {
ui.On("q", "<C-c>", func(e ui.Event) {
ui.StopLoop()
})
@ -166,7 +166,7 @@ func main() {
// load help widget after init termui/termbox so that it has access to terminal size
help = w.NewHelpMenu()
ui.On("resize", func(e ui.Event) {
ui.On("<resize>", func(e ui.Event) {
ui.Body.Width, ui.Body.Height = e.Width, e.Height
ui.Body.Resize()

View File

@ -6,6 +6,23 @@ import (
tb "github.com/nsf/termbox-go"
)
/*
here's the list of events which you can assign handlers too using the `On` function:
mouse events:
<MouseLeft> <MouseRight> <MouseMiddle>
<MouseWheelUp> <MouseWheelDown>
keyboard events:
any uppercase or lowercase letter or a set of two letters like j or jj or J or JJ
<C-d> etc
<M-d> etc
<up> <down> <left> <right>
<insert> <delete> <home> <end> <previous> <next>
<backspace> <tab> <enter> <escape> <space>
<C-<space>> etc
terminal events:
<resize>
*/
var eventStream = EventStream{
make(map[string]func(Event)),
"",
@ -104,7 +121,7 @@ func convertTermboxKeyValue(e tb.Event) string {
mod := ""
if e.Mod == tb.ModAlt {
mod = "M-"
mod = "<M-"
}
if e.Ch == 0 {
if e.Key > 0xFFFF-12 {
@ -115,7 +132,7 @@ func convertTermboxKeyValue(e tb.Event) string {
}
if e.Key <= 0x7F {
pre = "C-"
pre = "<C-"
k = string('a' - 1 + int(e.Key))
kmap := map[tb.Key][2]string{
tb.KeyCtrlSpace: {"C-", "<space>"},
@ -135,23 +152,27 @@ func convertTermboxKeyValue(e tb.Event) string {
}
}
if pre != "" {
k += ">"
}
return pre + mod + k
}
func convertTermboxMouseValue(e tb.Event) string {
switch e.Key {
case tb.MouseLeft:
return "MouseLeft"
return "<MouseLeft>"
case tb.MouseMiddle:
return "MouseMiddle"
return "<MouseMiddle>"
case tb.MouseRight:
return "MouseRight"
return "<MouseRight>"
case tb.MouseWheelUp:
return "MouseWheelUp"
return "<MouseWheelUp>"
case tb.MouseWheelDown:
return "MouseWheelDown"
return "<MouseWheelDown>"
case tb.MouseRelease:
return "MouseRelease"
return "<MouseRelease>"
}
return ""
}
@ -173,7 +194,7 @@ func convertTermboxEvent(e tb.Event) Event {
}
case tb.EventResize:
ne = Event{
Key: "resize",
Key: "<resize>",
Width: e.Width,
Height: e.Height,
}

View File

@ -156,16 +156,16 @@ func (p *Proc) ColResize() {
}
func (p *Proc) keyBinds() {
ui.On("MouseLeft", func(e ui.Event) {
ui.On("<MouseLeft>", func(e ui.Event) {
p.Click(e.MouseX, e.MouseY)
p.KeyPressed <- true
})
ui.On("MouseWheelUp", "MouseWheelDown", func(e ui.Event) {
ui.On("<MouseWheelUp>", "<MouseWheelDown>", func(e ui.Event) {
switch e.Key {
case "MouseWheelDown":
case "<MouseWheelDown>":
p.Down()
case "MouseWheelUp":
case "<MouseWheelUp>":
p.Up()
}
p.KeyPressed <- true
@ -181,7 +181,7 @@ func (p *Proc) keyBinds() {
p.KeyPressed <- true
})
viKeys := []string{"j", "k", "gg", "G", "C-d", "C-u", "C-f", "C-b"}
viKeys := []string{"j", "k", "gg", "G", "<C-d>", "<C-u>", "<C-f>", "<C-b>"}
ui.On(viKeys, func(e ui.Event) {
switch e.Key {
case "j":
@ -192,13 +192,13 @@ func (p *Proc) keyBinds() {
p.Top()
case "G":
p.Bottom()
case "C-d":
case "<C-d>":
p.HalfPageDown()
case "C-u":
case "<C-u>":
p.HalfPageUp()
case "C-f":
case "<C-f>":
p.PageDown()
case "C-b":
case "<C-b>":
p.PageUp()
}
p.KeyPressed <- true