-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
72 lines (58 loc) · 1.4 KB
/
input.go
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
package main
import (
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
type Input interface {
Value() string
View() string
Blur() tea.Msg
Update(tea.Msg) (Input, tea.Cmd)
}
type shortAnswerField struct {
textinput textinput.Model
}
type longAnswerField struct {
textarea textarea.Model
}
func NewShortAnswerField() *shortAnswerField {
ti := textinput.New()
ti.Placeholder = "Your answer here..."
ti.Focus()
return &shortAnswerField{ti}
}
func (sa *shortAnswerField) Value() string {
return sa.textinput.Value()
}
func (sa *shortAnswerField) View() string {
return sa.textinput.View()
}
func (sa *shortAnswerField) Blur() tea.Msg {
return sa.textinput.Blur
}
func (sa *shortAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) {
var cmd tea.Cmd
sa.textinput, cmd = sa.textinput.Update(msg)
return sa, cmd
}
func NewLongAnswerField() *longAnswerField {
ta := textarea.New()
ta.Placeholder = "Your answer here..."
ta.Focus()
return &longAnswerField{ta}
}
func (la *longAnswerField) Value() string {
return la.textarea.Value()
}
func (la *longAnswerField) View() string {
return la.textarea.View()
}
func (la *longAnswerField) Blur() tea.Msg {
return la.textarea.Blur
}
func (la *longAnswerField) Update(msg tea.Msg) (Input, tea.Cmd) {
var cmd tea.Cmd
la.textarea, cmd = la.textarea.Update(msg)
return la, cmd
}