apps/blobs/tui_items.go 1.4 K raw
1
package main
2
3
import (
4
	"fmt"
5
6
	"charm.land/bubbles/v2/list"
7
	sharedtui "github.com/stevedylandev/andromeda/pkg/tui"
8
)
9
10
var listIDStyle = sharedtui.ListIDStyle
11
12
type bucketItem struct{ b BucketInfo }
13
14
func (i bucketItem) Title() string {
15
	if i.b.CreationDate != "" {
16
		return i.b.Name + listIDStyle.Render(" "+i.b.CreationDate)
17
	}
18
	return i.b.Name
19
}
20
func (i bucketItem) Description() string { return "" }
21
func (i bucketItem) FilterValue() string { return i.b.Name }
22
23
type folderItemTUI struct {
24
	prefix string // full S3 prefix (ends in /)
25
	name   string
26
}
27
28
func (i folderItemTUI) Title() string       { return "📁 " + i.name + "/" }
29
func (i folderItemTUI) Description() string { return "" }
30
func (i folderItemTUI) FilterValue() string { return i.name }
31
32
type fileItemTUI struct {
33
	obj ObjectInfo
34
}
35
36
func (i fileItemTUI) Title() string {
37
	return i.obj.Name + listIDStyle.Render(fmt.Sprintf("  %s  %s", humanSize(i.obj.Size), i.obj.LastModified))
38
}
39
func (i fileItemTUI) Description() string { return "" }
40
func (i fileItemTUI) FilterValue() string { return i.obj.Name }
41
42
func newList(title string, items []list.Item) list.Model {
43
	l := list.New(items, sharedtui.ANSIListDelegate(), 0, 0)
44
	l.Title = title
45
	l.Styles = sharedtui.ANSIListStyles()
46
	l.SetShowStatusBar(false)
47
	l.SetShowPagination(false)
48
	l.SetShowHelp(false)
49
	l.SetFilteringEnabled(true)
50
	l.DisableQuitKeybindings()
51
	return l
52
}