From 95b0d1e3f4823d31bcbf5bc0c2ee20753b20379e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 5 Dec 2018 21:54:41 -0700 Subject: [PATCH] Wrap reports if necessary --- .bin/Scripts/functions/sensors.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.bin/Scripts/functions/sensors.py b/.bin/Scripts/functions/sensors.py index bead3bfa..5e33e1cb 100644 --- a/.bin/Scripts/functions/sensors.py +++ b/.bin/Scripts/functions/sensors.py @@ -3,6 +3,7 @@ import itertools import json import re +import shutil from functions.common import * @@ -37,7 +38,7 @@ def fix_sensor_str(s): return s def generate_report(sensor_data, *temp_labels, colors=True): - """Build report based on temp_labels, returns list if str.""" + """Generate report based on temp_labels, returns list if str.""" report = [] for _section, _adapters in sorted(sensor_data.items()): # CoreTemps then Other temps @@ -48,6 +49,7 @@ def generate_report(sensor_data, *temp_labels, colors=True): # Source _line = '{:18} '.format(fix_sensor_str(_source)) _temps = [] + # Temps (skip label for Current) for _label in temp_labels: _temps.append('{}{}{}'.format( _label.lower() if _label != 'Current' else '', @@ -57,6 +59,26 @@ def generate_report(sensor_data, *temp_labels, colors=True): report.append(_line) report.append(' ') + # Wrap lines if necessary + screen_size = shutil.get_terminal_size() + rows = screen_size.lines - 1 + if len(report) > rows and screen_size.columns > 55*2: + report = list(itertools.zip_longest( + report[:rows], report[rows:], fillvalue='')) + report = [join_columns(a, b) for a, b in report] + + # Handle empty reports (i.e. no sensors detected) + if not report: + report = [ + '{}WARNING: No sensors found{}'.format( + COLORS['YELLOW'] if colors else '', + COLORS['CLEAR'] if colors else ''), + ' ', + 'Please monitor temps manually'] + + # Done + return report + def get_colored_temp_str(temp): """Get colored string based on temp, returns str.""" try: