about summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-14 08:07:24 -0500
committerDrew DeVault <sir@cmpwn.com>2019-01-14 08:07:24 -0500
commitd35213eaabeda8749cd0aab103e5895cfcd96e94 (patch)
tree7722340021b0ffe0482eaabf902421883435b6ed /widgets
parent501c95d852971775d64b97872fe63ecea367c525 (diff)
downloadaerc-d35213eaabeda8749cd0aab103e5895cfcd96e94.tar.gz
Add cursor handling in ex line
Diffstat (limited to 'widgets')
-rw-r--r--widgets/exline.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/widgets/exline.go b/widgets/exline.go
index ae83933..e0954d7 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -14,7 +14,9 @@ import (
 type ExLine struct {
 	command []rune
 	commit  func(cmd string)
+	ctx     *ui.Context
 	cancel  func()
+	cells   int
 	index   int
 	scroll  int
 
@@ -24,6 +26,7 @@ type ExLine struct {
 func NewExLine(commit func(cmd string), cancel func()) *ExLine {
 	return &ExLine{
 		cancel:  cancel,
+		cells:   -1,
 		commit:  commit,
 		command: []rune{},
 	}
@@ -40,10 +43,13 @@ func (ex *ExLine) Invalidate() {
 }
 
 func (ex *ExLine) Draw(ctx *ui.Context) {
+	ex.ctx = ctx // gross
 	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]))
-	ctx.SetCursor(cells+1, 0)
+	if cells != ex.cells {
+		ctx.SetCursor(cells+1, 0)
+	}
 }
 
 func (ex *ExLine) insert(ch rune) {
@@ -115,10 +121,10 @@ func (ex *ExLine) Event(event tcell.Event) bool {
 		case tcell.KeyCtrlW:
 			ex.deleteWord()
 		case tcell.KeyEnter:
-			//ex.ctx.Screen().HideCursor()
+			ex.ctx.HideCursor()
 			ex.commit(string(ex.command))
 		case tcell.KeyEsc, tcell.KeyCtrlC:
-			//ex.ctx.Screen().HideCursor()
+			ex.ctx.HideCursor()
 			ex.cancel()
 		default:
 			if event.Rune() != 0 {