-
Notifications
You must be signed in to change notification settings - Fork 7
/
keybind.go
59 lines (54 loc) · 1.54 KB
/
keybind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package blivechat
import (
"blivechat/util"
"fmt"
"github.com/awesome-gocui/gocui"
"log"
)
func setKeyBindings() {
setMainKeyBindings()
setConfigKeyBindings()
setSendKeyBindings()
}
func setMainKeyBindings() {
if err := MainGui.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := MainGui.SetKeybinding("", gocui.KeyTab, gocui.ModNone, func(gui *gocui.Gui, view *gocui.View) error {
_, err := gui.SetCurrentView(ViewRoom)
return err
}); err != nil {
log.Panicln(err)
}
}
func setConfigKeyBindings() {
if err := MainGui.SetKeybinding(ViewConfig, gocui.KeyEnter, gocui.ModNone, func(gui *gocui.Gui, view *gocui.View) error {
util.SetCurrentViewOnTop(gui, ViewConfigVisualColorMode)
return nil
}); err != nil {
return
}
}
func setSendKeyBindings() {
if err := MainGui.SetKeybinding(ViewSend, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
msg := v.Buffer()
if len(msg) == 0 {
return nil
}
v.Clear()
util.ViewPrintWithTime(MainGui, ViewDebug, fmt.Sprintf("try send msg: %s", msg))
if Client.Account.UID == 0 {
util.ViewPrintWithTime(MainGui, ViewDebug, "Send Msg fail, not login")
return v.SetCursor(0, 0)
}
resp, err := sendDanmuMsg(msg)
if err != nil {
util.ViewPrintWithTime(MainGui, ViewDebug, fmt.Sprintf("Send Msg fail, %s", err))
return v.SetCursor(0, 0)
}
util.ViewPrintWithTime(MainGui, ViewDebug, fmt.Sprintf("send result - code:%d msg:%s", resp.Code, resp.Message))
return v.SetCursor(0, 0)
}); err != nil {
return
}
}