Skip to content

Commit d2728b4

Browse files
committed
Add colored output to values
1 parent cdc38ce commit d2728b4

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pkg/serra/add.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ func addCards(cards []string, unique bool, count int64) error {
134134

135135
if len(co) >= 1 {
136136
c := co[0]
137+
outputColor := coloredValue(c.getValue(foil))
137138

138139
if unique {
139-
l.Warnf("%dx \"%s\" (%s, %.2f%s) not added, because it already exists", count, c.Name, c.Rarity, c.getValue(foil), getCurrency())
140+
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)
140141
continue
141142
}
142143

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

168170
// Give feedback of successfully added card
169171
if foil {
170-
l.Infof("%dx \"%s\" (%s, %.2f%s, foil) added", total, c.Name, c.Rarity, c.getValue(foil), getCurrency())
172+
l.Infof("%dx \"%s\" (%s, %s%.2f%s%s, foil) added", total, c.Name, c.Rarity, outputColor, c.getValue(foil), getCurrency(), Reset)
171173
} else {
172-
l.Infof("%dx \"%s\" (%s, %.2f%s) added", total, c.Name, c.Rarity, c.getValue(foil), getCurrency())
174+
l.Infof("%dx \"%s\" (%s, %s%.2f%s%s) added", total, c.Name, c.Rarity, outputColor, c.getValue(foil), getCurrency(), Reset)
173175
}
174176
}
175177
}

pkg/serra/helpers.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,20 @@ func getFloat64(unknown interface{}) (float64, error) {
254254
return math.NaN(), errors.New("non-numeric type could not be converted to float")
255255
}
256256
}
257+
258+
func coloredValue(value float64) string {
259+
260+
outputColor := Reset
261+
262+
if value > 1 {
263+
outputColor = Green
264+
}
265+
if value > 5 {
266+
outputColor = Yellow
267+
}
268+
if value > 10 {
269+
outputColor = Red
270+
}
271+
272+
return outputColor
273+
}

0 commit comments

Comments
 (0)