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
int lines = 5;
@ -304,24 +304,26 @@ int printStats(bool mining)
int downloadPercent = height * 100 / netheight;
std::cout << " " << _("Downloading blocks") << " | " << height << " (" << nHeaders << " " << _("headers") << ") / ~" << netheight << " (" << downloadPercent << "%)" << std::endl;
// Draw 50-character progress bar, which will fit into a 79-character line.
int blockChars = downloadPercent / 2;
int headerChars = (nHeaders * 50) / netheight;
// Start with background colour reversed for "full" bar.
std::cout << " | [";
for (auto i : boost::irange(0, 50)) {
if (i == headerChars) {
// Switch to normal background colour for "empty" bar.
std::cout << "";
} else if (i == blockChars) {
// Switch to distinct colour for "headers" bar.
std::cout << "";
if (isScreen) {
// Draw 50-character progress bar, which will fit into a 79-character line.
int blockChars = downloadPercent / 2;
int headerChars = (nHeaders * 50) / netheight;
// Start with background colour reversed for "full" bar.
std::cout << " | [";
for (auto i : boost::irange(0, 50)) {
if (i == headerChars) {
// Switch to normal background colour for "empty" bar.
std::cout << "";
} else if (i == blockChars) {
// 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 {
std::cout << " " << _("Block height") << " | " << height << std::endl;
@ -604,7 +606,7 @@ void ThreadShowMetricsScreen()
#endif
if (loaded) {
lines += printStats(mining);
lines += printStats(isScreen, mining);
lines += printMiningStatus(mining);
}
lines += printMetrics(cols, mining);