From 3224c84fb1a90b8b85c0988e6fb214b8b4fa36a8 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 14 Jan 2021 16:39:39 +0800 Subject: [PATCH 1/2] add color for token amount --- cmd/lotus-storage-miner/info.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index ed74da96bf1..451ea0582c9 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -218,11 +218,11 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, availBalance) - fmt.Printf("Miner Balance: %s\n", color.YellowString("%s", types.FIL(mact.Balance).Short())) - fmt.Printf(" PreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits).Short()) - fmt.Printf(" Pledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement).Short()) - fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short()) - color.Green(" Available: %s", types.FIL(availBalance).Short()) + colorTokenAmount("Miner Balance: %s\n", mact.Balance) + colorTokenAmount(" PreCommit: %s\n", lockedFunds.PreCommitDeposits) + colorTokenAmount(" Pledge: %s\n", lockedFunds.InitialPledgeRequirement) + colorTokenAmount(" Vesting: %s\n", lockedFunds.VestingFunds) + colorTokenAmount(" Available: %s\n", availBalance) mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK) if err != nil { @@ -230,16 +230,16 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, big.Sub(mb.Escrow, mb.Locked)) - fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).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("Market Balance: %s\n", mb.Escrow) + colorTokenAmount(" Locked: %s\n", mb.Locked) + colorTokenAmount(" Available: %s\n", big.Sub(mb.Escrow, mb.Locked)) wb, err := api.WalletBalance(ctx, mi.Worker) if err != nil { return xerrors.Errorf("getting worker balance: %w", err) } spendable = big.Add(spendable, wb) - color.Cyan("Worker Balance: %s", types.FIL(wb).Short()) + colorTokenAmount("Worker Balance: %s\n", wb) if len(mi.ControlAddresses) > 0 { cbsum := big.Zero() for _, ca := range mi.ControlAddresses { @@ -251,9 +251,9 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, cbsum) - fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short()) + colorTokenAmount(" Control: %s\n", cbsum) } - fmt.Printf("Total Spendable: %s\n", color.YellowString(types.FIL(spendable).Short())) + colorTokenAmount("Total Spendable: %s\n", spendable) fmt.Println() @@ -355,3 +355,13 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) error { return nil } + +func colorTokenAmount(format string, amount abi.TokenAmount) { + if amount.GreaterThan(big.Zero()) { + fmt.Printf(format, color.GreenString("%s", types.FIL(amount).Short())) + } else if amount.Equals(big.Zero()) { + fmt.Printf(format, color.YellowString("%s", types.FIL(amount).Short())) + } else { + fmt.Printf(format, color.RedString("%s", types.FIL(amount).Short())) + } +} From 7747bcd8591e392277907cc16e9214644cb25b9f Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 15 Jan 2021 11:48:07 +0800 Subject: [PATCH 2/2] remove some colorTokenAmount --- cmd/lotus-storage-miner/info.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 451ea0582c9..499a24bf16f 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -218,10 +218,10 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, availBalance) - colorTokenAmount("Miner Balance: %s\n", mact.Balance) - colorTokenAmount(" PreCommit: %s\n", lockedFunds.PreCommitDeposits) - colorTokenAmount(" Pledge: %s\n", lockedFunds.InitialPledgeRequirement) - colorTokenAmount(" Vesting: %s\n", lockedFunds.VestingFunds) + fmt.Printf("Miner Balance: %s\n", color.YellowString("%s", types.FIL(mact.Balance).Short())) + fmt.Printf(" PreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits).Short()) + fmt.Printf(" Pledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement).Short()) + fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short()) colorTokenAmount(" Available: %s\n", availBalance) mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK) @@ -230,8 +230,8 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, big.Sub(mb.Escrow, mb.Locked)) - colorTokenAmount("Market Balance: %s\n", mb.Escrow) - colorTokenAmount(" Locked: %s\n", mb.Locked) + fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).Short()) + fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short()) colorTokenAmount(" Available: %s\n", big.Sub(mb.Escrow, mb.Locked)) wb, err := api.WalletBalance(ctx, mi.Worker) @@ -239,7 +239,7 @@ func infoCmdAct(cctx *cli.Context) error { return xerrors.Errorf("getting worker balance: %w", err) } spendable = big.Add(spendable, wb) - colorTokenAmount("Worker Balance: %s\n", wb) + color.Cyan("Worker Balance: %s", types.FIL(wb).Short()) if len(mi.ControlAddresses) > 0 { cbsum := big.Zero() for _, ca := range mi.ControlAddresses { @@ -251,7 +251,7 @@ func infoCmdAct(cctx *cli.Context) error { } spendable = big.Add(spendable, cbsum) - colorTokenAmount(" Control: %s\n", cbsum) + fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short()) } colorTokenAmount("Total Spendable: %s\n", spendable) @@ -358,10 +358,10 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) error { func colorTokenAmount(format string, amount abi.TokenAmount) { if amount.GreaterThan(big.Zero()) { - fmt.Printf(format, color.GreenString("%s", types.FIL(amount).Short())) + color.Green(format, types.FIL(amount).Short()) } else if amount.Equals(big.Zero()) { - fmt.Printf(format, color.YellowString("%s", types.FIL(amount).Short())) + color.Yellow(format, types.FIL(amount).Short()) } else { - fmt.Printf(format, color.RedString("%s", types.FIL(amount).Short())) + color.Red(format, types.FIL(amount).Short()) } }