summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xarchey330
1 files changed, 29 insertions, 1 deletions
diff --git a/archey3 b/archey3
index 6437a44..c74b2b2 100755
--- a/archey3
+++ b/archey3
@@ -170,6 +170,20 @@ class display(object):
(stdoutdata, stderrdata) = self.proccess.communicate(self.stdindata or None)
return self.format_output(stdoutdata.decode())
+ def color_me(self, output, number=None, low=30, low_color='green', medium=60, medium_color='yellow', high_color='red'):
+ if number is None and output.isdigit():
+ number = int(output)
+ elif number is None:
+ return output
+
+ if number <= low:
+ color = low_color
+ elif low < number <= medium:
+ color = medium_color
+ elif medium < number:
+ color = high_color
+
+ return '{0}{1}{2}'.format(self._parent.color(color), output, self._parent.color('clear'))
class fsDisplay(display):
command_line = "df -TPh {arg1}"
@@ -186,6 +200,14 @@ class fsDisplay(display):
mount = '/root' if self.arg1 == '/' else self.arg1
title = mount.split('/')[-1].title() + " FS"
+ try:
+ used_ = ''.join(c for c in used if c.isdigit())
+ total_ = ''.join(c for c in total if c.isdigit())
+ persentage = 100 - (int(used_)/int(total_) * 100)
+ except:
+ pass
+ else:
+ used = self.color_me(used, persentage)
part = '{used} / {total} ({fstype})'.format(used=used, total=total, fstype=fstype)
return title, part
@@ -197,7 +219,13 @@ class ramDisplay(display):
used = int(ram[2]) - int(ram[5]) - int(ram[6])
total = int(ram[1])
title = 'RAM'
- part = '{used} MB / {total} MB'.format(used=used, total=total)
+ try:
+ persentage = 100 - (used / total * 100)
+ except:
+ used += ' MB'
+ else:
+ used = self.color_me(number=persentage, output=str(used) + ' MB')
+ part = '{used} / {total} MB'.format(used=used, total=total)
return title, part
class sensorDisplay(display):