mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
cli: Add progress bar for -getinfo
Co-authored-by: jonatack <jon@atack.com>
This commit is contained in:
parent
5d83e7d714
commit
b851a92c06
1 changed files with 34 additions and 1 deletions
|
@ -884,6 +884,29 @@ static void GetWalletBalances(UniValue& result)
|
||||||
result.pushKV("balances", balances);
|
result.pushKV("balances", balances);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetProgressBar contructs a progress bar with 5% intervals.
|
||||||
|
*
|
||||||
|
* @param[in] progress The proportion of the progress bar to be filled between 0 and 1.
|
||||||
|
* @param[out] progress_bar String representation of the progress bar.
|
||||||
|
*/
|
||||||
|
static void GetProgressBar(double progress, std::string& progress_bar)
|
||||||
|
{
|
||||||
|
if (progress < 0 || progress > 1) return;
|
||||||
|
|
||||||
|
static constexpr double INCREMENT{0.05};
|
||||||
|
static const std::string COMPLETE_BAR{"\u2592"};
|
||||||
|
static const std::string INCOMPLETE_BAR{"\u2591"};
|
||||||
|
|
||||||
|
for (int i = 0; i < progress / INCREMENT; ++i) {
|
||||||
|
progress_bar += COMPLETE_BAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (1 - progress) / INCREMENT; ++i) {
|
||||||
|
progress_bar += INCOMPLETE_BAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParseGetInfoResult takes in -getinfo result in UniValue object and parses it
|
* ParseGetInfoResult takes in -getinfo result in UniValue object and parses it
|
||||||
* into a user friendly UniValue string to be printed on the console.
|
* into a user friendly UniValue string to be printed on the console.
|
||||||
|
@ -926,7 +949,17 @@ static void ParseGetInfoResult(UniValue& result)
|
||||||
std::string result_string = strprintf("%sChain: %s%s\n", BLUE, result["chain"].getValStr(), RESET);
|
std::string result_string = strprintf("%sChain: %s%s\n", BLUE, result["chain"].getValStr(), RESET);
|
||||||
result_string += strprintf("Blocks: %s\n", result["blocks"].getValStr());
|
result_string += strprintf("Blocks: %s\n", result["blocks"].getValStr());
|
||||||
result_string += strprintf("Headers: %s\n", result["headers"].getValStr());
|
result_string += strprintf("Headers: %s\n", result["headers"].getValStr());
|
||||||
result_string += strprintf("Verification progress: %.4f%%\n", result["verificationprogress"].get_real() * 100);
|
|
||||||
|
const double ibd_progress{result["verificationprogress"].get_real()};
|
||||||
|
std::string ibd_progress_bar;
|
||||||
|
// Display the progress bar only if IBD progress is less than 99%
|
||||||
|
if (ibd_progress < 0.99) {
|
||||||
|
GetProgressBar(ibd_progress, ibd_progress_bar);
|
||||||
|
// Add padding between progress bar and IBD progress
|
||||||
|
ibd_progress_bar += " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
result_string += strprintf("Verification progress: %s%.4f%%\n", ibd_progress_bar, ibd_progress * 100);
|
||||||
result_string += strprintf("Difficulty: %s\n\n", result["difficulty"].getValStr());
|
result_string += strprintf("Difficulty: %s\n\n", result["difficulty"].getValStr());
|
||||||
|
|
||||||
result_string += strprintf(
|
result_string += strprintf(
|
||||||
|
|
Loading…
Add table
Reference in a new issue