mirror of
https://github.com/ivabus/pop
synced 2024-11-14 04:25:08 +03:00
46 lines
853 B
Go
46 lines
853 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"path/filepath"
|
||
|
|
||
|
"github.com/charmbracelet/bubbles/list"
|
||
|
tea "github.com/charmbracelet/bubbletea"
|
||
|
)
|
||
|
|
||
|
type attachment string
|
||
|
|
||
|
func (a attachment) FilterValue() string {
|
||
|
return string(a)
|
||
|
}
|
||
|
|
||
|
type attachmentDelegate struct {
|
||
|
focused bool
|
||
|
}
|
||
|
|
||
|
func (d attachmentDelegate) Height() int {
|
||
|
return 1
|
||
|
}
|
||
|
|
||
|
func (d attachmentDelegate) Spacing() int {
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
func (d attachmentDelegate) Render(w io.Writer, m list.Model, index int, item list.Item) {
|
||
|
path := filepath.Base(item.(attachment).FilterValue())
|
||
|
style := textStyle
|
||
|
if m.Index() == index && d.focused {
|
||
|
style = activeTextStyle
|
||
|
}
|
||
|
|
||
|
if m.Index() == index {
|
||
|
_, _ = w.Write([]byte(style.Render("• " + path)))
|
||
|
} else {
|
||
|
_, _ = w.Write([]byte(style.Render(" " + path)))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (d attachmentDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd {
|
||
|
return nil
|
||
|
}
|