Auto merge of #1878 - str4d:1875-non-tty-metrics-usability, r=str4d

Improve non-TTY metrics usability

Closes #1875.
This commit is contained in:
zkbot
2016-12-07 23:19:47 +00:00
2 changed files with 43 additions and 19 deletions

View File

@@ -255,17 +255,24 @@ void ThreadShowMetricsScreen()
// Make this thread recognisable as the metrics screen thread
RenameThread("zcash-metrics-screen");
// Clear screen
std::cout << "\e[2J";
// Determine whether we should render a persistent UI or rolling metrics
bool isTTY = isatty(STDOUT_FILENO);
bool isScreen = GetBoolArg("-metricsui", isTTY);
int64_t nRefresh = GetArg("-metricsrefreshtime", isTTY ? 1 : 600);
// Print art
std::cout << METRICS_ART << std::endl;
std::cout << std::endl;
if (isScreen) {
// Clear screen
std::cout << "\e[2J";
// 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;
// Print art
std::cout << METRICS_ART << 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
int64_t nStart = GetTime();
@@ -276,7 +283,7 @@ void ThreadShowMetricsScreen()
int cols = 80;
// Get current window size
if (isatty(STDOUT_FILENO)) {
if (isTTY) {
struct winsize w;
w.ws_col = 0;
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) {
@@ -284,8 +291,10 @@ void ThreadShowMetricsScreen()
}
}
// Erase below current position
std::cout << "\e[J";
if (isScreen) {
// Erase below current position
std::cout << "\e[J";
}
// Miner status
bool mining = GetBoolArg("-gen", false);
@@ -298,13 +307,23 @@ void ThreadShowMetricsScreen()
lines += printMessageBox(cols);
lines += printInitMessage();
// Explain how to exit
std::cout << "[" << _("Press Ctrl+C to exit") << "] [" << _("Set 'showmetrics=0' to hide") << "]" << std::endl;;
if (isScreen) {
// 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();
MilliSleep(1000);
int64_t nWaitEnd = GetTime() + nRefresh;
while (GetTime() < nWaitEnd) {
boost::this_thread::interruption_point();
MilliSleep(200);
}
// Return to the top of the updating section
std::cout << "\e[" << lines << "A";
if (isScreen) {
// Return to the top of the updating section
std::cout << "\e[" << lines << "A";
}
}
}