summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-03-06 16:44:33 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-03-06 16:44:33 -0800
commit481a4dd1a1d661904d3b1633e6cca2dc239350e5 (patch)
tree85d7e22755f3abc4173b284a3713b889ffab5820
parent35e79f132bc16e21c64a8c9bb2ffa02b0069c581 (diff)
Changed some events to use angle brackets
-rw-r--r--gotop.go4
-rw-r--r--termui/events.go39
-rw-r--r--widgets/proc.go18
3 files changed, 41 insertions, 20 deletions
diff --git a/gotop.go b/gotop.go
index 411fe03..046b9a6 100644
--- a/gotop.go
+++ b/gotop.go
@@ -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()
diff --git a/termui/events.go b/termui/events.go
index 8849101..3bc5459 100644
--- a/termui/events.go
+++ b/termui/events.go
@@ -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,
}
diff --git a/widgets/proc.go b/widgets/proc.go
index 95bdf41..b63a7c1 100644
--- a/widgets/proc.go
+++ b/widgets/proc.go
@@ -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