create list panel struct
parent
cb38e48add
commit
dcce4c67ec
@ -0,0 +1,45 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||
)
|
||||
|
||||
type ListPanel[T comparable] struct {
|
||||
toColumns func(T) []string
|
||||
|
||||
selectedIdx int
|
||||
list FilteredList[T]
|
||||
view *gocui.View
|
||||
}
|
||||
|
||||
func (self *ListPanel[T]) setSelectedLineIdx(value int) {
|
||||
clampedValue := -1
|
||||
if self.list.Len() > 0 {
|
||||
clampedValue = utils.Clamp(value, 0, self.list.Len()-1)
|
||||
}
|
||||
|
||||
self.selectedIdx = clampedValue
|
||||
}
|
||||
|
||||
// moves the cursor up or down by the given amount (up for negative values)
|
||||
func (self *ListPanel[T]) moveSelectedLine(delta int) {
|
||||
self.setSelectedLineIdx(self.selectedIdx + delta)
|
||||
}
|
||||
|
||||
func (self *ListPanel[T]) SelectNextLine() {
|
||||
self.moveSelectedLine(1)
|
||||
}
|
||||
|
||||
func (self *ListPanel[T]) SelectPrevLine() {
|
||||
self.moveSelectedLine(-1)
|
||||
}
|
||||
|
||||
// list panel at the side of the screen that renders content to the main panel
|
||||
type SideListPanel[T comparable] struct {
|
||||
contextKeyPrefix string
|
||||
|
||||
ListPanel[T]
|
||||
|
||||
contextIdx int
|
||||
}
|
Loading…
Reference in New Issue