-
Notifications
You must be signed in to change notification settings - Fork 182
/
prompt.go
66 lines (52 loc) 路 1.06 KB
/
prompt.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
package prompt
import (
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/dlvhdr/gh-dash/ui/context"
)
type Model struct {
ctx *context.ProgramContext
prompt textinput.Model
}
func NewModel(ctx *context.ProgramContext) Model {
ti := textinput.New()
ti.Focus()
ti.Blur()
ti.CursorStart()
return Model{
ctx: ctx,
prompt: ti,
}
}
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
var cmd tea.Cmd
m.prompt, cmd = m.prompt.Update(msg)
return m, cmd
}
func (m Model) View() string {
return m.prompt.View()
}
func (m Model) Init() tea.Cmd {
return textinput.Blink
}
func (m *Model) Blur() {
m.prompt.Blur()
}
func (m *Model) Focus() tea.Cmd {
return m.prompt.Focus()
}
func (m *Model) SetValue(value string) {
m.prompt.SetValue(value)
}
func (m *Model) Value() string {
return m.prompt.Value()
}
func (m *Model) SetPrompt(prompt string) {
m.prompt.Prompt = prompt
}
func (m *Model) Reset() {
m.prompt.Reset()
}
func (m *Model) UpdateProgramContext(ctx *context.ProgramContext) {
m.ctx = ctx
}