events.go 586 B

12345678910111213141516171819202122232425262728293031323334
  1. package picker
  2. import (
  3. "github.com/ayn2op/tview"
  4. "github.com/gdamore/tcell/v3"
  5. )
  6. type SelectedEvent struct {
  7. tcell.EventTime
  8. Item
  9. }
  10. func newSelectedEvent(item Item) *SelectedEvent {
  11. return &SelectedEvent{Item: item}
  12. }
  13. func (p *Picker) _select() tview.Command {
  14. index := p.list.Cursor()
  15. if index >= 0 && index < len(p.filtered) {
  16. item := p.filtered[index]
  17. return func() tcell.Event {
  18. return newSelectedEvent(item)
  19. }
  20. }
  21. return nil
  22. }
  23. type CancelEvent struct{ tcell.EventTime }
  24. func cancel() tview.Command {
  25. return func() tcell.Event {
  26. return &CancelEvent{}
  27. }
  28. }