diff options
Diffstat (limited to 'glances/outputs/glances_sparklines.py')
-rw-r--r-- | glances/outputs/glances_sparklines.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/glances/outputs/glances_sparklines.py b/glances/outputs/glances_sparklines.py index 6d6d2b86..3a5dabf8 100644 --- a/glances/outputs/glances_sparklines.py +++ b/glances/outputs/glances_sparklines.py @@ -34,7 +34,10 @@ class Sparkline(object): """Manage sparklines (see https://pypi.org/project/sparklines/).""" - def __init__(self, size, pre_char='[', post_char=']', empty_char=' ', with_text=True): + def __init__(self, size, + pre_char='[', post_char=']', + unit_char='%', + display_value=True): # If the sparklines python module available ? self.__available = sparklines_module # Sparkline size @@ -44,8 +47,9 @@ class Sparkline(object): # Char used for the decoration self.__pre_char = pre_char self.__post_char = post_char - self.__empty_char = empty_char - self.__with_text = with_text + self.__unit_char = unit_char + # Value should be displayed ? + self.__display_value = display_value @property def available(self): @@ -56,7 +60,7 @@ class Sparkline(object): # Return the sparkline size, with or without decoration if with_decoration: return self.__size - if self.__with_text: + if self.__display_value: return self.__size - 6 @property @@ -75,14 +79,19 @@ class Sparkline(object): def post_char(self): return self.__post_char - def get(self): + def get(self, overwrite=''): """Return the sparkline.""" ret = sparklines(self.percents, minimum=0, maximum=100)[0] - if self.__with_text: + if self.__display_value: percents_without_none = [x for x in self.percents if x is not None] if len(percents_without_none) > 0: - ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1]) - return nativestr(ret) + ret = '{}{:5.1f}{}'.format(ret, + percents_without_none[-1], + self.__unit_char) + ret = nativestr(ret) + if overwrite and len(overwrite) < len(ret) - 6: + ret = overwrite + ret[len(overwrite):] + return ret def __str__(self): """Return the sparkline.""" |