put buttons next to each other

This commit is contained in:
2024-12-26 21:12:20 +02:00
parent 1d456b9863
commit 85ebb57885
+31 -14
View File
@@ -51,6 +51,7 @@ type Model struct {
Config []Config Config []Config
VisibleConfig []Config VisibleConfig []Config
FocusIndex int FocusIndex int
ChoiceIndex int
ParsedConfig ParsedConfig ParsedConfig ParsedConfig
DryRun bool DryRun bool
ErrQuit bool ErrQuit bool
@@ -180,16 +181,16 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "enter", " ": case "enter", " ":
// parse config and switch to main screen if we're focused on the start button // parse config and switch to main screen if we're focused on the start button
if m.FocusIndex == len(m.VisibleConfig) { if m.FocusIndex == len(m.VisibleConfig) {
return m, m.parseConfig(false) if m.ChoiceIndex == 0 {
} return m, m.parseConfig(false)
// parse config, print it and exit } else if m.ChoiceIndex == 1 {
if m.FocusIndex == len(m.VisibleConfig)+1 { return m, m.parseConfig(true)
return m, m.parseConfig(true) }
} }
case "g": case "g":
m.FocusIndex = 0 m.FocusIndex = 0
case "G": case "G":
m.FocusIndex = len(m.VisibleConfig) + 1 m.FocusIndex = len(m.VisibleConfig)
case "tab", "shift+tab", "up", "down", "j", "k": case "tab", "shift+tab", "up", "down", "j", "k":
if key == "up" || key == "shift+tab" || key == "k" { if key == "up" || key == "shift+tab" || key == "k" {
m.FocusIndex-- m.FocusIndex--
@@ -197,10 +198,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.FocusIndex++ m.FocusIndex++
} }
if m.FocusIndex >= len(m.VisibleConfig)+2 { if m.FocusIndex > len(m.VisibleConfig) {
m.FocusIndex = 0 m.FocusIndex = 0
} else if m.FocusIndex < 0 { } else if m.FocusIndex < 0 {
m.FocusIndex = len(m.VisibleConfig) + 1 m.FocusIndex = len(m.VisibleConfig)
} }
case "left", "right", "h", "l": case "left", "right", "h", "l":
// If we're not hovering a button // If we're not hovering a button
@@ -220,6 +221,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.updateConfigFocusedOptions() m.updateConfigFocusedOptions()
m.VisibleConfig = getVisibleConfigs(m.Config) m.VisibleConfig = getVisibleConfigs(m.Config)
} else {
if key == "right" || key == "l" {
m.ChoiceIndex++
} else {
m.ChoiceIndex--
}
if m.ChoiceIndex > 1 {
m.ChoiceIndex = 0
} else if m.ChoiceIndex < 0 {
m.ChoiceIndex = 1
}
} }
} }
case quitMsg: case quitMsg:
@@ -362,18 +375,22 @@ func CfgScreenView(m Model) string {
} }
} }
if m.FocusIndex == len(m.VisibleConfig) { var startButton string
view += FocusedStartButton var dryRunButton string
if m.FocusIndex == len(m.VisibleConfig) && m.ChoiceIndex == 0 {
startButton = FocusedStartButton
} else { } else {
view += BlurredStartButton startButton = BlurredStartButton
} }
if m.FocusIndex == len(m.VisibleConfig)+1 { if m.FocusIndex == len(m.VisibleConfig) && m.ChoiceIndex == 1 {
view += FocusedDryRunButton dryRunButton = FocusedDryRunButton
} else { } else {
view += BlurredDryRunButton dryRunButton = BlurredDryRunButton
} }
view += lipgloss.JoinHorizontal(0, startButton, dryRunButton)
view += "\n" view += "\n"
return view return view