about summary refs log tree commit diff stats
path: root/lib/ui/text.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 /lib/ui/text.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 'lib/ui/text.go')
-rw-r--r--lib/ui/text.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/ui/text.go b/lib/ui/text.go
index 6164837..e2e218c 100644
--- a/lib/ui/text.go
+++ b/lib/ui/text.go
@@ -2,7 +2,7 @@ package ui
 
 import (
 	"github.com/mattn/go-runewidth"
-	tb "github.com/nsf/termbox-go"
+	"github.com/gdamore/tcell"
 )
 
 const (
@@ -14,8 +14,8 @@ const (
 type Text struct {
 	text         string
 	strategy     uint
-	fg           tb.Attribute
-	bg           tb.Attribute
+	fg           tcell.Color
+	bg           tcell.Color
 	onInvalidate func(d Drawable)
 }
 
@@ -35,7 +35,7 @@ func (t *Text) Strategy(strategy uint) *Text {
 	return t
 }
 
-func (t *Text) Color(fg tb.Attribute, bg tb.Attribute) *Text {
+func (t *Text) Color(fg tcell.Color, bg tcell.Color) *Text {
 	t.fg = fg
 	t.bg = bg
 	t.Invalidate()
@@ -44,11 +44,6 @@ func (t *Text) Color(fg tb.Attribute, bg tb.Attribute) *Text {
 
 func (t *Text) Draw(ctx *Context) {
 	size := runewidth.StringWidth(t.text)
-	cell := tb.Cell{
-		Ch: ' ',
-		Fg: t.fg,
-		Bg: t.bg,
-	}
 	x := 0
 	if t.strategy == TEXT_CENTER {
 		x = (ctx.Width() - size) / 2
@@ -56,8 +51,9 @@ func (t *Text) Draw(ctx *Context) {
 	if t.strategy == TEXT_RIGHT {
 		x = ctx.Width() - size
 	}
-	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), cell)
-	ctx.Printf(x, 0, cell, "%s", t.text)
+	style := tcell.StyleDefault.Background(t.bg).Foreground(t.fg)
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
+	ctx.Printf(x, 0, style, t.text)
 }
 
 func (t *Text) OnInvalidate(onInvalidate func(d Drawable)) {