Auto merge of #1878 - str4d:1875-non-tty-metrics-usability, r=str4d
Improve non-TTY metrics usability Closes #1875.
This commit is contained in:
@@ -450,6 +450,11 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-min", _("Start minimized"));
|
||||
strUsage += HelpMessageOpt("-rootcertificates=<file>", _("Set SSL root certificates for payment request (default: -system-)"));
|
||||
strUsage += HelpMessageOpt("-splash", _("Show splash screen on startup (default: 1)"));
|
||||
} else if (mode == HMM_BITCOIND) {
|
||||
strUsage += HelpMessageGroup(_("Metrics Options (only if -daemon and -printtoconsole are not set):"));
|
||||
strUsage += HelpMessageOpt("-showmetrics", _("Show metrics on stdout (default: 1 if running in a console, 0 otherwise)"));
|
||||
strUsage += HelpMessageOpt("-metricsui", _("Set to 1 for a persistent metrics screen, 0 for sequential metrics output (default: 1 if running in a console, 0 otherwise)"));
|
||||
strUsage += HelpMessageOpt("-metricsrefreshtime", strprintf(_("Number of seconds between metrics refreshes (default: %u if running in a console, %u otherwise)"), 1, 600));
|
||||
}
|
||||
|
||||
return strUsage;
|
||||
@@ -980,7 +985,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
|
||||
|
||||
if ((chainparams.NetworkIDString() != "regtest") &&
|
||||
GetBoolArg("-showmetrics", true) &&
|
||||
GetBoolArg("-showmetrics", isatty(STDOUT_FILENO)) &&
|
||||
!fPrintToConsole && !GetBoolArg("-daemon", false)) {
|
||||
// Start the persistent metrics interface
|
||||
ConnectMetricsScreen();
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user