Merge branch 'stdin'
This commit is contained in:
commit
606db0f50e
@ -3,67 +3,73 @@ package handlers
|
||||
import (
|
||||
"github.com/gizak/termui"
|
||||
"github.com/nlopes/slack"
|
||||
termbox "github.com/nsf/termbox-go"
|
||||
|
||||
"github.com/erroneousboat/slack-term/src/context"
|
||||
"github.com/erroneousboat/slack-term/src/views"
|
||||
)
|
||||
|
||||
func RegisterEventHandlers(ctx *context.AppContext) {
|
||||
termui.Handle("/sys/kbd/", anyKeyHandler(ctx))
|
||||
termui.Handle("/sys/wnd/resize", resizeHandler(ctx))
|
||||
anyKeyHandler(ctx)
|
||||
incomingMessageHandler(ctx)
|
||||
termui.Handle("/sys/wnd/resize", resizeHandler(ctx))
|
||||
}
|
||||
|
||||
func anyKeyHandler(ctx *context.AppContext) func(termui.Event) {
|
||||
return func(e termui.Event) {
|
||||
key := e.Data.(termui.EvtKbd).KeyStr
|
||||
func anyKeyHandler(ctx *context.AppContext) {
|
||||
go func() {
|
||||
for {
|
||||
ev := termbox.PollEvent()
|
||||
|
||||
if ev.Type == termbox.EventKey {
|
||||
if ctx.Mode == context.CommandMode {
|
||||
switch key {
|
||||
case "q":
|
||||
switch ev.Key {
|
||||
case termbox.KeyPgup:
|
||||
actionScrollUpChat(ctx)
|
||||
case termbox.KeyCtrlB:
|
||||
actionScrollUpChat(ctx)
|
||||
case termbox.KeyCtrlU:
|
||||
actionScrollUpChat(ctx)
|
||||
case termbox.KeyPgdn:
|
||||
actionScrollDownChat(ctx)
|
||||
case termbox.KeyCtrlF:
|
||||
actionScrollDownChat(ctx)
|
||||
case termbox.KeyCtrlD:
|
||||
actionScrollDownChat(ctx)
|
||||
default:
|
||||
switch ev.Ch {
|
||||
case 'q':
|
||||
actionQuit()
|
||||
case "j":
|
||||
case 'j':
|
||||
actionMoveCursorDownChannels(ctx)
|
||||
case "k":
|
||||
case 'k':
|
||||
actionMoveCursorUpChannels(ctx)
|
||||
case "i":
|
||||
case 'i':
|
||||
actionInsertMode(ctx)
|
||||
case "<previous>":
|
||||
actionScrollUpChat(ctx)
|
||||
case "C-b":
|
||||
actionScrollUpChat(ctx)
|
||||
case "C-u":
|
||||
actionScrollUpChat(ctx)
|
||||
case "<next>":
|
||||
actionScrollDownChat(ctx)
|
||||
case "C-f":
|
||||
actionScrollDownChat(ctx)
|
||||
case "C-d":
|
||||
actionScrollDownChat(ctx)
|
||||
}
|
||||
}
|
||||
} else if ctx.Mode == context.InsertMode {
|
||||
switch key {
|
||||
case "<escape>":
|
||||
switch ev.Key {
|
||||
case termbox.KeyEsc:
|
||||
actionCommandMode(ctx)
|
||||
case "<enter>":
|
||||
case termbox.KeyEnter:
|
||||
actionSend(ctx)
|
||||
case "<space>":
|
||||
case termbox.KeySpace:
|
||||
actionInput(ctx.View, " ")
|
||||
case "<backspace>":
|
||||
case termbox.KeyBackspace, termbox.KeyBackspace2:
|
||||
actionBackSpace(ctx.View)
|
||||
case "C-8":
|
||||
actionBackSpace(ctx.View)
|
||||
case "<delete>":
|
||||
case termbox.KeyDelete:
|
||||
actionDelete(ctx.View)
|
||||
case "<right>":
|
||||
case termbox.KeyArrowRight:
|
||||
actionMoveCursorRight(ctx.View)
|
||||
case "<left>":
|
||||
case termbox.KeyArrowLeft:
|
||||
actionMoveCursorLeft(ctx.View)
|
||||
default:
|
||||
actionInput(ctx.View, key)
|
||||
actionInput(ctx.View, string(ev.Ch))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func resizeHandler(ctx *context.AppContext) func(termui.Event) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user