summary refs log tree commit diff stats
path: root/widgets/exline.go
diff options
context:
space:
mode:
authorMarkus Ongyerth <aerc@ongy.net>2018-06-01 09:58:00 +0200
committerDrew DeVault <sir@cmpwn.com>2018-06-01 16:04:43 -0700
commit80e891a8024ac10a60daa790131e04f0326b0c73 (patch)
tree7a07cc26b2885e43e57e1672d2895c7fae2b173e /widgets/exline.go
parent3836d240c9aa26615e7d768a57436d171edc3831 (diff)
downloadaerc-80e891a8024ac10a60daa790131e04f0326b0c73.tar.gz
switch to tcell from termbox
This is a simple mostly straight forward switch to tcell in favor of
termbox.
It uses the tcell native api (not the compat layer) but does not make
use of most features.

Further changes should include moving to tcell's views.TextArea and the
general built in widget behaviour instead of the current ad hoc
implementation.

Regression: Cursor isn't shown in ex-line
Diffstat (limited to 'widgets/exline.go')
-rw-r--r--widgets/exline.go49
1 files changed, 21 insertions, 28 deletions
diff --git a/widgets/exline.go b/widgets/exline.go
index 0522371..de652ba 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -2,7 +2,7 @@ package widgets
 
 import (
 	"github.com/mattn/go-runewidth"
-	tb "github.com/nsf/termbox-go"
+	"github.com/gdamore/tcell"
 
 	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
 )
@@ -40,15 +40,10 @@ func (ex *ExLine) Invalidate() {
 }
 
 func (ex *ExLine) Draw(ctx *ui.Context) {
-	cell := tb.Cell{
-		Fg: tb.ColorDefault,
-		Bg: tb.ColorDefault,
-		Ch: ' ',
-	}
-	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), cell)
-	ctx.Printf(0, 0, cell, ":%s", string(ex.command))
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+	ctx.Printf(0, 0, tcell.StyleDefault, ":%s", string(ex.command))
 	cells := runewidth.StringWidth(string(ex.command[:ex.index]))
-	tb.SetCursor(ctx.X()+cells+1, ctx.Y())
+	ctx.SetCursor(cells + 1, 0)
 }
 
 func (ex *ExLine) insert(ch rune) {
@@ -93,43 +88,41 @@ func (ex *ExLine) backspace() {
 	}
 }
 
-func (ex *ExLine) Event(event tb.Event) bool {
-	switch event.Type {
-	case tb.EventKey:
-		switch event.Key {
-		case tb.KeySpace:
-			ex.insert(' ')
-		case tb.KeyBackspace, tb.KeyBackspace2:
+func (ex *ExLine) Event(event tcell.Event) bool {
+	switch event := event.(type) {
+	case *tcell.EventKey:
+		switch event.Key() {
+		case tcell.KeyBackspace, tcell.KeyBackspace2:
 			ex.backspace()
-		case tb.KeyCtrlD, tb.KeyDelete:
+		case tcell.KeyCtrlD, tcell.KeyDelete:
 			ex.deleteChar()
-		case tb.KeyCtrlB, tb.KeyArrowLeft:
+		case tcell.KeyCtrlB, tcell.KeyLeft:
 			if ex.index > 0 {
 				ex.index--
 				ex.Invalidate()
 			}
-		case tb.KeyCtrlF, tb.KeyArrowRight:
+		case tcell.KeyCtrlF, tcell.KeyRight:
 			if ex.index < len(ex.command) {
 				ex.index++
 				ex.Invalidate()
 			}
-		case tb.KeyCtrlA, tb.KeyHome:
+		case tcell.KeyCtrlA, tcell.KeyHome:
 			ex.index = 0
 			ex.Invalidate()
-		case tb.KeyCtrlE, tb.KeyEnd:
+		case tcell.KeyCtrlE, tcell.KeyEnd:
 			ex.index = len(ex.command)
 			ex.Invalidate()
-		case tb.KeyCtrlW:
+		case tcell.KeyCtrlW:
 			ex.deleteWord()
-		case tb.KeyEnter:
-			tb.HideCursor()
+		case tcell.KeyEnter:
+			//ex.ctx.Screen().HideCursor()
 			ex.commit(string(ex.command))
-		case tb.KeyEsc, tb.KeyCtrlC:
-			tb.HideCursor()
+		case tcell.KeyEsc, tcell.KeyCtrlC:
+			//ex.ctx.Screen().HideCursor()
 			ex.cancel()
 		default:
-			if event.Ch != 0 {
-				ex.insert(event.Ch)
+			if event.Rune() != 0 {
+				ex.insert(event.Rune())
 			}
 		}
 	}