Skip to content

Commit d6dc1aa

Browse files
committed
feat: basic keep previous responses
1 parent 470ab6a commit d6dc1aa

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

models/weaveinit/run_l1_node.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package weaveinit
22

33
import (
44
"fmt"
5+
"github.com/initia-labs/weave/styles"
56
"os"
67
"path/filepath"
78

@@ -12,7 +13,8 @@ import (
1213

1314
type RunL1NodeNetworkSelect struct {
1415
utils.Selector[L1NodeNetworkOption]
15-
state *RunL1NodeState
16+
state *RunL1NodeState
17+
question string
1618
}
1719

1820
type L1NodeNetworkOption string
@@ -32,18 +34,25 @@ func NewRunL1NodeNetworkSelect(state *RunL1NodeState) *RunL1NodeNetworkSelect {
3234
Local,
3335
},
3436
},
35-
state: state,
37+
state: state,
38+
question: "Which network will your node participate in?",
3639
}
3740
}
3841

42+
func (m *RunL1NodeNetworkSelect) GetQuestion() string {
43+
return m.question
44+
}
45+
3946
func (m *RunL1NodeNetworkSelect) Init() tea.Cmd {
4047
return nil
4148
}
4249

4350
func (m *RunL1NodeNetworkSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4451
selected, cmd := m.Select(msg)
4552
if selected != nil {
46-
m.state.network = string(*selected)
53+
selectedString := string(*selected)
54+
m.state.network = selectedString
55+
m.state.weave.PreviousResponse += styles.RenderPreviousResponse(styles.ArrowSeparator, m.GetQuestion(), []string{}, selectedString)
4756
switch *selected {
4857
case Mainnet, Testnet:
4958
return NewExistingAppChecker(m.state), utils.DoTick()
@@ -57,7 +66,11 @@ func (m *RunL1NodeNetworkSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5766
}
5867

5968
func (m *RunL1NodeNetworkSelect) View() string {
60-
view := "? Which network will your node participate in?\n"
69+
view := m.state.weave.PreviousResponse + styles.RenderPrompt(
70+
"Which network will your node participate in?\n",
71+
[]string{},
72+
styles.Question,
73+
)
6174
for i, option := range m.Options {
6275
if i == m.Cursor {
6376
view += "(■) " + string(option) + "\n"
@@ -95,7 +108,7 @@ func (m *RunL1NodeVersionInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
95108
}
96109

97110
func (m *RunL1NodeVersionInput) View() string {
98-
return m.TextInput.View("Please specify the initiad version")
111+
return m.state.weave.PreviousResponse + m.TextInput.View("Please specify the initiad version")
99112
}
100113

101114
type RunL1NodeChainIdInput struct {

models/weaveinit/state.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package weaveinit
22

3+
import "github.com/initia-labs/weave/types"
4+
35
type RunL1NodeState struct {
6+
weave types.WeaveState
47
network string
58
initiadVersion string
69
chainId string

styles/text.go

+19
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ func RenderPrompt(text string, highlights []string, status PromptStatus) string
6767
// Return the prompt with the highlighted text
6868
return prompt + text
6969
}
70+
71+
type ResponseSeparator int64
72+
73+
const (
74+
ArrowSeparator ResponseSeparator = iota
75+
DotsSeparator
76+
)
77+
78+
func RenderPreviousResponse(separator ResponseSeparator, question string, highlights []string, answer string) string {
79+
var separatorString string
80+
switch separator {
81+
case ArrowSeparator:
82+
separatorString = Text(" > ", Gray)
83+
case DotsSeparator:
84+
separatorString = Text(" ... ", Gray)
85+
}
86+
87+
return RenderPrompt(question, highlights, Completed) + separatorString + answer + "\n"
88+
}

types/state.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package types
2+
3+
type WeaveState struct {
4+
PreviousResponse string
5+
}

utils/text_input.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ type TextInput struct {
1111
Text string
1212
Cursor int // Cursor position within the text
1313
Placeholder string
14-
Entered bool
1514
}
1615

1716
func NewTextInput() TextInput {
18-
return TextInput{Text: "", Cursor: 0, Placeholder: "<todo: Jennie revisit placeholder>", Entered: false}
17+
return TextInput{
18+
Text: "",
19+
Cursor: 0,
20+
Placeholder: "<todo: Jennie revisit placeholder>",
21+
}
1922
}
2023

2124
func (ti TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd, bool) {
2225
switch msg := msg.(type) {
2326
case tea.KeyMsg:
2427
switch msg.Type {
2528
case tea.KeyEnter:
26-
ti.Entered = true
2729
return ti, nil, true
2830
case tea.KeyBackspace, tea.KeyCtrlH:
2931
if ti.Cursor > 0 && len(ti.Text) > 0 {
@@ -50,11 +52,7 @@ func (ti TextInput) Update(msg tea.Msg) (TextInput, tea.Cmd, bool) {
5052
}
5153

5254
func (ti TextInput) View(questionText string) string {
53-
if !ti.Entered {
54-
questionText = styles.Text("? ", styles.Cyan) + questionText + "\n> "
55-
} else {
56-
questionText = styles.Text("✓ ", styles.Green) + questionText + "\n> "
57-
}
55+
questionText = styles.Text("? ", styles.Cyan) + questionText + "\n> "
5856

5957
var beforeCursor, cursorChar, afterCursor string
6058
if len(ti.Text) == 0 {

0 commit comments

Comments
 (0)