Merge pull request #5352 from filcloud/color-amount

add color for token amount
This commit is contained in:
Łukasz Magiera 2021-01-19 11:47:22 +01:00 committed by GitHub
commit 388c53e637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -222,7 +222,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Printf(" PreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits).Short()) fmt.Printf(" PreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits).Short())
fmt.Printf(" Pledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement).Short()) fmt.Printf(" Pledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement).Short())
fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short()) fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short())
color.Green(" Available: %s", types.FIL(availBalance).Short()) colorTokenAmount(" Available: %s\n", availBalance)
mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK) mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK)
if err != nil { if err != nil {
@ -232,7 +232,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).Short()) fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).Short())
fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short()) fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short())
color.Green(" Available: %s\n", types.FIL(big.Sub(mb.Escrow, mb.Locked)).Short()) colorTokenAmount(" Available: %s\n", big.Sub(mb.Escrow, mb.Locked))
wb, err := api.WalletBalance(ctx, mi.Worker) wb, err := api.WalletBalance(ctx, mi.Worker)
if err != nil { if err != nil {
@ -253,7 +253,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short()) fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short())
} }
fmt.Printf("Total Spendable: %s\n", color.YellowString(types.FIL(spendable).Short())) colorTokenAmount("Total Spendable: %s\n", spendable)
fmt.Println() fmt.Println()
@ -359,3 +359,13 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
return nil return nil
} }
func colorTokenAmount(format string, amount abi.TokenAmount) {
if amount.GreaterThan(big.Zero()) {
color.Green(format, types.FIL(amount).Short())
} else if amount.Equals(big.Zero()) {
color.Yellow(format, types.FIL(amount).Short())
} else {
color.Red(format, types.FIL(amount).Short())
}
}