|
|
|
@ -9,10 +9,10 @@ import (
@@ -9,10 +9,10 @@ import (
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
app *cview.Application |
|
|
|
|
inputView *cview.InputField |
|
|
|
|
entryList *optionsList |
|
|
|
|
appDetailsView *cview.TextView |
|
|
|
|
app *cview.Application |
|
|
|
|
inputView *cview.InputField |
|
|
|
|
entryList *cview.List |
|
|
|
|
detailView *cview.TextView |
|
|
|
|
|
|
|
|
|
closedTUI bool |
|
|
|
|
) |
|
|
|
@ -65,8 +65,6 @@ func (r *optionsList) Draw(screen tcell.Screen) {
@@ -65,8 +65,6 @@ func (r *optionsList) Draw(screen tcell.Screen) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tv := r.TextView |
|
|
|
|
tv.SetBackgroundColor(tcell.ColorDefault) |
|
|
|
|
tv.SetTextColor(tcell.ColorDefault) |
|
|
|
|
tv.SetText(b.String()) |
|
|
|
|
tv.Highlight("gmenu") |
|
|
|
|
tv.ScrollToBeginning() |
|
|
|
@ -76,6 +74,13 @@ func (r *optionsList) Draw(screen tcell.Screen) {
@@ -76,6 +74,13 @@ func (r *optionsList) Draw(screen tcell.Screen) {
|
|
|
|
|
func initTUI() (*cview.Application, error) { |
|
|
|
|
app = cview.NewApplication() |
|
|
|
|
|
|
|
|
|
// TODO this breaks highlighting the line
|
|
|
|
|
/* |
|
|
|
|
cview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault |
|
|
|
|
cview.Styles.PrimaryTextColor = tcell.ColorDefault |
|
|
|
|
cview.Styles.ScrollBarColor = tcell.ColorDefault |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
inputView = cview.NewInputField() |
|
|
|
|
inputView.SetLabel("") |
|
|
|
|
inputView.SetFieldWidth(0) |
|
|
|
@ -85,78 +90,41 @@ func initTUI() (*cview.Application, error) {
@@ -85,78 +90,41 @@ func initTUI() (*cview.Application, error) {
|
|
|
|
|
gmenu.SetInput(text) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
entryList = newOptionsList(nil) |
|
|
|
|
entryList = cview.NewList() |
|
|
|
|
entryList.ShowSecondaryText(false) |
|
|
|
|
entryList.SetHighlightFullLine(true) |
|
|
|
|
|
|
|
|
|
grid := cview.NewGrid() |
|
|
|
|
grid.SetBorders(false) |
|
|
|
|
grid.SetRows(1, -1) |
|
|
|
|
|
|
|
|
|
appDetailsView = cview.NewTextView() |
|
|
|
|
appDetailsView.SetTextAlign(cview.AlignLeft) |
|
|
|
|
appDetailsView.SetWrap(true) |
|
|
|
|
appDetailsView.SetWordWrap(true) |
|
|
|
|
appDetailsView.SetBackgroundColor(tcell.ColorDefault) |
|
|
|
|
appDetailsView.SetTextColor(tcell.ColorDefault) |
|
|
|
|
detailView = cview.NewTextView() |
|
|
|
|
detailView.SetTextAlign(cview.AlignLeft) |
|
|
|
|
detailView.SetWrap(true) |
|
|
|
|
detailView.SetWordWrap(true) |
|
|
|
|
|
|
|
|
|
if config.HideAppDetails { |
|
|
|
|
grid.SetColumns(-1) |
|
|
|
|
grid.AddItem(inputView, 0, 0, 1, 1, 0, 0, true) |
|
|
|
|
grid.AddItem(entryList, 1, 0, 1, 1, 0, 0, false) |
|
|
|
|
} else { |
|
|
|
|
grid.SetColumns(-1, -1) |
|
|
|
|
box := cview.NewBox() |
|
|
|
|
box.SetVisible(false) |
|
|
|
|
|
|
|
|
|
grid.SetColumns(-1, 1, -1) |
|
|
|
|
grid.AddItem(inputView, 0, 0, 1, 2, 0, 0, true) |
|
|
|
|
grid.AddItem(entryList, 1, 0, 1, 1, 0, 0, false) |
|
|
|
|
grid.AddItem(appDetailsView, 1, 1, 1, 1, 0, 0, false) |
|
|
|
|
grid.AddItem(box, 1, 1, 1, 1, 0, 0, false) |
|
|
|
|
grid.AddItem(detailView, 1, 2, 1, 1, 0, 0, false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { |
|
|
|
|
defer app.QueueUpdateDraw(updateEntryInfo) |
|
|
|
|
|
|
|
|
|
if event.Key() == tcell.KeyUp { |
|
|
|
|
if entryList.origin > 0 && entryList.selected == entryList.origin { |
|
|
|
|
entryList.origin-- |
|
|
|
|
} |
|
|
|
|
if entryList.selected > 0 { |
|
|
|
|
entryList.selected-- |
|
|
|
|
} |
|
|
|
|
event = nil |
|
|
|
|
} else if event.Key() == tcell.KeyDown { |
|
|
|
|
if entryList.selected < len(entryList.options)-1 { |
|
|
|
|
entryList.selected++ |
|
|
|
|
if entryList.selected > entryList.origin+entryList.shown-1 { |
|
|
|
|
entryList.origin++ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
event = nil |
|
|
|
|
} else if event.Key() == tcell.KeyPgUp { |
|
|
|
|
if entryList.origin == 0 { |
|
|
|
|
entryList.selected = 0 |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entryList.origin -= entryList.shown - 2 |
|
|
|
|
if entryList.origin < 0 { |
|
|
|
|
entryList.origin = 0 |
|
|
|
|
} |
|
|
|
|
entryList.selected = entryList.origin |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} else if event.Key() == tcell.KeyPgDn { |
|
|
|
|
numEntries := len(gmenu.FilteredEntries) |
|
|
|
|
|
|
|
|
|
if entryList.origin >= numEntries-entryList.shown { |
|
|
|
|
entryList.selected = numEntries - 1 |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entryList.origin += entryList.shown - 2 |
|
|
|
|
if entryList.origin > numEntries-entryList.shown { |
|
|
|
|
entryList.origin = numEntries - entryList.shown |
|
|
|
|
} |
|
|
|
|
entryList.selected = entryList.origin |
|
|
|
|
|
|
|
|
|
if event.Key() == tcell.KeyUp || event.Key() == tcell.KeyDown || event.Key() == tcell.KeyPgUp || event.Key() == tcell.KeyPgDn { |
|
|
|
|
entryList.InputHandler()(event, func(p cview.Primitive) { |
|
|
|
|
app.SetFocus(p) |
|
|
|
|
}) |
|
|
|
|
return nil |
|
|
|
|
} else if event.Key() == tcell.KeyEnter || event.Rune() == '\n' { |
|
|
|
|
runInTerminal := event.Modifiers()&tcell.ModAlt > 0 |
|
|
|
@ -173,8 +141,15 @@ func initTUI() (*cview.Application, error) {
@@ -173,8 +141,15 @@ func initTUI() (*cview.Application, error) {
|
|
|
|
|
|
|
|
|
|
app.SetRoot(grid, true) |
|
|
|
|
|
|
|
|
|
go gmenu.HandleInput(updateEntries) |
|
|
|
|
updateEntries("") |
|
|
|
|
|
|
|
|
|
go gmenu.HandleInput(func(input string) { |
|
|
|
|
gmenu.FilterEntries() |
|
|
|
|
app.QueueUpdateDraw(updateEntryInfo) |
|
|
|
|
}) |
|
|
|
|
gmenu.SetInput("") |
|
|
|
|
|
|
|
|
|
app.SetFocus(entryList) |
|
|
|
|
return app, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|