Add -metricsui flag to toggle between persistent screen and rolling metrics

Defaults to true if stdout is a TTY, else false.
This commit is contained in:
Jack Grigg 2016-11-18 16:17:09 +13:00
parent 26fb4db53b
commit 3c02477360
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with 29 additions and 15 deletions

View File

@ -248,17 +248,22 @@ void ThreadShowMetricsScreen()
// Make this thread recognisable as the metrics screen thread // Make this thread recognisable as the metrics screen thread
RenameThread("zcash-metrics-screen"); RenameThread("zcash-metrics-screen");
// Clear screen // Determine whether we should render a persistent UI or rolling metrics
std::cout << "\e[2J"; bool isScreen = GetBoolArg("-metricsui", isatty(STDOUT_FILENO));
// Print art if (isScreen) {
std::cout << METRICS_ART << std::endl; // Clear screen
std::cout << std::endl; std::cout << "\e[2J";
// Thank you text // Print art
std::cout << _("Thank you for running a Zcash node!") << std::endl; std::cout << METRICS_ART << std::endl;
std::cout << _("You're helping to strengthen the network and contributing to a social good :)") << std::endl; std::cout << std::endl;
std::cout << std::endl;
// Thank you text
std::cout << _("Thank you for running a Zcash node!") << std::endl;
std::cout << _("You're helping to strengthen the network and contributing to a social good :)") << std::endl;
std::cout << std::endl;
}
// Count uptime // Count uptime
int64_t nStart = GetTime(); int64_t nStart = GetTime();
@ -277,8 +282,10 @@ void ThreadShowMetricsScreen()
} }
} }
// Erase below current position if (isScreen) {
std::cout << "\e[J"; // Erase below current position
std::cout << "\e[J";
}
// Miner status // Miner status
bool mining = GetBoolArg("-gen", false); bool mining = GetBoolArg("-gen", false);
@ -291,13 +298,20 @@ void ThreadShowMetricsScreen()
lines += printMessageBox(cols); lines += printMessageBox(cols);
lines += printInitMessage(); lines += printInitMessage();
// Explain how to exit if (isScreen) {
std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl;; // Explain how to exit
std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl;
} else {
// Print delineator
std::cout << "----------------" << std::endl;
}
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
MilliSleep(1000); MilliSleep(1000);
// Return to the top of the updating section if (isScreen) {
std::cout << "\e[" << lines << "A"; // Return to the top of the updating section
std::cout << "\e[" << lines << "A";
}
} }
} }