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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package pikdex
import (
"git.sr.ht/~ewy/pik/describe"
"git.sr.ht/~ewy/pik/model"
"github.com/charmbracelet/lipgloss"
"strings"
)
type MetaSetter func(s *model.SourceData, content string)
type MetaFile struct {
MetaSetter
Description string
}
var MetaFiles = map[string]*MetaFile{
".want": {MetaSetter: func(s *model.SourceData, content string) {
s.Wants = append(s.Wants, contentLines(content)...)
}, Description: "want[s] adds external sources to your pik state. Currently only local paths are supported, one per line. For example, including '../web' will ensure that folder will be included and callable in the pik state without having to provide the --all flag."},
".wants": {MetaSetter: func(s *model.SourceData, content string) {
s.Wants = append(s.Wants, contentLines(content)...)
}},
".include": {MetaSetter: func(s *model.SourceData, content string) {
s.Includes = append(s.Includes, contentLines(content)...)
}, Description: "include[s] adds items from external sources to this pik source. For example, adding '../shared' will add all targets from there to this source. Triggers from the included source will work, and all targets will be ran as if they were part of the including source."},
".includes": {MetaSetter: func(s *model.SourceData, content string) {
s.Includes = append(s.Includes, contentLines(content)...)
}},
".alias": {MetaSetter: func(s *model.SourceData, content string) {
s.Aliases = contentLines(content)
}, Description: "alias can contain multiple lines with alternate names for this source. The first non-comment line will be used as the display name. You can use this for, for example, abbreviations."},
".icon": {MetaSetter: func(s *model.SourceData, content string) {
lines := contentLines(content)
if len(lines) == 0 {
return
}
icon := string([]rune(lines[0])[:2])
desiredWidth := lipgloss.Width(icon)
diff := desiredWidth - len([]rune(icon))
icon += strings.Repeat(" ", diff)
s.Icon = icon
}, Description: "icon can contain unicode symbols representing your source. It will be used in the TUI. It will be cropped to maximum two symbols and padded if shorter."},
}
func contentLines(input string) []string {
result := make([]string, 0, len(input))
nextLine:
for _, l := range strings.Split(input, "\n") {
l = strings.TrimSpace(l)
if l == "" {
continue nextLine
}
for _, c := range describe.CommentPrefixes {
if strings.HasPrefix(l, c) {
continue nextLine
}
}
result = append(result, l)
}
return result
}
|