diff options
-rw-r--r-- | glances/outputs/glances_bars.py | 6 | ||||
-rw-r--r-- | glances/outputs/glances_sparklines.py | 20 | ||||
-rw-r--r-- | glances/plugins/glances_quicklook.py | 2 |
3 files changed, 18 insertions, 10 deletions
diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py index d3a7bf03..9d4b916a 100644 --- a/glances/outputs/glances_bars.py +++ b/glances/outputs/glances_bars.py @@ -82,7 +82,7 @@ class Bar(object): def post_char(self): return self.__post_char - def __str__(self): + def get(self): """Return the bars.""" frac, whole = modf(self.size * self.percent / 100.0) ret = curses_bars[8] * int(whole) @@ -93,3 +93,7 @@ class Bar(object): if self.__with_text: ret = '{}{:5.1f}%'.format(ret, self.percent) return ret + + def __str__(self): + """Return the bars.""" + return self.get() diff --git a/glances/outputs/glances_sparklines.py b/glances/outputs/glances_sparklines.py index 33dc1919..d2b5af3b 100644 --- a/glances/outputs/glances_sparklines.py +++ b/glances/outputs/glances_sparklines.py @@ -19,11 +19,15 @@ """Manage sparklines for Glances output.""" +from __future__ import unicode_literals from __future__ import division +import sys from math import modf from glances.logger import logger +from glances.compat import nativestr sparklines_module = True + try: from sparklines import sparklines except ImportError as e: @@ -31,8 +35,8 @@ except ImportError as e: sparklines_module = False try: - '\xe2\x96\x81'.decode('utf-8') -except Exception as e: + '┌┬┐╔╦╗╒╤╕╓╥╖│║─═├┼┤╠╬╣╞╪╡╟╫╢└┴┘╚╩╝╘╧╛╙╨╜'.encode(sys.stdout.encoding) +except UnicodeEncodeError: logger.warning("UTF-8 is mandatory for sparklines ({})".format(e)) sparklines_module = False @@ -84,13 +88,13 @@ class Sparkline(object): def get(self): """Return the sparkline.""" - return sparklines(self.percents)[0].encode('utf8') - - def __str__(self): - """Return the sparkline.""" - ret = self.get() + ret = sparklines(self.percents)[0] if self.__with_text: 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 ret + return nativestr(ret) + + def __str__(self): + """Return the sparkline.""" + return self.get() diff --git a/glances/plugins/glances_quicklook.py b/glances/plugins/glances_quicklook.py index b1daed9e..ead8ac34 100644 --- a/glances/plugins/glances_quicklook.py +++ b/glances/plugins/glances_quicklook.py @@ -185,7 +185,7 @@ class Plugin(GlancesPlugin): ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(data.pre_char, decoration='BOLD')) - ret.append(self.curse_add_line(str(data), self.get_views(key=key, option='decoration'))) + ret.append(self.curse_add_line(data.get(), self.get_views(key=key, option='decoration'))) ret.append(self.curse_add_line(data.post_char, decoration='BOLD')) ret.append(self.curse_add_line(' ')) |