Add support for ctrlW

This commit is contained in:
Tony Blyler 2018-06-12 16:59:50 -04:00
parent 66c8c81810
commit 938844c326

23
main.go
View file

@ -9,6 +9,7 @@ import (
"io" "io"
"net" "net"
"os" "os"
"unicode"
"github.com/jroimartin/gocui" "github.com/jroimartin/gocui"
"gitlab.com/tblyler/ep2pchat/client" "gitlab.com/tblyler/ep2pchat/client"
@ -128,7 +129,27 @@ func main() {
return nil return nil
}) })
gui.SetKeybinding("", gocui.KeyCtrlL, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { gui.SetKeybinding("input", gocui.KeyCtrlW, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
buffer := v.Buffer()
foundFirstSpace := false
foundFirstChar := false
for i := len(buffer) - 1; i >= 0; i-- {
if unicode.IsSpace(rune(buffer[i])) {
if foundFirstSpace && foundFirstChar {
break
}
foundFirstSpace = true
} else {
foundFirstChar = true
}
v.EditDelete(true)
}
return nil
})
gui.SetKeybinding("input", gocui.KeyCtrlL, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
chat, err := g.View("chat") chat, err := g.View("chat")
if err != nil { if err != nil {
return nil return nil