summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurie Clark-Michalek <bluepeppers@archlinux.us>2010-11-07 11:48:53 +0000
committerLaurie Clark-Michalek <bluepeppers@archlinux.us>2010-11-07 11:48:53 +0000
commitc5d85285e941c44c25e0840ecdb9ac6bea33b94c (patch)
treea68882ad050847e4701cbd5175facac692662d1a
parent32c53e86b6215d42f50a1e20d3df37924375e5b6 (diff)
Added color_me method to display classes, and colored RootFS output, and RAM output
-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):