Skip to content

Commit

Permalink
Add colored output to values
Browse files Browse the repository at this point in the history
noqqe committed Dec 10, 2024
1 parent cdc38ce commit d2728b4
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/serra/add.go
Original file line number Diff line number Diff line change
@@ -134,9 +134,10 @@ func addCards(cards []string, unique bool, count int64) error {

if len(co) >= 1 {
c := co[0]
outputColor := coloredValue(c.getValue(foil))

if unique {
l.Warnf("%dx \"%s\" (%s, %.2f%s) not added, because it already exists", count, c.Name, c.Rarity, c.getValue(foil), getCurrency())
l.Warnf("%dx \"%s\" (%s, %s%.2f%s%s) not added, because it already exists", count, c.Name, c.Rarity, outputColor, c.getValue(foil), getCurrency(), Reset)
continue
}

@@ -145,6 +146,7 @@ func addCards(cards []string, unique bool, count int64) error {
} else {
// Fetch card from scryfall
c, err := fetchCard(setName, collectorNumber)
outputColor := coloredValue(c.getValue(foil))
if err != nil {
l.Warn(err)
continue
@@ -167,9 +169,9 @@ func addCards(cards []string, unique bool, count int64) error {

// Give feedback of successfully added card
if foil {
l.Infof("%dx \"%s\" (%s, %.2f%s, foil) added", total, c.Name, c.Rarity, c.getValue(foil), getCurrency())
l.Infof("%dx \"%s\" (%s, %s%.2f%s%s, foil) added", total, c.Name, c.Rarity, outputColor, c.getValue(foil), getCurrency(), Reset)
} else {
l.Infof("%dx \"%s\" (%s, %.2f%s) added", total, c.Name, c.Rarity, c.getValue(foil), getCurrency())
l.Infof("%dx \"%s\" (%s, %s%.2f%s%s) added", total, c.Name, c.Rarity, outputColor, c.getValue(foil), getCurrency(), Reset)
}
}
}
17 changes: 17 additions & 0 deletions pkg/serra/helpers.go
Original file line number Diff line number Diff line change
@@ -254,3 +254,20 @@ func getFloat64(unknown interface{}) (float64, error) {
return math.NaN(), errors.New("non-numeric type could not be converted to float")
}
}

func coloredValue(value float64) string {

outputColor := Reset

if value > 1 {
outputColor = Green
}
if value > 5 {
outputColor = Yellow
}
if value > 10 {
outputColor = Red
}

return outputColor
}

0 comments on commit d2728b4

Please sign in to comment.