* ParseGetInfoResult takes in -getinfo result in UniValue object and parses it * into a user friendly UniValue string to be printed on the console. * @param[out] result Reference to UniValue result containing the -getinfo output. */
| 947 | * @param[out] result Reference to UniValue result containing the -getinfo output. |
| 948 | */ |
| 949 | static void ParseGetInfoResult(UniValue& result) |
| 950 | { |
| 951 | if (!find_value(result, "error").isNull()) return; |
| 952 | |
| 953 | std::string RESET, GREEN, BLUE, YELLOW, MAGENTA, CYAN; |
| 954 | bool should_colorize = false; |
| 955 | |
| 956 | #ifndef WIN32 |
| 957 | if (isatty(fileno(stdout))) { |
| 958 | // By default, only print colored text if OS is not WIN32 and stdout is connected to a terminal. |
| 959 | should_colorize = true; |
| 960 | } |
| 961 | #endif |
| 962 | |
| 963 | if (gArgs.IsArgSet("-color")) { |
| 964 | const std::string color{gArgs.GetArg("-color", DEFAULT_COLOR_SETTING)}; |
| 965 | if (color == "always") { |
| 966 | should_colorize = true; |
| 967 | } else if (color == "never") { |
| 968 | should_colorize = false; |
| 969 | } else if (color != "auto") { |
| 970 | throw std::runtime_error("Invalid value for -color option. Valid values: always, auto, never."); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | if (should_colorize) { |
| 975 | RESET = "\x1B[0m"; |
| 976 | GREEN = "\x1B[32m"; |
| 977 | BLUE = "\x1B[34m"; |
| 978 | YELLOW = "\x1B[33m"; |
| 979 | MAGENTA = "\x1B[35m"; |
| 980 | CYAN = "\x1B[36m"; |
| 981 | } |
| 982 | |
| 983 | std::string result_string = strprintf("%sChain: %s%s\n", BLUE, result["chain"].getValStr(), RESET); |
| 984 | result_string += strprintf("Blocks: %s\n", result["blocks"].getValStr()); |
| 985 | result_string += strprintf("Headers: %s\n", result["headers"].getValStr()); |
| 986 | |
| 987 | const double ibd_progress{result["verificationprogress"].get_real()}; |
| 988 | std::string ibd_progress_bar; |
| 989 | // Display the progress bar only if IBD progress is less than 99% |
| 990 | if (ibd_progress < 0.99) { |
| 991 | GetProgressBar(ibd_progress, ibd_progress_bar); |
| 992 | // Add padding between progress bar and IBD progress |
| 993 | ibd_progress_bar += " "; |
| 994 | } |
| 995 | |
| 996 | result_string += strprintf("Verification progress: %s%.4f%%\n", ibd_progress_bar, ibd_progress * 100); |
| 997 | result_string += strprintf("Difficulty: %s\n\n", result["difficulty"].getValStr()); |
| 998 | |
| 999 | result_string += strprintf( |
| 1000 | "%sNetwork: in %s, out %s, total %s%s\n", |
| 1001 | GREEN, |
| 1002 | result["connections"]["in"].getValStr(), |
| 1003 | result["connections"]["out"].getValStr(), |
| 1004 | result["connections"]["total"].getValStr(), |
| 1005 | RESET); |
| 1006 | result_string += strprintf("Version: %s\n", result["version"].getValStr()); |
no test coverage detected