From b7d2d2a73e4dc5ce01ecde7dceeb51db16dccc18 Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Mon, 27 Jun 2016 08:00:09 +0100 Subject: [PATCH] Print CPU usage without decimal point if >= 100 Also: add --colours shortopt to help/readme, Conform to coding style. --- README.rst | 2 +- common/main.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 08adebd..f499fd9 100644 --- a/README.rst +++ b/README.rst @@ -116,7 +116,7 @@ The full usage:: Available options: -h, --help Prints this help message - --colors + -c, --colors Use tmux colors in output --powerline-right Use powerline symbols throughout the output, DO NOT reset background color at the end, enables --colors diff --git a/common/main.cc b/common/main.cc index 211c4be..6d76f1f 100644 --- a/common/main.cc +++ b/common/main.cc @@ -51,10 +51,17 @@ std::string cpu_string( CPU_MODE cpu_mode, unsigned int cpu_usage_delay, unsigne percentage = cpu_percentage( cpu_usage_delay ); // set multiplier to number of threads ? - if ( cpu_mode == CPU_MODE_THREADS ) { + if ( cpu_mode == CPU_MODE_THREADS ) + { multiplier = get_cpu_count(); } + // if percentage*multiplier >= 100, remove decimal point to keep number short + if ( percentage*multiplier >= 100.0f ) + { + oss.precision( 0 ); + } + if( use_colors ) { unsigned int percent = static_cast( percentage );