From c3c07c97cfbbf71cb3ffc9ebd636203f28534f68 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Wed, 4 Nov 2020 01:32:48 +0000 Subject: [PATCH] chat view can backspace --- internal/app/chat_view.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/app/chat_view.go b/internal/app/chat_view.go index 5dd4159..d632395 100644 --- a/internal/app/chat_view.go +++ b/internal/app/chat_view.go @@ -19,6 +19,15 @@ func (c *chatView) handleEvent(ui *UI, e tcell.Event) bool { case *tcell.EventKey: key := t.Key() + if key == tcell.KeyBackspace || key == tcell.KeyBackspace2 { + line := []rune(c.composing) + if len(line) > 0 { + line = line[:len(line)-1] + } + c.composing = string(line) + break + } + if key == tcell.KeyRune { c.composing = fmt.Sprintf("%s%c", c.composing, t.Rune()) c.Info("composing: %v", c.composing) @@ -32,8 +41,10 @@ func (c *chatView) handleEvent(ui *UI, e tcell.Event) bool { func (c *chatView) draw(b *buffer) { b.writeString(c.composing, math.Vec{0, b.height - 1}, tcell.StyleDefault) + if c.inFocus { - b.set(len([]rune(c.composing)), b.height-1, tile{r: tcell.RuneBlock, style: tcell.StyleDefault.Blink(true).Foreground(tcell.NewRGBColor(255, 0, 0))}) + cursor := tile{r: tcell.RuneBlock, style: tcell.StyleDefault.Blink(true)} + b.set(len([]rune(c.composing)), b.height-1, cursor) } }