-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
105 lines (89 loc) · 1.91 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"os"
"tui/test/models"
"tui/test/views"
"github.com/Broderick-Westrope/charmutils"
tea "github.com/charmbracelet/bubbletea"
)
type app struct {
step models.Step
searchModel views.SearchModel
downloadModel views.DownloadModel
}
func (app app) Init() tea.Cmd {
return nil
}
func (app app) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c":
return app, tea.Quit
}
}
switch app.step {
case models.Searching:
cmd, err := charmutils.UpdateTypedModel(&app.searchModel, msg)
if err != nil {
panic(err)
}
return app, cmd
case models.Downloading:
cmd, err := charmutils.UpdateTypedModel(&app.downloadModel, msg)
if err != nil {
panic(err)
}
return app, cmd
}
return app, nil
}
func (app app) View() string {
switch app.step {
case models.Searching:
return app.searchModel.View()
case models.Downloading:
return app.downloadModel.View()
default:
return "ERROR"
}
}
// var searchBar, content string
// switch app.state.Step {
// case models.Searching:
// searchBar = app.searchInput.View()
// switch app.state.ApiState.Status {
// case models.Idle:
// content = ""
// case models.Loading:
// content = "Loading..."
// case models.Success:
// content = app.resultsList.View()
// case models.Error:
// content = fmt.Sprintf("Error: %v", app.state.ApiState.Error)
// }
// return fmt.Sprintf(
// "%s\n%s",
// searchBar,
// content,
// )
// case models.Downloading:
// content = "Downloading..."
// return fmt.Sprintf(
// "%s",
// content,
// )
// default:
// return fmt.Sprintf("Something bad happened")
// }
func main() {
app := app{
step: models.Searching,
searchModel: views.NewSearchModel(),
}
if _, err := tea.NewProgram(app, tea.WithAltScreen()).Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
}