Add colored output to values
This commit is contained in:
parent
cdc38ce2a0
commit
d2728b455b
@ -134,9 +134,10 @@ func addCards(cards []string, unique bool, count int64) error {
|
|||||||
|
|
||||||
if len(co) >= 1 {
|
if len(co) >= 1 {
|
||||||
c := co[0]
|
c := co[0]
|
||||||
|
outputColor := coloredValue(c.getValue(foil))
|
||||||
|
|
||||||
if unique {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +146,7 @@ func addCards(cards []string, unique bool, count int64) error {
|
|||||||
} else {
|
} else {
|
||||||
// Fetch card from scryfall
|
// Fetch card from scryfall
|
||||||
c, err := fetchCard(setName, collectorNumber)
|
c, err := fetchCard(setName, collectorNumber)
|
||||||
|
outputColor := coloredValue(c.getValue(foil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Warn(err)
|
l.Warn(err)
|
||||||
continue
|
continue
|
||||||
@ -167,9 +169,9 @@ func addCards(cards []string, unique bool, count int64) error {
|
|||||||
|
|
||||||
// Give feedback of successfully added card
|
// Give feedback of successfully added card
|
||||||
if foil {
|
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 {
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -254,3 +254,20 @@ func getFloat64(unknown interface{}) (float64, error) {
|
|||||||
return math.NaN(), errors.New("non-numeric type could not be converted to float")
|
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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user