-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (85 loc) · 2.01 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
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
)
const (
homeView = iota
vaultsView
createVaultView
enterVaultView
vaultView
createSecretView
)
const VAULTSPATH = "vaults/"
var Program *tea.Program
func main() {
Program = tea.NewProgram(initialMainModel())
if _, err := Program.Run(); err != nil {
fmt.Printf("There is been an error: %v", err)
os.Exit(1)
}
}
type mainModel struct {
viewState int
homeView tea.Model
vaultsView tea.Model
createVaultView tea.Model
enterVaultView tea.Model
vaultView tea.Model
createSecretView tea.Model
}
func (m mainModel) Init() tea.Cmd {
return tea.Batch(tea.EnterAltScreen, tea.WindowSize())
}
func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch m.viewState {
default:
model, cmd := m.homeView.Update(msg)
return model, cmd
case vaultsView:
model, cmd := m.vaultsView.Update(msg)
return model, cmd
case createVaultView:
model, cmd := m.createVaultView.Update(msg)
return model, cmd
case enterVaultView:
model, cmd := m.enterVaultView.Update(msg)
return model, cmd
case vaultView:
model, cmd := m.vaultView.Update(msg)
return model, cmd
case createSecretView:
model, cmd := m.createSecretView.Update(msg)
return model, cmd
}
}
func (m mainModel) View() string {
switch m.viewState {
default:
return m.homeView.View()
case vaultsView:
return m.vaultsView.View()
case createVaultView:
return m.createVaultView.View()
case enterVaultView:
return m.enterVaultView.View()
case vaultView:
return m.vaultView.View()
case createSecretView:
return m.createSecretView.View()
}
}
func initialMainModel() mainModel {
var m mainModel
m = mainModel{
viewState: homeView,
homeView: InitialHomeModel(&m),
vaultsView: InitialVaultsModel(&m),
createVaultView: InitialCreateVaultModel(&m),
enterVaultView: InitialEnterVaultModel(&m),
vaultView: InitialVaultModel(&m),
createSecretView: InitialCreateSecretModel(&m)}
return m
}