Add swap information - Todo: WebUI

This commit is contained in:
nicolargo 2024-01-20 17:19:41 +01:00
parent ef9694cd6a
commit 2d997ac36f
2 changed files with 11 additions and 11 deletions

View File

@ -15,7 +15,6 @@ from math import modf
class Bar(object):
"""Manage bar (progression or status).
import sys
@ -29,11 +28,8 @@ class Bar(object):
"""
def __init__(self, size,
percentage_char='|',
empty_char=' ',
pre_char='[', post_char=']',
display_value=True,
min_value=0, max_value=100):
percentage_char='|', empty_char=' ', pre_char='[', post_char=']',
display_value=True, min_value=0, max_value=100):
# Build curses_bars
self.__curses_bars = [empty_char] * 5 + [percentage_char] * 5
# Bar size
@ -75,11 +71,9 @@ class Bar(object):
def post_char(self):
return self.__post_char
def get(self):
def get(self, overwrite=''):
"""Return the bars."""
value = self.percent
if value > self.max_value:
value = self.max_value
value = self.max_value if self.percent > self.max_value else self.percent
frac, whole = modf(self.size * value / 100.0)
ret = self.__curses_bars[8] * int(whole)
if frac > 0:
@ -91,6 +85,8 @@ class Bar(object):
ret = '{}>{:4.0f}%'.format(ret, self.max_value)
else:
ret = '{}{:5.1f}%'.format(ret, self.percent)
if overwrite and len(overwrite) < len(ret) - 6:
ret = overwrite + ret[len(overwrite):]
return ret
def __str__(self):

View File

@ -221,10 +221,14 @@ class PluginModel(GlancesPluginModel):
def _msg_create_line(self, msg, data, key):
"""Create a new line to the Quick view."""
if key == 'mem' and self.get_alert(self.stats['swap'], header='swap') != 'DEFAULT':
overwrite = 'SWAP'
else:
overwrite = ''
return [
self.curse_add_line(msg),
self.curse_add_line(data.pre_char, decoration='BOLD'),
self.curse_add_line(data.get(), self.get_views(key=key, option='decoration')),
self.curse_add_line(data.get(overwrite), self.get_views(key=key, option='decoration')),
self.curse_add_line(data.post_char, decoration='BOLD'),
self.curse_add_line(' '),
]