From 6b9f21fd08a33babbad37d7345128d9966d9180f Mon Sep 17 00:00:00 2001 From: Arinerron Date: Thu, 10 May 2018 19:20:14 -0700 Subject: [PATCH] Add color configuration to statistics command --- onionr/logger.py | 2 +- onionr/onionr.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/onionr/logger.py b/onionr/logger.py index 990a8b95..c915f2f9 100644 --- a/onionr/logger.py +++ b/onionr/logger.py @@ -222,7 +222,7 @@ def error(data, error=None, timestamp=True): if not error is None: debug('Error: ' + str(error) + parse_error()) -# fatal: when the something so bad has happened that the prorgam must stop +# fatal: when the something so bad has happened that the program must stop def fatal(data, timestamp=True): if get_level() <= LEVEL_FATAL: log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp) diff --git a/onionr/onionr.py b/onionr/onionr.py index 13c2d0c2..e4cbfb13 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -574,6 +574,16 @@ class Onionr: 'Enabled Plugins Count' : str(len(config.get('plugins')['enabled'])) + ' / ' + str(len(os.listdir('data/plugins/'))) } + # color configuration + colors = { + 'title' : logger.colors.bold, + 'key' : logger.colors.fg.lightgreen, + 'val' : logger.colors.fg.green, + 'border' : logger.colors.fg.lightblue, + + 'reset' : logger.colors.reset + } + # pre-processing maxlength = 0 for key, val in messages.items(): @@ -581,14 +591,14 @@ class Onionr: maxlength = max(len(key), maxlength) # generate stats table - logger.info(logger.colors.bold + 'Onionr v%s Statistics' % ONIONR_VERSION + logger.colors.reset) - logger.info('─' * (maxlength + 1) + '┐') + logger.info(colors['title'] + 'Onionr v%s Statistics' % ONIONR_VERSION + colors['reset']) + logger.info(colors['border'] + '─' * (maxlength + 1) + '┐' + colors['reset']) for key, val in messages.items(): if not (type(val) is bool and val is True): - logger.info(str(key).rjust(maxlength) + ' │ ' + str(val)) + logger.info(colors['key'] + str(key).rjust(maxlength) + colors['reset'] + colors['border'] + ' │ ' + colors['reset'] + colors['val'] + str(val) + colors['reset']) else: - logger.info('─' * (maxlength + 1) + '┤') - logger.info('─' * (maxlength + 1) + '┘') + logger.info(colors['border'] + '─' * (maxlength + 1) + '┤' + colors['reset']) + logger.info(colors['border'] + '─' * (maxlength + 1) + '┘' + colors['reset']) except Exception as e: logger.error('Failed to generate statistics table.', error = e, timestamp = False)