Skip to content

Commit

Permalink
feat: indicate if package details exceed screen height
Browse files Browse the repository at this point in the history
Indicate (...) that we have more content than
what is currently shown on screen.
If so, allow navigating to the package details pane.
This enabled us to scroll via keyboard as well

Signed-off-by: moson-mo <[email protected]>
  • Loading branch information
moson-mo committed Dec 1, 2023
1 parent 6431ac9 commit 1f68078
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
6 changes: 6 additions & 0 deletions internal/pacseek/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ func (ps *UI) drawPackageInfo(i InfoRecord, width int) {
}
}
}
// check if we got more lines than current screen height
_, _, _, height := ps.tableDetails.GetInnerRect()
ps.tableDetailsMore = false
if r > height-1 {
ps.tableDetailsMore = true
}
ps.tableDetails.ScrollToBeginning()
}

Expand Down
74 changes: 55 additions & 19 deletions internal/pacseek/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ func (ps *UI) createComponents() {
if ps.conf.EnableAutoSuggest {
ps.inputSearch.SetAutocompleteFunc(ps.autoComplete)
}
ps.tableDetails.SetFocusFunc(func() {
if ps.flexRight.GetItem(0) == ps.textPkgbuild {
ps.app.SetFocus(ps.textPkgbuild)
} else {
ps.app.SetFocus(ps.tablePackages)
}
}).
ps.tableDetails.SetEvaluateAllRows(true).
SetFocusFunc(func() {
if ps.flexRight.GetItem(0) == ps.textPkgbuild {
ps.app.SetFocus(ps.textPkgbuild)
} else if !ps.tableDetailsMore {
ps.app.SetFocus(ps.tablePackages)
}
}).
SetBorder(true).
SetTitleAlign(tview.AlignLeft).
SetBorderPadding(1, 1, 1, 1)
SetBorderPadding(1, 0, 1, 1)
ps.displayHelp()
ps.tablePackages.SetSelectable(true, false).
SetFixed(1, 1).
Expand All @@ -75,6 +76,21 @@ func (ps *UI) createComponents() {
SetBorderPadding(1, 1, 1, 1).
SetBorder(true).
SetTitleAlign(tview.AlignLeft)
ps.tableDetails.SetDrawFunc(func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
// draw "more..." for package details exceeding screen limits
_, _, _, innerHeight := ps.tableDetails.GetInnerRect()
offset, _ := ps.tableDetails.GetOffset()
rowCount := ps.tableDetails.GetRowCount()

if rowCount-offset > innerHeight {
for i, char := range "..." {
style := tcell.StyleDefault.Background(ps.conf.Colors().DefaultBackground).
Foreground(tcell.ColorWhite)
screen.SetContent(x+2+i, y+height-2, char, nil, style)
}
}
return ps.tableDetails.GetInnerRect()
})

// layouting
ps.flexRoot.AddItem(ps.flexContainer, 0, 1, true).
Expand Down Expand Up @@ -247,7 +263,7 @@ func (ps *UI) setupKeyBindings() {
// CTRL+N - Show help/instructions
if event.Key() == tcell.KeyCtrlN {
ps.displayHelp()
if ps.flexRight.GetItem(0) == ps.formSettings {
if settingsVisible {
ps.flexRight.Clear()
ps.flexRight.AddItem(ps.tableDetails, 0, 1, false)
}
Expand Down Expand Up @@ -367,16 +383,20 @@ func (ps *UI) setupKeyBindings() {
ps.app.SetFocus(ps.tablePackages)
}
}).SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
itemRight := ps.flexRight.GetItem(0)
// Down
if event.Key() == tcell.KeyDown && !ps.conf.EnableAutoSuggest {
ps.app.SetFocus(ps.tablePackages)
return nil
}
// CTRL+Right
if event.Key() == tcell.KeyRight &&
event.Modifiers() == tcell.ModCtrl &&
ps.flexRight.GetItem(0) == ps.formSettings {
ps.app.SetFocus(ps.formSettings.GetFormItem(0))
event.Modifiers() == tcell.ModCtrl {
if itemRight == ps.formSettings {
ps.app.SetFocus(ps.formSettings.GetFormItem(0))
} else if itemRight == ps.tableDetails && ps.tableDetailsMore {
ps.app.SetFocus(ps.tableDetails)
}
ps.prevComponent = ps.inputSearch
return nil
}
Expand All @@ -387,26 +407,26 @@ func (ps *UI) setupKeyBindings() {
ps.tablePackages.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
// TAB / Up
row, _ := ps.tablePackages.GetSelection()
itemRight := ps.flexRight.GetItem(0)
if event.Key() == tcell.KeyTAB ||
(event.Key() == tcell.KeyUp && row <= 1) ||
(event.Key() == tcell.KeyUp && event.Modifiers() == tcell.ModCtrl) {
if ps.flexRight.GetItem(0) == ps.formSettings && event.Key() == tcell.KeyTAB {
if itemRight == ps.formSettings && event.Key() == tcell.KeyTAB {
ps.app.SetFocus(ps.formSettings.GetFormItem(0))
} else if ps.flexRight.GetItem(0) == ps.textPkgbuild && event.Key() == tcell.KeyTAB {
ps.app.SetFocus(ps.textPkgbuild)
} else if event.Key() == tcell.KeyTAB {
ps.app.SetFocus(itemRight)
} else {
ps.app.SetFocus(ps.inputSearch)
}
return nil
}
// Right
if event.Key() == tcell.KeyRight && ps.flexRight.GetItem(0) == ps.formSettings {
if event.Key() == tcell.KeyRight && itemRight == ps.formSettings {
ps.app.SetFocus(ps.formSettings.GetFormItem(0))
ps.prevComponent = ps.tablePackages
return nil
}
if event.Key() == tcell.KeyRight && ps.flexRight.GetItem(0) == ps.textPkgbuild {
ps.app.SetFocus(ps.textPkgbuild)
} else if event.Key() == tcell.KeyRight {
ps.app.SetFocus(itemRight)
ps.prevComponent = ps.tablePackages
return nil
}
Expand Down Expand Up @@ -448,6 +468,22 @@ func (ps *UI) setupKeyBindings() {

return event
})

// Package details
ps.tableDetails.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
// Left
if event.Key() == tcell.KeyLeft {
ps.app.SetFocus(ps.tablePackages)
return nil
}
// TAB
if event.Key() == tcell.KeyTAB {
ps.app.SetFocus(ps.inputSearch)
return nil
}

return event
})
}

// sets up settings form
Expand Down
2 changes: 2 additions & 0 deletions internal/pacseek/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type UI struct {
isArm bool
flags args.Flags

tableDetailsMore bool

pkgbuildWriter io.Writer
}

Expand Down

0 comments on commit 1f68078

Please sign in to comment.