-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (65 loc) · 1.48 KB
/
main.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
77
78
79
80
81
82
package main
import (
"log"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
)
type screen interface {
Reset()
Update(msg tea.Msg) (tea.Model, tea.Cmd)
View() string
}
var currentScreen screen
type model struct {
err error
list list.Model
queryTextInput textinput.Model
viewport viewport.Model
ready bool
selectedTopic []list.Item
response SearchResponse
selectedQuery string
resultContent string
}
func (m *model) Init() tea.Cmd {
return nil
}
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg, ok := msg.(tea.WindowSizeMsg); ok {
if !m.ready {
m.ready = true
m.viewport = viewport.Model{Width: msg.Width, Height: msg.Height - (headerHeight + footerHeight)}
m.viewport.YPosition = headerHeight + 1
}
}
return currentScreen.Update(msg)
}
func (m model) View() string {
return currentScreen.View()
}
func InitialModel() *model {
tm := textinput.NewModel()
tm.Placeholder = "Your query"
tm.Focus()
tm.CharLimit = 156
tm.Width = 20
m := model{
queryTextInput: tm,
}
m.list.Title = "Topics"
return &m
}
func setCurrentScreen(scr screen) {
currentScreen = scr
currentScreen.Reset()
}
func main() {
m := InitialModel()
setCurrentScreen(&searchScreen{model: m})
p := tea.NewProgram(m, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
log.Fatal("Error running program:", err)
}
}