Skip to content

Commit

Permalink
refactor TAB input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arguablykomodo committed Sep 25, 2018
1 parent d51191e commit b35cdaf
Showing 1 changed file with 29 additions and 51 deletions.
80 changes: 29 additions & 51 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,60 +56,38 @@ func createUI() error {
app.Stop()
})

// Setup input so that TAB switches between buttons
profileSelect.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTAB {
if (event.Modifiers() & tcell.ModShift) == tcell.ModShift {
app.SetFocus(exitButton)
// Setup input callbacks so that TAB switches between buttons
app.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
if e.Key() == tcell.KeyTAB {
if e.Modifiers()&tcell.ModShift == tcell.ModShift {
switch {
case exitButton.HasFocus():
app.SetFocus(uninstallButton)
case uninstallButton.HasFocus():
app.SetFocus(installButton)
case installButton.HasFocus():
app.SetFocus(uuidCheckBox)
case uuidCheckBox.HasFocus():
app.SetFocus(profileSelect)
case profileSelect.HasFocus():
app.SetFocus(exitButton)
}
} else {
app.SetFocus(uuidCheckBox)
switch {
case profileSelect.HasFocus():
app.SetFocus(uuidCheckBox)
case uuidCheckBox.HasFocus():
app.SetFocus(installButton)
case installButton.HasFocus():
app.SetFocus(uninstallButton)
case uninstallButton.HasFocus():
app.SetFocus(exitButton)
case exitButton.HasFocus():
app.SetFocus(profileSelect)
}
}
}
return event
})

uuidCheckBox.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTAB {
if (event.Modifiers() & tcell.ModShift) == tcell.ModShift {
app.SetFocus(profileSelect)
} else {
app.SetFocus(installButton)
}
}
return event
})

installButton.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTAB {
if (event.Modifiers() & tcell.ModShift) == tcell.ModShift {
app.SetFocus(uuidCheckBox)
} else {
app.SetFocus(uninstallButton)
}
}
return event
})

uninstallButton.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTAB {
if (event.Modifiers() & tcell.ModShift) == tcell.ModShift {
app.SetFocus(installButton)
} else {
app.SetFocus(exitButton)
}
}
return event
})

exitButton.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyTAB {
if (event.Modifiers() & tcell.ModShift) == tcell.ModShift {
app.SetFocus(uninstallButton)
} else {
app.SetFocus(profileSelect)
}
}
return event
return e
})

flex := tview.NewFlex().SetDirection(tview.FlexRow).
Expand Down

0 comments on commit b35cdaf

Please sign in to comment.