summaryrefslogtreecommitdiffstats
path: root/glances/outputs/glances_bars.py
diff options
context:
space:
mode:
authorNicolargo <nicolas@nicolargo.com>2015-05-05 11:42:12 +0200
committerNicolargo <nicolas@nicolargo.com>2015-05-05 11:42:12 +0200
commit9798fb41ca87b1545b3fec0f8425afc5b4baf122 (patch)
treed261814fc035cb8ff0db40cd214cece75a806f7d /glances/outputs/glances_bars.py
parent10d16c7e5ba7e8ae00f5f7f7c5fca612e347553c (diff)
Correct an issue when displaying quicklook plugin on non UTF-8 terminal
Diffstat (limited to 'glances/outputs/glances_bars.py')
-rw-r--r--glances/outputs/glances_bars.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/glances/outputs/glances_bars.py b/glances/outputs/glances_bars.py
index f149fef3..2d3d2974 100644
--- a/glances/outputs/glances_bars.py
+++ b/glances/outputs/glances_bars.py
@@ -21,9 +21,7 @@
# Import system lib
from math import modf
-
-# Global vars
-curses_bars = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"]
+import locale
class Bar(object):
@@ -54,6 +52,15 @@ class Bar(object):
self.__post_char = post_char
self.__empty_char = empty_char
self.__with_text = with_text
+ # Char used for the bar
+ self.curses_bars = self.__get_curses_bars()
+
+ def __get_curses_bars(self):
+ # Return the chars used to display the bar
+ if locale.getdefaultlocale()[1] == 'UTF-8':
+ return [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█"]
+ else:
+ return [" ", " ", " ", " ", "|", "|", "|", "|", "|"]
@property
def size(self, with_decoration=False):
@@ -80,9 +87,9 @@ class Bar(object):
def __str__(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: