metrics: Only print IBD progress bar on TTY

Now that it is created from space characters, it is meaningless to print
it to a log file.
This commit is contained in:
Jack Grigg 2020-06-02 14:23:03 +12:00
parent a79337c3ee
commit 12e169d09f
1 changed files with 20 additions and 18 deletions

View File

@ -266,7 +266,7 @@ boost::optional<int64_t> SecondsLeftToNextEpoch(const Consensus::Params& params,
} }
} }
int printStats(bool mining) int printStats(bool isScreen, bool mining)
{ {
// Number of lines that are always displayed // Number of lines that are always displayed
int lines = 5; int lines = 5;
@ -304,24 +304,26 @@ int printStats(bool mining)
int downloadPercent = height * 100 / netheight; int downloadPercent = height * 100 / netheight;
std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl; std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl;
// Draw 50-character progress bar, which will fit into a 79-character line. if (isScreen) {
int blockChars = downloadPercent / 2; // Draw 50-character progress bar, which will fit into a 79-character line.
int headerChars = (nHeaders * 50) / netheight; int blockChars = downloadPercent / 2;
// Start with background colour reversed for "full" bar. int headerChars = (nHeaders * 50) / netheight;
std::cout << " | ["; // Start with background colour reversed for "full" bar.
for (auto i : boost::irange(0, 50)) { std::cout << " | [";
if (i == headerChars) { for (auto i : boost::irange(0, 50)) {
// Switch to normal background colour for "empty" bar. if (i == headerChars) {
std::cout << ""; // Switch to normal background colour for "empty" bar.
} else if (i == blockChars) { std::cout << "";
// Switch to distinct colour for "headers" bar. } else if (i == blockChars) {
std::cout << ""; // Switch to distinct colour for "headers" bar.
std::cout << "";
}
std::cout << " ";
} }
std::cout << " "; // Ensure that colour is reset after the progress bar is printed.
std::cout << "]" << std::endl;
lines++;
} }
// Ensure that colour is reset after the progress bar is printed.
std::cout << "]" << std::endl;
lines++;
} }
} else { } else {
std::cout << " " << _("Block height") << " | " << height << std::endl; std::cout << " " << _("Block height") << " | " << height << std::endl;
@ -604,7 +606,7 @@ void ThreadShowMetricsScreen()
#endif #endif
if (loaded) { if (loaded) {
lines += printStats(mining); lines += printStats(isScreen, mining);
lines += printMiningStatus(mining); lines += printMiningStatus(mining);
} }
lines += printMetrics(cols, mining); lines += printMetrics(cols, mining);