Skip to content

Commit 2dc6386

Browse files
committed
impv: move new homepage
1 parent 78ee0fb commit 2dc6386

File tree

5 files changed

+116
-3
lines changed

5 files changed

+116
-3
lines changed

cmd/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package cmd
22

33
import (
44
"context"
5+
"github.com/initia-labs/weave/models"
56

67
tea "github.com/charmbracelet/bubbletea"
78
"github.com/spf13/cobra"
89
"github.com/spf13/viper"
910

10-
"github.com/initia-labs/weave/models/demo"
1111
"github.com/initia-labs/weave/states"
1212
)
1313

@@ -28,7 +28,7 @@ func Execute() error {
2828
return nil
2929
},
3030
RunE: func(cmd *cobra.Command, args []string) error {
31-
_, err := tea.NewProgram(demo.New()).Run()
31+
_, err := tea.NewProgram(models.NewHomepage()).Run()
3232
if err != nil {
3333
return err
3434
}

models/homepage.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package models
2+
3+
import (
4+
tea "github.com/charmbracelet/bubbletea"
5+
6+
"github.com/initia-labs/weave/models/weaveinit"
7+
"github.com/initia-labs/weave/utils"
8+
)
9+
10+
type Homepage struct {
11+
utils.Selector[HomepageOption]
12+
}
13+
14+
type HomepageOption string
15+
16+
const (
17+
Init HomepageOption = "Weave Init"
18+
)
19+
20+
func NewHomepage() tea.Model {
21+
return &Homepage{
22+
Selector: utils.Selector[HomepageOption]{
23+
Options: []HomepageOption{
24+
Init,
25+
},
26+
Cursor: 0,
27+
},
28+
}
29+
}
30+
31+
func (m *Homepage) Init() tea.Cmd {
32+
return nil
33+
}
34+
35+
func (m *Homepage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
36+
selected, cmd := m.Select(msg)
37+
if selected != nil {
38+
switch *selected {
39+
case Init:
40+
return weaveinit.NewInitSelect(&weaveinit.State{}), nil
41+
}
42+
}
43+
44+
return m, cmd
45+
}
46+
47+
func (m *Homepage) View() string {
48+
view := "Hi 👋🏻 Weave is a CLI for managing Initia deployments.\n"
49+
for i, option := range m.Options {
50+
if i == m.Cursor {
51+
view += "(•) " + string(option) + "\n"
52+
} else {
53+
view += "( ) " + string(option) + "\n"
54+
}
55+
}
56+
return view + "\nPress Enter to select, or q to quit."
57+
}

models/weaveinit/init_select.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package weaveinit
2+
3+
import (
4+
tea "github.com/charmbracelet/bubbletea"
5+
"github.com/initia-labs/weave/utils"
6+
)
7+
8+
type InitSelect struct {
9+
utils.Selector[string]
10+
state *State
11+
}
12+
13+
func NewInitSelect(state *State) *InitSelect {
14+
return &InitSelect{
15+
Selector: utils.Selector[string]{
16+
Options: []string{
17+
"move",
18+
"wasm",
19+
},
20+
Cursor: 0,
21+
},
22+
state: state,
23+
}
24+
}
25+
26+
func (m *InitSelect) Init() tea.Cmd {
27+
return nil
28+
}
29+
30+
func (m *InitSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
31+
selected, cmd := m.Select(msg)
32+
if selected != nil {
33+
m.state.vm = *selected
34+
return m, nil
35+
}
36+
37+
return m, cmd
38+
}
39+
40+
func (m *InitSelect) View() string {
41+
view := "Which vm would you like to build on?\n"
42+
for i, option := range m.Options {
43+
if i == m.Cursor {
44+
view += "(•) " + option + "\n"
45+
} else {
46+
view += "( ) " + option + "\n"
47+
}
48+
}
49+
return view + "\nPress Enter to select, or q to quit."
50+
}

models/weaveinit/state.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package weaveinit
2+
3+
type State struct {
4+
vm string
5+
gasStationMnemonic string
6+
}

states/initia_init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (ii *InitiaInit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4545
}
4646

4747
func (ii *InitiaInit) View() string {
48-
view := "weave init\n\nWhat action would you like to perform?\n"
48+
view := "weave weaveinit\n\nWhat action would you like to perform?\n"
4949
for i, transition := range ii.Transitions {
5050
if i == ii.Cursor {
5151
view += "(•) " + transition.GetName() + "\n"

0 commit comments

Comments
 (0)