File tree 9 files changed +158
-16
lines changed
9 files changed +158
-16
lines changed Original file line number Diff line number Diff line change 7
7
"github.com/spf13/cobra"
8
8
"github.com/spf13/viper"
9
9
10
+ "github.com/initia-labs/weave/models/demo"
10
11
"github.com/initia-labs/weave/states"
11
12
)
12
13
@@ -27,16 +28,7 @@ func Execute() error {
27
28
return nil
28
29
},
29
30
RunE : func (cmd * cobra.Command , args []string ) error {
30
-
31
- // Initialize state transitions and ensure they're set up correctly
32
- states .GetHomePage () // Initialize homepage state
33
-
34
- states .SetHomePageTransitions () // Set homepage transitions lazily after initialization
35
- states .SetInitiaInitTransitions () // Initialize transitions for InitiaInit
36
- states .SetRunL1NodeTransitions () // Initialize transitions for RunL1Node
37
- states .SetRunL1NodeTextInputTransitions () // Initialize transitions for RunL1NodeTextInput
38
-
39
- _ , err := tea .NewProgram (states .GetHomePage ()).Run ()
31
+ _ , err := tea .NewProgram (demo .New ()).Run ()
40
32
if err != nil {
41
33
return err
42
34
}
Original file line number Diff line number Diff line change @@ -3,15 +3,13 @@ module github.com/initia-labs/weave
3
3
go 1.22.6
4
4
5
5
require (
6
- github.com/charmbracelet/bubbles v0.19.0
7
6
github.com/charmbracelet/bubbletea v1.1.0
8
7
github.com/spf13/cobra v1.8.1
9
8
github.com/spf13/viper v1.19.0
10
9
github.com/stretchr/testify v1.9.0
11
10
)
12
11
13
12
require (
14
- github.com/atotto/clipboard v0.1.4 // indirect
15
13
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
16
14
github.com/charmbracelet/lipgloss v0.13.0 // indirect
17
15
github.com/charmbracelet/x/ansi v0.2.3 // indirect
Original file line number Diff line number Diff line change 1
- github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4 =
2
- github.com/atotto/clipboard v0.1.4 /go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI =
3
1
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k =
4
2
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 =
7
3
github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c =
8
4
github.com/charmbracelet/bubbletea v1.1.0 /go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4 =
9
5
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw =
Original file line number Diff line number Diff line change
1
+ package demo
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ tea "github.com/charmbracelet/bubbletea"
7
+
8
+ "github.com/initia-labs/weave/utils"
9
+ )
10
+
11
+ type Denom struct {
12
+ input utils.TextInput
13
+ state * State
14
+ }
15
+
16
+ func NewDenom (state * State ) * Denom {
17
+ return & Denom {
18
+ input : "umin" ,
19
+ state : state ,
20
+ }
21
+ }
22
+
23
+ func (m * Denom ) Init () tea.Cmd {
24
+ return nil
25
+ }
26
+
27
+ func (m * Denom ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
28
+ input , done := m .input .Update (msg )
29
+ if done {
30
+ m .state .denom = string (input )
31
+ fmt .Println ("[info] state " , m .state )
32
+ return m , tea .Quit
33
+ }
34
+ m .input = input
35
+ return m , nil
36
+ }
37
+
38
+ func (m * Denom ) View () string {
39
+ return fmt .Sprintf ("Enter the denom: %s\n " , m .input )
40
+ }
Original file line number Diff line number Diff line change
1
+ package demo
2
+
3
+ import tea "github.com/charmbracelet/bubbletea"
4
+
5
+ func New () tea.Model {
6
+ return NewVMSelect (& State {})
7
+ }
Original file line number Diff line number Diff line change
1
+ package demo
2
+
3
+ type State struct {
4
+ vm string
5
+ denom string
6
+ }
Original file line number Diff line number Diff line change
1
+ package demo
2
+
3
+ import (
4
+ tea "github.com/charmbracelet/bubbletea"
5
+ "github.com/initia-labs/weave/utils"
6
+ )
7
+
8
+ type VMSelect struct {
9
+ utils.Selector [string ]
10
+ state * State
11
+ }
12
+
13
+ func NewVMSelect (state * State ) * VMSelect {
14
+ return & VMSelect {
15
+ Selector : utils.Selector [string ]{
16
+ Options : []string {
17
+ "move" ,
18
+ "wasm" ,
19
+ "evm" ,
20
+ },
21
+ Cursor : 0 ,
22
+ },
23
+ state : state ,
24
+ }
25
+ }
26
+
27
+ func (m * VMSelect ) Init () tea.Cmd {
28
+ return nil
29
+ }
30
+
31
+ func (m * VMSelect ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
32
+ selected , cmd := m .Select (msg )
33
+ if selected != nil {
34
+ m .state .vm = * selected
35
+ return NewDenom (m .state ), nil
36
+ }
37
+
38
+ return m , cmd
39
+ }
40
+
41
+ func (m * VMSelect ) View () string {
42
+ view := "Which vm would you like to build on?\n "
43
+ for i , option := range m .Options {
44
+ if i == m .Cursor {
45
+ view += "(•) " + option + "\n "
46
+ } else {
47
+ view += "( ) " + option + "\n "
48
+ }
49
+ }
50
+ return view + "\n Press Enter to select, or q to quit."
51
+ }
Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import tea "github.com/charmbracelet/bubbletea"
4
+
5
+ type Selector [T any ] struct {
6
+ Options []T
7
+ Cursor int
8
+ }
9
+
10
+ func (s * Selector [T ]) Select (msg tea.Msg ) (* T , tea.Cmd ) {
11
+ switch msg := msg .(type ) {
12
+ case tea.KeyMsg :
13
+ switch msg .String () {
14
+ case "down" , "j" :
15
+ s .Cursor = (s .Cursor + 1 ) % len (s .Options )
16
+ return nil , nil
17
+ case "up" , "k" :
18
+ s .Cursor = (s .Cursor - 1 + len (s .Options )) % len (s .Options )
19
+ return nil , nil
20
+ case "q" , "ctrl+c" :
21
+ return nil , tea .Quit
22
+ case "enter" :
23
+ return & s .Options [s .Cursor ], nil
24
+ }
25
+ }
26
+ return nil , nil
27
+ }
Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import tea "github.com/charmbracelet/bubbletea"
4
+
5
+ type TextInput string
6
+
7
+ func (ti TextInput ) Update (msg tea.Msg ) (TextInput , bool ) {
8
+ switch msg := msg .(type ) {
9
+ case tea.KeyMsg :
10
+ switch msg .Type {
11
+ case tea .KeyEnter :
12
+ return ti , true
13
+ default :
14
+ return HandleKeyInput (ti , msg ), false
15
+ }
16
+ }
17
+ return ti , false
18
+ }
19
+
20
+ func HandleKeyInput (currentText TextInput , msg tea.KeyMsg ) TextInput {
21
+ if msg .Type == tea .KeyRunes {
22
+ return currentText + TextInput (string (msg .Runes ))
23
+ }
24
+ return currentText
25
+ }
You can’t perform that action at this time.
0 commit comments