mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-02 00:38:15 +01:00
Merge bitcoin/bitcoin#22547: cli: Add progress bar for -getinfo
b851a92c06cli: Add progress bar for -getinfo (klementtan) Pull request description: Add a progress bar for the `Verification progress` attribute in `-getinfo` when verification progress `< 99%`.  **Motivation**: * Improve user-friendliness of `-getinfo` * Can be useful with `watch -n 1 bitcoin-cli -getinfo`(suggested by theStack [below](https://github.com/bitcoin/bitcoin/pull/22547#issuecomment-887488172)) * The progress bar is only display when are still syncing to tip(verification progress `< 99%`) **Reviewing** If your verification progress is `> 99%` you can restart the verification progress with ```shell $ ./src/bitcoind -reindex $./src/bitcoin-cli -getinfo ``` ACKs for top commit: prayank23: reACKb851a92c06theStack: re-ACKb851a92c06🍹 Zero-1729: re-tACKb851a92c06(re-tested, works as expected 🍾) jonatack: ACKb851a92c06lsilva01: Tested ACKb851a92c06on mainnet and signet on Ubuntu 20.04. Tree-SHA512: 2046d812e3c4623c6cc3ed4c24f2daaa92ba12cd181fa21626b782743890c2373be3175cff1441a7ba37295b6d5818368deea90d483959875c22f7ad9b601a20
This commit is contained in:
@@ -884,6 +884,29 @@ static void GetWalletBalances(UniValue& result)
|
||||
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
|
||||
* 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);
|
||||
result_string += strprintf("Blocks: %s\n", result["blocks"].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(
|
||||
|
||||
Reference in New Issue
Block a user