Skip to content

Commit d9470ba

Browse files
committed
feat: initial global
1 parent 00e7666 commit d9470ba

9 files changed

+135
-9
lines changed

go.mod

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module github.com/initia-labs/weave
33
go 1.22.6
44

55
require (
6+
github.com/charmbracelet/bubbles v0.19.0
67
github.com/charmbracelet/bubbletea v1.1.0
78
github.com/spf13/cobra v1.8.1
89
github.com/spf13/viper v1.19.0
9-
github.com/stretchr/testify v1.9.0
1010
)
1111

1212
require (
13+
github.com/atotto/clipboard v0.1.4 // indirect
1314
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1415
github.com/charmbracelet/lipgloss v0.13.0 // indirect
1516
github.com/charmbracelet/x/ansi v0.2.3 // indirect
1617
github.com/charmbracelet/x/term v0.2.0 // indirect
17-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1818
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
1919
github.com/fsnotify/fsnotify v1.7.0 // indirect
2020
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -23,13 +23,12 @@ require (
2323
github.com/magiconair/properties v1.8.7 // indirect
2424
github.com/mattn/go-isatty v0.0.20 // indirect
2525
github.com/mattn/go-localereader v0.0.1 // indirect
26-
github.com/mattn/go-runewidth v0.0.15 // indirect
26+
github.com/mattn/go-runewidth v0.0.16 // indirect
2727
github.com/mitchellh/mapstructure v1.5.0 // indirect
2828
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
2929
github.com/muesli/cancelreader v0.2.2 // indirect
3030
github.com/muesli/termenv v0.15.2 // indirect
3131
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
32-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
3332
github.com/rivo/uniseg v0.4.7 // indirect
3433
github.com/sagikazarmark/locafero v0.4.0 // indirect
3534
github.com/sagikazarmark/slog-shim v0.1.0 // indirect

go.sum

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
2+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
13
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
24
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
5+
github.com/charmbracelet/bubbles v0.19.0 h1:gKZkKXPP6GlDk6EcfujDK19PCQqRjaJZQ7QRERx1UF0=
6+
github.com/charmbracelet/bubbles v0.19.0/go.mod h1:WILteEqZ+krG5c3ntGEMeG99nCupcuIk7V0/zOP0tOA=
37
github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c=
48
github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
59
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
@@ -37,8 +41,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
3741
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
3842
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
3943
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
40-
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
41-
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
44+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
45+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
4246
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
4347
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
4448
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=

states/global.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package states
2+
3+
import (
4+
"sync"
5+
)
6+
7+
type GlobalState struct {
8+
mu sync.RWMutex
9+
10+
mnemonic string
11+
}
12+
13+
var globalStateInstance *GlobalState
14+
var once sync.Once
15+
16+
func GetGlobalState() *GlobalState {
17+
once.Do(func() {
18+
globalStateInstance = &GlobalState{}
19+
})
20+
return globalStateInstance
21+
}
22+
23+
func (gs *GlobalState) GetMnemonic() string {
24+
gs.mu.RLock()
25+
defer gs.mu.RUnlock()
26+
return gs.mnemonic
27+
}
28+
29+
func (gs *GlobalState) SetMnemonic(mnemonic string) {
30+
gs.mu.Lock()
31+
defer gs.mu.Unlock()
32+
gs.mnemonic = mnemonic
33+
}

states/homepage.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func GetHomePage() *HomePage {
2525
HomePageInstance = &HomePage{}
2626
HomePageInstance.once.Do(func() {
2727
HomePageInstance.BaseState = BaseState{
28-
Transitions: []State{GetInitiaInit()}, // Ensure all transitions are properly initialized
28+
Transitions: []State{GetInitiaInit()},
29+
Global: GetGlobalState(),
2930
}
3031
})
3132
}

states/initia_init.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func GetInitiaInit() *InitiaInit {
2525
InitiaInitInstance.once.Do(func() {
2626
InitiaInitInstance.BaseState = BaseState{
2727
Transitions: []State{GetRunL1Node(), GetLaunchNewMinitia()}, // Initialize transitions if needed
28+
Global: GetGlobalState(),
2829
}
2930
})
3031
}

states/launch_minitia.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func GetLaunchNewMinitia() *LaunchNewMinitia {
2424
LaunchNewMinitiaInstance.once.Do(func() {
2525
LaunchNewMinitiaInstance.BaseState = BaseState{
2626
Transitions: []State{},
27+
Global: GetGlobalState(),
2728
}
2829
})
2930
}

states/run_l1_node.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package states
22

33
import (
4+
"fmt"
45
"sync"
56

67
tea "github.com/charmbracelet/bubbletea"
@@ -23,7 +24,10 @@ func GetRunL1Node() *RunL1Node {
2324
RunL1NodeInstance = &RunL1Node{}
2425
RunL1NodeInstance.once.Do(func() {
2526
RunL1NodeInstance.BaseState = BaseState{
26-
Transitions: []State{},
27+
Transitions: []State{
28+
GetTextInput(),
29+
},
30+
Global: GetGlobalState(),
2731
}
2832
})
2933
}
@@ -39,7 +43,7 @@ func (rl1 *RunL1Node) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3943
}
4044

4145
func (rl1 *RunL1Node) View() string {
42-
return rl1.GetName() + " Page\n"
46+
return fmt.Sprintf("🪢🪢 Welcome to %s Page 🪢🪢\n\nPress enter to continue...", rl1.GetName())
4347
}
4448

4549
func (rl1 *RunL1Node) GetName() string {

states/state.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type State interface {
2222
type BaseState struct {
2323
Transitions []State
2424
Cursor int
25+
Global *GlobalState
2526
}
2627

2728
func (bs *BaseState) CommonUpdate(msg tea.Msg, currentState State) (tea.Model, tea.Cmd) {

states/textinput.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package states
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
7+
"github.com/charmbracelet/bubbles/textinput"
8+
tea "github.com/charmbracelet/bubbletea"
9+
)
10+
11+
type (
12+
errMsg error
13+
)
14+
15+
var _ State = &TextInput{}
16+
var _ tea.Model = &TextInput{}
17+
18+
type TextInput struct {
19+
BaseState
20+
once sync.Once
21+
22+
textInput textinput.Model
23+
err error
24+
}
25+
26+
var textInputInstance *TextInput
27+
28+
func GetTextInput() *TextInput {
29+
if textInputInstance == nil {
30+
ti := textinput.New()
31+
ti.Placeholder = "Some Option"
32+
ti.Focus()
33+
ti.CharLimit = 64
34+
ti.Width = 20
35+
textInputInstance = &TextInput{
36+
textInput: ti,
37+
err: nil,
38+
}
39+
textInputInstance.once.Do(func() {
40+
textInputInstance.BaseState = BaseState{
41+
Transitions: []State{},
42+
Global: GetGlobalState(),
43+
}
44+
})
45+
}
46+
return textInputInstance
47+
}
48+
49+
func (ti *TextInput) Init() tea.Cmd {
50+
return textinput.Blink
51+
}
52+
53+
func (ti *TextInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
54+
var cmd tea.Cmd
55+
56+
switch msg := msg.(type) {
57+
case tea.KeyMsg:
58+
switch msg.Type {
59+
case tea.KeyEnter, tea.KeyCtrlC, tea.KeyEsc:
60+
return ti, tea.Quit
61+
}
62+
63+
case errMsg:
64+
ti.err = msg
65+
return ti, nil
66+
}
67+
68+
ti.textInput, cmd = ti.textInput.Update(msg)
69+
return ti, cmd
70+
}
71+
72+
func (ti *TextInput) View() string {
73+
return fmt.Sprintf(
74+
"? Please set up a Gas Station account\n\n%s\n\n%s",
75+
ti.textInput.View(),
76+
"(esc to quit)",
77+
) + "\n"
78+
}
79+
80+
func (ti *TextInput) GetName() string {
81+
return "Text Input"
82+
}

0 commit comments

Comments
 (0)