batman
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package tui
|
||||
|
||||
import tea "charm.land/bubbletea/v2"
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
// Global keys first — always handled regardless of step
|
||||
if key, ok := msg.(tea.KeyPressMsg); ok {
|
||||
switch key.String() {
|
||||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
|
||||
switch m.currentStep {
|
||||
case StepCheckDocker:
|
||||
return m.updateCheckDocker(msg)
|
||||
case StepDockerInstall:
|
||||
return m.updateDockerInstall(msg)
|
||||
case StepIPQuestion:
|
||||
return m.updateIPQuestion(msg)
|
||||
case StepDone:
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateCheckDocker(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if msg, ok := msg.(DockerCheckedMsg); ok {
|
||||
m.dockerInstalled = msg.Installed
|
||||
if msg.Installed {
|
||||
m.currentStep = StepIPQuestion
|
||||
} else {
|
||||
m.currentStep = StepDockerInstall
|
||||
m.cursor = 0 // reset cursor on enter
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateDockerInstall(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
const numOptions = 2
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyPressMsg:
|
||||
switch msg.String() {
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
m.cursor--
|
||||
}
|
||||
case "down", "j":
|
||||
if m.cursor < numOptions-1 {
|
||||
m.cursor++
|
||||
}
|
||||
case "enter":
|
||||
switch m.cursor {
|
||||
case 0:
|
||||
return m, InstallDockerCmd()
|
||||
case 1:
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
case DockerInstalledMsg:
|
||||
if msg.Err != nil {
|
||||
m.err = msg.Err
|
||||
} else {
|
||||
m.currentStep = StepIPQuestion
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateIPQuestion(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
Reference in New Issue
Block a user