Skip to content

Commit 94b81c5

Browse files
committed
feat: improve check box
1 parent ae9b4c4 commit 94b81c5

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

models/weaveinit/run_l1_node.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (m *MinGasPriceInput) View() string {
294294
}
295295

296296
type EnableFeaturesCheckbox struct {
297-
utils.Selector[EnableFeaturesOption]
297+
utils.CheckBox[EnableFeaturesOption]
298298
state *RunL1NodeState
299299
}
300300

@@ -307,13 +307,8 @@ const (
307307

308308
func NewEnableFeaturesCheckbox(state *RunL1NodeState) *EnableFeaturesCheckbox {
309309
return &EnableFeaturesCheckbox{
310-
Selector: utils.Selector[EnableFeaturesOption]{
311-
Options: []EnableFeaturesOption{
312-
LCD,
313-
gRPC,
314-
},
315-
},
316-
state: state,
310+
CheckBox: *utils.NewCheckBox([]EnableFeaturesOption{LCD, gRPC}),
311+
state: state,
317312
}
318313
}
319314

@@ -322,17 +317,16 @@ func (m *EnableFeaturesCheckbox) Init() tea.Cmd {
322317
}
323318

324319
func (m *EnableFeaturesCheckbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
325-
return m, nil
320+
cb, cmd, done := m.Select(msg)
321+
if done {
322+
fmt.Println("yo")
323+
}
324+
m.CheckBox = *cb
325+
return m, cmd
326326
}
327327

328328
func (m *EnableFeaturesCheckbox) View() string {
329329
view := "? Would you like to enable the following options?\n"
330-
for i, option := range m.Options {
331-
if i == m.Cursor {
332-
view += "(■) " + string(option) + "\n"
333-
} else {
334-
view += "( ) " + string(option) + "\n"
335-
}
336-
}
330+
view += m.CheckBox.View()
337331
return view + "\nUse arrow-keys. Space to select. Return to submit, or q to quit."
338332
}

utils/checkbox.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ func (s *CheckBox[T]) View() string {
5757
if i == s.Cursor {
5858
cursor = ">"
5959
}
60-
selectedMark := " "
60+
selectedMark := ""
6161
if s.Selected[i] {
62-
selectedMark = "x"
62+
selectedMark = ""
6363
}
64-
b.WriteString(fmt.Sprintf("%s [%s] %v\n", cursor, selectedMark, option))
64+
b.WriteString(fmt.Sprintf("%s %s %v\n", cursor, selectedMark, option))
6565
}
6666
return b.String()
6767
}

0 commit comments

Comments
 (0)