Dynamically adjust stats menu size
This commit is contained in:
parent
25208e4374
commit
d382fca524
@ -637,16 +637,24 @@ class Onionr:
|
|||||||
|
|
||||||
# pre-processing
|
# pre-processing
|
||||||
maxlength = 0
|
maxlength = 0
|
||||||
|
width = self.getConsoleWidth()
|
||||||
for key, val in messages.items():
|
for key, val in messages.items():
|
||||||
if not (type(val) is bool and val is True):
|
if not (type(val) is bool and val is True):
|
||||||
maxlength = max(len(key), maxlength)
|
maxlength = max(len(key), maxlength)
|
||||||
|
prewidth = maxlength + len(' | ')
|
||||||
|
groupsize = width - prewidth - len('[+] ')
|
||||||
|
|
||||||
# generate stats table
|
# generate stats table
|
||||||
logger.info(colors['title'] + 'Onionr v%s Statistics' % ONIONR_VERSION + colors['reset'])
|
logger.info(colors['title'] + 'Onionr v%s Statistics' % ONIONR_VERSION + colors['reset'])
|
||||||
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
||||||
for key, val in messages.items():
|
for key, val in messages.items():
|
||||||
if not (type(val) is bool and val is True):
|
if not (type(val) is bool and val is True):
|
||||||
logger.info(colors['key'] + str(key).rjust(maxlength) + colors['reset'] + colors['border'] + ' | ' + colors['reset'] + colors['val'] + str(val) + colors['reset'])
|
val = [str(val)[i:i + groupsize] for i in range(0, len(str(val)), groupsize)]
|
||||||
|
|
||||||
|
logger.info(colors['key'] + str(key).rjust(maxlength) + colors['reset'] + colors['border'] + ' | ' + colors['reset'] + colors['val'] + str(val.pop(0)) + colors['reset'])
|
||||||
|
|
||||||
|
for value in val:
|
||||||
|
logger.info(' ' * maxlength + colors['border'] + ' | ' + colors['reset'] + colors['val'] + str(value) + colors['reset'])
|
||||||
else:
|
else:
|
||||||
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
||||||
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
logger.info(colors['border'] + '-' * (maxlength + 1) + '+' + colors['reset'])
|
||||||
@ -683,6 +691,21 @@ class Onionr:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def getConsoleWidth(self):
|
||||||
|
'''
|
||||||
|
Returns an integer, the width of the terminal/cmd window
|
||||||
|
'''
|
||||||
|
|
||||||
|
columns = 80
|
||||||
|
|
||||||
|
try:
|
||||||
|
columns = int(os.popen('stty size', 'r').read().split()[1])
|
||||||
|
except:
|
||||||
|
# if it errors, it's probably windows, so default to 80.
|
||||||
|
pass
|
||||||
|
|
||||||
|
return columns
|
||||||
|
|
||||||
def addFile(self):
|
def addFile(self):
|
||||||
'''
|
'''
|
||||||
Adds a file to the onionr network
|
Adds a file to the onionr network
|
||||||
|
Loading…
Reference in New Issue
Block a user