aboutsummaryrefslogtreecommitdiff
path: root/lib/ui/textinput.go
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/ui/textinput.go
parent065da5e37230976d85d163a6f682eddb9345aede (diff)
Update tab name as subject changes
Also moves truncation to the tab widget
Diffstat (limited to 'lib/ui/textinput.go')
-rw-r--r--lib/ui/textinput.go15
1 files changed, 15 insertions, 0 deletions
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: