1
1
package states
2
2
3
3
import (
4
+ "sync"
5
+
4
6
tea "github.com/charmbracelet/bubbletea"
5
7
)
6
8
@@ -9,15 +11,24 @@ var _ tea.Model = &InitiaInit{}
9
11
10
12
type InitiaInit struct {
11
13
BaseState
14
+ once sync.Once
12
15
}
13
16
14
- func NewInitiaInit (transitions []State ) * InitiaInit {
15
- return & InitiaInit {
16
- BaseState : BaseState {
17
- Transitions : transitions ,
18
- Name : "Run L1 Node" ,
19
- },
17
+ // InitiaInitInstance holds the singleton instance of InitiaInit
18
+ var InitiaInitInstance * InitiaInit
19
+
20
+ // GetInitiaInit returns the singleton instance of the InitiaInit state
21
+ func GetInitiaInit () * InitiaInit {
22
+ // Use sync.Once to ensure the InitiaInit is initialized only once
23
+ if InitiaInitInstance == nil {
24
+ InitiaInitInstance = & InitiaInit {}
25
+ InitiaInitInstance .once .Do (func () {
26
+ InitiaInitInstance .BaseState = BaseState {
27
+ Transitions : []State {GetRunL1Node (), GetLaunchNewMinitia ()}, // Initialize transitions if needed
28
+ }
29
+ })
20
30
}
31
+ return InitiaInitInstance
21
32
}
22
33
23
34
func (ii * InitiaInit ) Init () tea.Cmd {
@@ -29,5 +40,17 @@ func (ii *InitiaInit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
29
40
}
30
41
31
42
func (ii * InitiaInit ) View () string {
32
- return ii .Name + " Page\n "
43
+ view := "weave init\n \n What action would you like to perform?\n "
44
+ for i , transition := range ii .Transitions {
45
+ if i == ii .Cursor {
46
+ view += "(•) " + transition .GetName () + "\n "
47
+ } else {
48
+ view += "( ) " + transition .GetName () + "\n "
49
+ }
50
+ }
51
+ return view + "\n Press Enter to go to the selected page, or Q to quit."
52
+ }
53
+
54
+ func (ii * InitiaInit ) GetName () string {
55
+ return "Weave Init"
33
56
}
0 commit comments