blob: a53be4d91bfbbc947848a6e329f1e24f201bdb33 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package context
import "github.com/jesseduffield/lazygit/pkg/gui/context/traits"
type BasicViewModel[T any] struct {
*traits.ListCursor
getModel func() []T
}
func NewBasicViewModel[T any](getModel func() []T) *BasicViewModel[T] {
self := &BasicViewModel[T]{
getModel: getModel,
}
self.ListCursor = traits.NewListCursor(self)
return self
}
func (self *BasicViewModel[T]) Len() int {
return len(self.getModel())
}
func (self *BasicViewModel[T]) GetSelected() T {
if self.Len() == 0 {
return Zero[T]()
}
return self.getModel()[self.GetSelectedLineIdx()]
}
func Zero[T any]() T {
return *new(T)
}
|