summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-14 16:18:21 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-14 16:18:59 -0400
commit2c486cb7f52ac5dd88f7445ca79726639e4a0084 (patch)
tree552b1fe370f1fd2344687c7e55ada9d80c0bc9a7 /lib
parent065da5e37230976d85d163a6f682eddb9345aede (diff)
downloadaerc-2c486cb7f52ac5dd88f7445ca79726639e4a0084.tar.gz
Update tab name as subject changes
Also moves truncation to the tab widget
Diffstat (limited to 'lib')
-rw-r--r--lib/ui/tab.go4
-rw-r--r--lib/ui/textinput.go15
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/ui/tab.go b/lib/ui/tab.go
index 49bdffa..c39e327 100644
--- a/lib/ui/tab.go
+++ b/lib/ui/tab.go
@@ -2,6 +2,7 @@ package ui
 
 import (
 	"github.com/gdamore/tcell"
+	"github.com/mattn/go-runewidth"
 )
 
 type Tabs struct {
@@ -87,7 +88,8 @@ func (strip *TabStrip) Draw(ctx *Context) {
 		if strip.Selected == i {
 			style = tcell.StyleDefault
 		}
-		x += ctx.Printf(x, 0, style, " %s ", tab.Name)
+		trunc := runewidth.Truncate(tab.Name, 32, "…")
+		x += ctx.Printf(x, 0, style, " %s ", trunc)
 	}
 	style := tcell.StyleDefault.Reverse(true)
 	ctx.Fill(x, 0, ctx.Width()-x, 1, ' ', style)
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 688d91d..9d2cdc7 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -17,6 +17,7 @@ type TextInput struct {
 	prompt string
 	scroll int
 	text   []rune
+	change []func(ti *TextInput)
 }
 
 // Creates a new TextInput. TextInputs will render a "textbox" in the entire
@@ -69,6 +70,7 @@ func (ti *TextInput) insert(ch rune) {
 	ti.text = append(left, append([]rune{ch}, right...)...)
 	ti.index++
 	ti.Invalidate()
+	ti.onChange()
 }
 
 func (ti *TextInput) deleteWord() {
@@ -88,12 +90,14 @@ func (ti *TextInput) deleteWord() {
 	ti.text = append(ti.text[:i+1], ti.text[ti.index:]...)
 	ti.index = i + 1
 	ti.Invalidate()
+	ti.onChange()
 }
 
 func (ti *TextInput) deleteChar() {
 	if len(ti.text) > 0 && ti.index != len(ti.text) {
 		ti.text = append(ti.text[:ti.index], ti.text[ti.index+1:]...)
 		ti.Invalidate()
+		ti.onChange()
 	}
 }
 
@@ -102,9 +106,20 @@ func (ti *TextInput) backspace() {
 		ti.text = append(ti.text[:ti.index-1], ti.text[ti.index:]...)
 		ti.index--
 		ti.Invalidate()
+		ti.onChange()
 	}
 }
 
+func (ti *TextInput) onChange() {
+	for _, change := range ti.change {
+		change(ti)
+	}
+}
+
+func (ti *TextInput) OnChange(onChange func(ti *TextInput)) {
+	ti.change = append(ti.change, onChange)
+}
+
 func (ti *TextInput) Event(event tcell.Event) bool {
 	switch event := event.(type) {
 	case *tcell.EventKey:
e='author Drew DeVault <sir@cmpwn.com> 2018-02-27 21:17:26 -0500 committer Drew DeVault <sir@cmpwn.com> 2018-02-27 21:17:26 -0500 Pull main aerc UI into widget' href='/akspecs/aerc/commit/widgets/aerc.go?h=0.5.0&id=cab3771e17286788913255a6abe858b476166837'>cab3771 ^
80e891a ^
1c41b63 ^

cab3771 ^
648ca98 ^

1c41b63 ^
cab3771 ^
cab3771 ^
6728a11 ^



cab3771 ^














80e891a ^



cea9846 ^

6728a11 ^
cea9846 ^









80e891a ^




cea9846 ^
cab3771 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91