Better auto adjust width, bug fix for empty exclude list
If no exclude folders were given the list was not set so the initial read failed. Auto adjust to terminal size now works identical for smaller and larger
This commit is contained in:
@@ -514,8 +514,12 @@ args = parser.parse_args()
|
|||||||
### MAIN CODE
|
### MAIN CODE
|
||||||
##############################################################
|
##############################################################
|
||||||
|
|
||||||
|
# init verbose to 0 if not set
|
||||||
if not args.verbose:
|
if not args.verbose:
|
||||||
args.verbose = 0
|
args.verbose = 0
|
||||||
|
# init exclude source to list if not set
|
||||||
|
if not args.exclude_sources:
|
||||||
|
args.exclude_sources = []
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print("### ARGUMENT VARS: I: {incl}, X: {excl}, L: {lr}, F: {fc}, M: {osm}, G: {gp}, E: {em}, R: {read}, A: {adj}, C: {cmp}, N: {nbk}, W: {wrc}, V: {v}, D: {d}, T: {t}".format(
|
print("### ARGUMENT VARS: I: {incl}, X: {excl}, L: {lr}, F: {fc}, M: {osm}, G: {gp}, E: {em}, R: {read}, A: {adj}, C: {cmp}, N: {nbk}, W: {wrc}, V: {v}, D: {d}, T: {t}".format(
|
||||||
@@ -748,40 +752,58 @@ if args.read_only:
|
|||||||
for format_key in ['filename', 'latitude', 'longitude', 'country', 'state', 'city', 'location', 'path']:
|
for format_key in ['filename', 'latitude', 'longitude', 'country', 'state', 'city', 'location', 'path']:
|
||||||
format_length[format_key] = ceil(format_length[format_key] - ((format_length[format_key] / 100) * reduce_percent))
|
format_length[format_key] = ceil(format_length[format_key] - ((format_length[format_key] / 100) * reduce_percent))
|
||||||
else:
|
else:
|
||||||
|
# minimum resize size for a column
|
||||||
|
resize_width_min = 4
|
||||||
|
# the resize percent
|
||||||
|
# start with 10, then increase until we reach max
|
||||||
|
resize_percent_min = 10
|
||||||
|
resize_percent_max = 50
|
||||||
|
# abort flag so we can break out of the second loop too
|
||||||
|
abort = False
|
||||||
|
# formay key order, in which order the elements will be resized
|
||||||
|
format_key_order = []
|
||||||
|
# resize flag: 0 no, 1: make bigger, -1: make smaller
|
||||||
# change sizes for print based on terminal size
|
# change sizes for print based on terminal size
|
||||||
# NOTE: in screen or term this data might NOT be correct
|
# NOTE: in screen or term this data might NOT be correct
|
||||||
# Current size needs the in between and left/right space data
|
# Current size needs the in between and left/right space data
|
||||||
current_columns = sum(format_length.values()) + ((len(format_length) - 1) * 3) + 2
|
current_columns = sum(format_length.values()) + ((len(format_length) - 1) * 3) + 2
|
||||||
if current_columns < get_terminal_size().columns:
|
if current_columns < get_terminal_size().columns:
|
||||||
# only do if not disabled
|
resize = 1
|
||||||
if not args.no_autoadjust:
|
format_key_order = ['path', 'location', 'state', 'city', 'country', 'filename']
|
||||||
# keep one empty
|
|
||||||
width_up = get_terminal_size().columns - current_columns - 1
|
|
||||||
if width_up > 0:
|
|
||||||
format_length['path'] += width_up
|
|
||||||
else:
|
else:
|
||||||
# NOTE: perhaps we can have some min size numbers to counter resize
|
resize = -1
|
||||||
# lat/long -> max 6, country -> 10, path -> 20
|
format_key_order = ['latitude', 'longitude', 'path', 'country', 'state', 'city', 'location', 'filename']
|
||||||
if not args.no_autoadjust:
|
# if we have no auto adjust
|
||||||
print("Terminal width too small, will adjust layout automatically")
|
if resize and args.no_autoadjust:
|
||||||
# abort flag so we can break out of the second loop too
|
# warningn if screen is too small
|
||||||
abort = False
|
if resize == -1:
|
||||||
# start with 10, then increase until we reach max
|
print("[!!!] Screen layout might be skewed. Increase Terminal width")
|
||||||
reduce_percent_min = 10
|
resize = 0
|
||||||
reduce_percent_max = 50
|
else:
|
||||||
# loop for each percent grouping and through each reduce size
|
for resize_percent in range(resize_percent_min, resize_percent_max, 10):
|
||||||
for reduce_percent in range(reduce_percent_min, reduce_percent_max, 10):
|
for format_key in format_key_order:
|
||||||
for format_key in ['latitude', 'longitude', 'path', 'country', 'state', 'city', 'location', 'filename']:
|
resize_width = (format_length[format_key] / 100) * resize_percent
|
||||||
format_length[format_key] = ceil(format_length[format_key] - ((format_length[format_key] / 100) * reduce_percent))
|
# if we down size, make it negative
|
||||||
# abort if the size of the new format is smaller than the terminal columns
|
if resize == -1:
|
||||||
if sum(format_length.values()) + ((len(format_length) - 1) * 3) + 3 <= get_terminal_size().columns:
|
resize_width *= -1
|
||||||
|
resize_width = ceil(format_length[format_key] + resize_width)
|
||||||
|
# in case too small, keep old one
|
||||||
|
format_length[format_key] = resize_width if resize_width > resize_width_min else format_length[format_key]
|
||||||
|
# calc new width for check if we can abort
|
||||||
|
current_columns = sum(format_length.values()) + ((len(format_length) - 1) * 3) + 2
|
||||||
|
if (resize == 1 and current_columns >= get_terminal_size().columns) or (resize == -1 and current_columns < get_terminal_size().columns):
|
||||||
|
# check that we are not OVER but one under
|
||||||
|
width_up = get_terminal_size().columns - current_columns - 1
|
||||||
|
if (resize == 1 and width_up < 0) or (resize == -1 and width_up != 0):
|
||||||
|
if format_length['path'] + width_up >= resize_width_min:
|
||||||
|
format_length['path'] += width_up
|
||||||
abort = True
|
abort = True
|
||||||
break
|
break
|
||||||
# break out of the outer loop too
|
|
||||||
if abort:
|
if abort:
|
||||||
break
|
break
|
||||||
else:
|
if sum(format_length.values()) + ((len(format_length) - 1) * 3) + 2 > get_terminal_size().columns:
|
||||||
print("Screen layout might be skewed. Increase Terminal width")
|
print("[!!!] Screen layout might be skewed. Increase Terminal width")
|
||||||
|
|
||||||
# after how many lines do we reprint the header
|
# after how many lines do we reprint the header
|
||||||
header_repeat = 50;
|
header_repeat = 50;
|
||||||
# how many pages will we have
|
# how many pages will we have
|
||||||
@@ -809,15 +831,15 @@ if args.read_only:
|
|||||||
{}'''.format(
|
{}'''.format(
|
||||||
'> Page {page_no:,}/{page_all:,}', # can later be set to something else, eg page numbers
|
'> Page {page_no:,}/{page_all:,}', # can later be set to something else, eg page numbers
|
||||||
format_line.format( # the header title line
|
format_line.format( # the header title line
|
||||||
filename = 'File',
|
filename = 'File'[:format_length['filename']],
|
||||||
latitude = 'Latitude',
|
latitude = 'Latitude'[:format_length['latitude']],
|
||||||
longitude = 'Longitude',
|
longitude = 'Longitude'[:format_length['longitude']],
|
||||||
code = 'Code',
|
code = 'Code',
|
||||||
country = 'Country',
|
country = 'Country'[:format_length['country']],
|
||||||
state = 'State',
|
state = 'State'[:format_length['state']],
|
||||||
city = 'City',
|
city = 'City'[:format_length['city']],
|
||||||
location = 'Location',
|
location = 'Location'[:format_length['location']],
|
||||||
path = 'Path'
|
path = 'Path'[:format_length['path']]
|
||||||
),
|
),
|
||||||
"{}+{}+{}+{}+{}+{}+{}+{}+{}".format( # the header seperator line
|
"{}+{}+{}+{}+{}+{}+{}+{}+{}".format( # the header seperator line
|
||||||
'-' * (format_length['filename'] + 2),
|
'-' * (format_length['filename'] + 2),
|
||||||
|
|||||||
Reference in New Issue
Block a user