|
|
|
|
@@ -26,7 +26,7 @@ import (
|
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type List struct {
|
|
|
|
|
type SimpleList struct {
|
|
|
|
|
id string
|
|
|
|
|
title string
|
|
|
|
|
style tcell.Style
|
|
|
|
|
@@ -50,15 +50,15 @@ type List struct {
|
|
|
|
|
logger func(string, ...any)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ Widget = (*List)(nil)
|
|
|
|
|
var _ Widget = (*SimpleList)(nil)
|
|
|
|
|
|
|
|
|
|
func NewList(id string, style tcell.Style) *List {
|
|
|
|
|
ret := &List{style: style}
|
|
|
|
|
func NewSimpleList(id string, style tcell.Style) *SimpleList {
|
|
|
|
|
ret := &SimpleList{style: style}
|
|
|
|
|
ret.Init(id, style)
|
|
|
|
|
return ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) Init(id string, style tcell.Style) {
|
|
|
|
|
func (w *SimpleList) Init(id string, style tcell.Style) {
|
|
|
|
|
w.id = id
|
|
|
|
|
w.style = style
|
|
|
|
|
w.focusable = true
|
|
|
|
|
@@ -87,14 +87,14 @@ func (w *List) Init(id string, style tcell.Style) {
|
|
|
|
|
w.itemsStyle = make(map[int]tcell.Style)
|
|
|
|
|
w.focusable = true
|
|
|
|
|
}
|
|
|
|
|
func (w *List) Id() string { return w.id }
|
|
|
|
|
func (w *List) HandleResize(ev *tcell.EventResize) {
|
|
|
|
|
func (w *SimpleList) Id() string { return w.id }
|
|
|
|
|
func (w *SimpleList) HandleResize(ev *tcell.EventResize) {
|
|
|
|
|
w.w, w.h = ev.Size()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) SetKeyMap(km KeyMap) { w.keyMap = km }
|
|
|
|
|
func (w *List) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
|
|
|
|
func (w *List) RemoveFromKeyMap(km KeyMap) {
|
|
|
|
|
func (w *SimpleList) SetKeyMap(km KeyMap) { w.keyMap = km }
|
|
|
|
|
func (w *SimpleList) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
|
|
|
|
func (w *SimpleList) RemoveFromKeyMap(km KeyMap) {
|
|
|
|
|
for k := range km.Keys {
|
|
|
|
|
w.keyMap.Remove(k)
|
|
|
|
|
}
|
|
|
|
|
@@ -103,14 +103,14 @@ func (w *List) RemoveFromKeyMap(km KeyMap) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) HandleKey(ev *tcell.EventKey) bool {
|
|
|
|
|
func (w *SimpleList) HandleKey(ev *tcell.EventKey) bool {
|
|
|
|
|
if !w.active || !w.focusable {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return w.keyMap.Handle(ev)
|
|
|
|
|
}
|
|
|
|
|
func (w *List) HandleTime(ev *tcell.EventTime) {}
|
|
|
|
|
func (w *List) Draw(screen tcell.Screen) {
|
|
|
|
|
func (w *SimpleList) HandleTime(ev *tcell.EventTime) {}
|
|
|
|
|
func (w *SimpleList) Draw(screen tcell.Screen) {
|
|
|
|
|
dS := w.style
|
|
|
|
|
if !w.active {
|
|
|
|
|
dS = dS.Dim(true)
|
|
|
|
|
@@ -145,24 +145,24 @@ func (w *List) Draw(screen tcell.Screen) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) Active() bool { return w.active }
|
|
|
|
|
func (w *List) SetActive(a bool) { w.active = a }
|
|
|
|
|
func (w *List) Visible() bool { return w.visible }
|
|
|
|
|
func (w *List) SetVisible(a bool) { w.visible = a }
|
|
|
|
|
func (w *List) SetX(x int) { w.x = x }
|
|
|
|
|
func (w *List) SetY(y int) { w.y = y }
|
|
|
|
|
func (w *List) GetX() int { return w.x }
|
|
|
|
|
func (w *List) GetY() int { return w.y }
|
|
|
|
|
func (w *List) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
|
|
|
|
func (w *List) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
|
|
|
|
func (w *List) SetW(x int) { w.w = x }
|
|
|
|
|
func (w *List) SetH(y int) { w.h = y }
|
|
|
|
|
func (w *List) GetW() int { return w.w }
|
|
|
|
|
func (w *List) GetH() int { return w.y }
|
|
|
|
|
func (w *List) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
|
|
|
|
func (w *List) Focusable() bool { return w.focusable }
|
|
|
|
|
func (w *List) SetFocusable(b bool) { w.focusable = b }
|
|
|
|
|
func (w *List) WantW() int {
|
|
|
|
|
func (w *SimpleList) Active() bool { return w.active }
|
|
|
|
|
func (w *SimpleList) SetActive(a bool) { w.active = a }
|
|
|
|
|
func (w *SimpleList) Visible() bool { return w.visible }
|
|
|
|
|
func (w *SimpleList) SetVisible(a bool) { w.visible = a }
|
|
|
|
|
func (w *SimpleList) SetX(x int) { w.x = x }
|
|
|
|
|
func (w *SimpleList) SetY(y int) { w.y = y }
|
|
|
|
|
func (w *SimpleList) GetX() int { return w.x }
|
|
|
|
|
func (w *SimpleList) GetY() int { return w.y }
|
|
|
|
|
func (w *SimpleList) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
|
|
|
|
func (w *SimpleList) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
|
|
|
|
func (w *SimpleList) SetW(x int) { w.w = x }
|
|
|
|
|
func (w *SimpleList) SetH(y int) { w.h = y }
|
|
|
|
|
func (w *SimpleList) GetW() int { return w.w }
|
|
|
|
|
func (w *SimpleList) GetH() int { return w.y }
|
|
|
|
|
func (w *SimpleList) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
|
|
|
|
func (w *SimpleList) Focusable() bool { return w.focusable }
|
|
|
|
|
func (w *SimpleList) SetFocusable(b bool) { w.focusable = b }
|
|
|
|
|
func (w *SimpleList) WantW() int {
|
|
|
|
|
lng := wh.Longest(w.list)
|
|
|
|
|
if len(w.border) > 0 {
|
|
|
|
|
return lng + 2
|
|
|
|
|
@@ -170,7 +170,7 @@ func (w *List) WantW() int {
|
|
|
|
|
return lng
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) WantH() int {
|
|
|
|
|
func (w *SimpleList) WantH() int {
|
|
|
|
|
lng := len(w.list)
|
|
|
|
|
if len(w.border) > 0 {
|
|
|
|
|
return lng + 2
|
|
|
|
|
@@ -178,7 +178,7 @@ func (w *List) WantH() int {
|
|
|
|
|
return lng
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) MinW() int {
|
|
|
|
|
func (w *SimpleList) MinW() int {
|
|
|
|
|
lng := wh.Longest(w.list)
|
|
|
|
|
if lng > 80 {
|
|
|
|
|
lng = 80
|
|
|
|
|
@@ -186,10 +186,10 @@ func (w *List) MinW() int {
|
|
|
|
|
return 2 + lng
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) MinH() int { return 4 }
|
|
|
|
|
func (w *SimpleList) MinH() int { return 4 }
|
|
|
|
|
|
|
|
|
|
func (w *List) SetCursorWrap(b bool) { w.cursorWrap = b }
|
|
|
|
|
func (w *List) MoveUp() bool {
|
|
|
|
|
func (w *SimpleList) SetCursorWrap(b bool) { w.cursorWrap = b }
|
|
|
|
|
func (w *SimpleList) MoveUp() bool {
|
|
|
|
|
if w.cursor > 0 {
|
|
|
|
|
w.cursor--
|
|
|
|
|
return true
|
|
|
|
|
@@ -200,7 +200,7 @@ func (w *List) MoveUp() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) MoveDown() bool {
|
|
|
|
|
func (w *SimpleList) MoveDown() bool {
|
|
|
|
|
if w.cursor < len(w.list)-1 {
|
|
|
|
|
w.cursor++
|
|
|
|
|
return true
|
|
|
|
|
@@ -210,11 +210,11 @@ func (w *List) MoveDown() bool {
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
func (w *List) SetTitle(ttl string) { w.title = ttl }
|
|
|
|
|
func (w *List) SetList(l []string) { w.list = l }
|
|
|
|
|
func (w *List) Clear() { w.list = []string{} }
|
|
|
|
|
func (w *List) Add(l string) { w.list = append(w.list, l) }
|
|
|
|
|
func (w *List) Remove(l string) {
|
|
|
|
|
func (w *SimpleList) SetTitle(ttl string) { w.title = ttl }
|
|
|
|
|
func (w *SimpleList) SetList(l []string) { w.list = l }
|
|
|
|
|
func (w *SimpleList) Clear() { w.list = []string{} }
|
|
|
|
|
func (w *SimpleList) Add(l string) { w.list = append(w.list, l) }
|
|
|
|
|
func (w *SimpleList) Remove(l string) {
|
|
|
|
|
var idx int
|
|
|
|
|
var found bool
|
|
|
|
|
for idx = range w.list {
|
|
|
|
|
@@ -228,7 +228,7 @@ func (w *List) Remove(l string) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) SetBorder(brd []rune) {
|
|
|
|
|
func (w *SimpleList) SetBorder(brd []rune) {
|
|
|
|
|
if len(brd) == 0 {
|
|
|
|
|
w.border = wh.BRD_SIMPLE
|
|
|
|
|
} else {
|
|
|
|
|
@@ -236,19 +236,19 @@ func (w *List) SetBorder(brd []rune) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *List) SetItemStyle(idx int, s tcell.Style) { w.itemsStyle[idx] = s }
|
|
|
|
|
func (w *List) SetItem(idx int, txt string) {
|
|
|
|
|
func (w *SimpleList) SetItemStyle(idx int, s tcell.Style) { w.itemsStyle[idx] = s }
|
|
|
|
|
func (w *SimpleList) SetItem(idx int, txt string) {
|
|
|
|
|
if len(w.list) < idx {
|
|
|
|
|
w.list[idx] = txt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (w *List) SelectedIndex() int { return w.cursor }
|
|
|
|
|
func (w *List) ClearBorder() { w.border = []rune{} }
|
|
|
|
|
func (w *List) SetOnSelect(s func(int, string) bool) { w.onSelect = s }
|
|
|
|
|
func (w *List) SetVimMode(b bool) { w.vimMode = b }
|
|
|
|
|
func (w *SimpleList) SelectedIndex() int { return w.cursor }
|
|
|
|
|
func (w *SimpleList) ClearBorder() { w.border = []rune{} }
|
|
|
|
|
func (w *SimpleList) SetOnSelect(s func(int, string) bool) { w.onSelect = s }
|
|
|
|
|
func (w *SimpleList) SetVimMode(b bool) { w.vimMode = b }
|
|
|
|
|
|
|
|
|
|
func (w *List) SetLogger(l func(string, ...any)) { w.logger = l }
|
|
|
|
|
func (w *List) Log(txt string, args ...any) {
|
|
|
|
|
func (w *SimpleList) SetLogger(l func(string, ...any)) { w.logger = l }
|
|
|
|
|
func (w *SimpleList) Log(txt string, args ...any) {
|
|
|
|
|
if w.logger != nil {
|
|
|
|
|
w.logger(txt, args...)
|
|
|
|
|
}
|