-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
76 lines (61 loc) · 1.53 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
73
74
75
76
package main
import (
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
type Input interface {
Value() string
Blur() tea.Msg
Update(tea.Msg) (Input, tea.Cmd)
View() string
}
type ShortAnswerField struct {
textinput textinput.Model
}
// textinput
func NewShortAnswerField() *ShortAnswerField {
ti := textinput.New()
ti.Focus()
ti.Placeholder = "Type your answer here..."
return &ShortAnswerField{ti}
}
func (sa *ShortAnswerField) Value() string {
return sa.textinput.Value()
}
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 (sa *ShortAnswerField) View() string{
return sa.textinput.View()
}
// ------------------------
type LongAnswerField struct {
textarea textarea.Model
}
// textarea
func NewLongAnswerField() *LongAnswerField {
ta := textarea.New()
ta.Focus()
ta.Placeholder = "Type your answer here..."
return &LongAnswerField{ta}
}
func (la *LongAnswerField) Value() string {
return la.textarea.Value()
}
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
}
func (la *LongAnswerField) View() string{
return la.textarea.View()
}