From 7208bd3df7a005429498ffbe7e35adb09db43e1c Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 11 Aug 2019 11:13:47 +0200 Subject: [PATCH] [Feature Request] Option in config to change character used to display percentage in Quicklook #1511 --- conf/glances.conf | 2 ++ glances/outputs/glances_bars.py | 13 ++++++++----- glances/plugins/glances_plugin.py | 4 ++-- glances/plugins/glances_quicklook.py | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index 1e985bf7..b8a6e961 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -27,6 +27,8 @@ max_processes_display=30 # Set to true to disable a plugin # Note: you can also disable it from the command line (see --disable-plugin) disable=false +# Graphical percentage char used in the terminal user interface (default is |) +percentage_char=| # Define CPU, MEM and SWAP thresholds in % cpu_careful=50 cpu_warning=70 diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py index 9d4b916a..fda2039f 100644 --- a/glances/outputs/glances_bars.py +++ b/glances/outputs/glances_bars.py @@ -23,8 +23,6 @@ from __future__ import division from math import modf -curses_bars = [' ', ' ', ' ', ' ', '|', '|', '|', '|', '|'] - class Bar(object): @@ -40,7 +38,12 @@ class Bar(object): sys.stdout.flush() """ - def __init__(self, size, pre_char='[', post_char=']', empty_char=' ', with_text=True): + def __init__(self, size, + percentage_char='|', empty_char=' ', + pre_char='[', post_char=']', + with_text=True): + # Build curses_bars + self.__curses_bars = [empty_char] * 5 + [percentage_char] * 5 # Bar size self.__size = size # Bar current percent @@ -85,9 +88,9 @@ class Bar(object): def get(self): """Return the bars.""" frac, whole = modf(self.size * self.percent / 100.0) - ret = curses_bars[8] * int(whole) + ret = self.__curses_bars[8] * int(whole) if frac > 0: - ret += curses_bars[int(frac * 8)] + ret += self.__curses_bars[int(frac * 8)] whole += 1 ret += self.__empty_char * int(self.size - whole) if self.__with_text: diff --git a/glances/plugins/glances_plugin.py b/glances/plugins/glances_plugin.py index 482fca63..755a300d 100644 --- a/glances/plugins/glances_plugin.py +++ b/glances/plugins/glances_plugin.py @@ -726,7 +726,7 @@ class GlancesPlugin(object): # Return the action list return log_tag[0].lower() == 'true' - def get_conf_value(self, value, header="", plugin_name=None): + def get_conf_value(self, value, header="", plugin_name=None, default=[]): """Return the configuration (header_) value for the current plugin. ...or the one given by the plugin_name var. @@ -742,7 +742,7 @@ class GlancesPlugin(object): try: return self._limits[plugin_name + '_' + value] except KeyError: - return [] + return default def is_hide(self, value, header=""): """Return True if the value is in the hide configuration list. diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index ebafaf4f..32ec62e8 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -129,7 +129,9 @@ class Plugin(GlancesPlugin): sparkline_tag = data.available if not sparkline_tag: # Fallback to bar if Sparkline module is not installed - data = Bar(max_width) + data = Bar(max_width, + percentage_char=self.get_conf_value('percentage_char', + default=['|'])[0]) # Build the string message if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: -- GitLab