Skip to content

Commit

Permalink
Add a limit to tags (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGroundZero authored Feb 5, 2025
1 parent 49506ed commit 41cb600
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ func generateTCard(streams IOStreams, contentPath, outPath string, tpl image.Ima
}

var tags []string
for _, t := range fm.Tags {
lim := len(fm.Tags)
if l := cnf.Tags.Limit; l > 0 && l <= lim {
lim = l
}

for _, t := range fm.Tags[:lim] {
tags = append(tags, strings.Title(t))
}

Expand Down
1 change: 1 addition & 0 deletions example/default.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ info:
timeFormat: "Jan 2"
tags:
enabled: true
limit: 0
start:
px: 1025
py: 451
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type BoxTextsOption struct {
BoxSpacing *int `json:"boxSpacing,omitempty"`
BoxAlign box.Align `json:"boxAlign,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Limit int `json:"limit,omitempty"`
}

type Point struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var defaultCnf = DrawingConfig{
},
Tags: &BoxTextsOption{
Enabled: ptrBool(true),
Limit: 0,
TextOption: TextOption{
Start: &Point{X: 1025, Y: 451},
FgHexColor: "#FFFFFF",
Expand Down Expand Up @@ -102,6 +103,9 @@ func defaultTags(bto *BoxTextsOption) {
if bto.Enabled == nil {
bto.Enabled = defaultCnf.Tags.Enabled
}
if bto.Limit < 0 {
bto.Limit = defaultCnf.Tags.Limit
}

setArgsAsDefaultTextOption(&bto.TextOption, &defaultCnf.Tags.TextOption)

Expand Down

0 comments on commit 41cb600

Please sign in to comment.