From 80e891a8024ac10a60daa790131e04f0326b0c73 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Fri, 1 Jun 2018 09:58:00 +0200 Subject: 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 --- widgets/exline.go | 49 +++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'widgets/exline.go') 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()) } } } -- cgit v1.2.3