[Feature Request] Option in config to change character used to display percentage in Quicklook #1511

This commit is contained in:
nicolargo 2019-08-11 11:13:47 +02:00
parent 2ec1adb17e
commit 7208bd3df7
4 changed files with 15 additions and 8 deletions

View File

@ -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

View File

@ -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:

View File

@ -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.

View File

@ -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: