mirror of
https://github.com/clearlinux/clr-installer.git
synced 2026-04-28 11:13:46 +00:00
Enable Left-Right arrows for Tabs
Signed-off-by: Mark D Horn <mark.d.horn@intel.com>
This commit is contained in:
50
tui/tab.go
50
tui/tab.go
@@ -5,6 +5,8 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/VladimirMarkelov/clui"
|
||||
term "github.com/nsf/termbox-go"
|
||||
|
||||
"github.com/clearlinux/clr-installer/errors"
|
||||
)
|
||||
|
||||
@@ -124,12 +126,60 @@ func (tg *TabGroup) AddTab(label string, hotKey rune) (*TabPage, error) {
|
||||
return page, nil
|
||||
}
|
||||
|
||||
func (tg *TabGroup) findNextTab() *TabPage {
|
||||
if len(tg.pages) < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
maxIndex := len(tg.pages) - 1
|
||||
index := 0
|
||||
for i, curr := range tg.pages {
|
||||
if curr == tg.selected {
|
||||
index = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
// Check for running of the end
|
||||
if index > maxIndex {
|
||||
index = maxIndex
|
||||
}
|
||||
|
||||
return tg.pages[index]
|
||||
}
|
||||
|
||||
func (tg *TabGroup) findPrevTab() *TabPage {
|
||||
if len(tg.pages) < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
minIndex := 0
|
||||
index := 0
|
||||
for i, curr := range tg.pages {
|
||||
if curr == tg.selected {
|
||||
index = i - 1
|
||||
}
|
||||
}
|
||||
|
||||
// Check for running of the end
|
||||
if index < minIndex {
|
||||
index = minIndex
|
||||
}
|
||||
|
||||
return tg.pages[index]
|
||||
}
|
||||
|
||||
func keyEventCb(ev clui.Event, data interface{}) bool {
|
||||
cbData := data.(*TabKeyCb)
|
||||
|
||||
var selected *TabPage
|
||||
var hidden []*TabPage
|
||||
|
||||
if ev.Key == term.KeyArrowRight {
|
||||
selected = cbData.tab.findNextTab()
|
||||
} else if ev.Key == term.KeyArrowLeft {
|
||||
selected = cbData.tab.findPrevTab()
|
||||
}
|
||||
|
||||
for _, curr := range cbData.tab.pages {
|
||||
if ev.Ch == curr.hotKey || ev.Ch == unicode.ToUpper(curr.hotKey) {
|
||||
selected = curr
|
||||
|
||||
Reference in New Issue
Block a user