diff --git a/.config/i3blocks/load b/.config/i3blocks/load index feace31..9e6b99e 100755 --- a/.config/i3blocks/load +++ b/.config/i3blocks/load @@ -3,28 +3,42 @@ import multiprocessing import os +from block import * -def load_fmt(load): - cores = multiprocessing.cpu_count() - color = '#ffffff' +ICON = "\uf085" - if load > cores * 0.5: - color = '#FFD966' - if load > cores * 0.7: - color = '#dd0000' +class Load(Block): - return '{:.2f}'.format(color, load) + def __init__(self, icon=None, icon_color=None): + super().__init__(icon, icon_color) + + self.cores = multiprocessing.cpu_count() + + def load_fmt(self, load): + color = '#ffffff' + + if load > self.cores * 0.5: + color = '#FFD966' + + if load > self.cores * 0.7: + color = '#dd0000' + + return self.color_text('{:.2f}'.format(load), color=color) + + def execute(self): + load1, load5, load15 = os.getloadavg() + + return ', '.join([ + self.load_fmt(load1), + self.load_fmt(load5), + self.load_fmt(load15), + ]) def main(): - load1, load5, load15 = os.getloadavg() - - print('\uf085 {}, {}, {}'.format( - load_fmt(load1), - load_fmt(load5), - load_fmt(load15), - )) + block = Load(ICON) + block.render() if __name__ == '__main__':