forked from charmbracelet/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattachments.go
45 lines (35 loc) · 851 Bytes
/
attachments.go
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
35
36
37
38
39
40
41
42
43
44
45
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(_ tea.Msg, _ *list.Model) tea.Cmd {
return nil
}