diff: Better title rendering
This commit is contained in:
parent
9cb7a6b2c7
commit
7365ed9b05
@ -150,8 +150,8 @@ def create_collection(left, right):
|
||||
collect_files(collection, left, right)
|
||||
else:
|
||||
pl, pr = os.path.abspath(left), os.path.abspath(right)
|
||||
path_name_map[left] = pl
|
||||
path_name_map[right] = pr
|
||||
path_name_map[pl] = left
|
||||
path_name_map[pr] = right
|
||||
collection.add_change(pl, pr)
|
||||
collection.finalize()
|
||||
return collection
|
||||
|
||||
@ -46,7 +46,7 @@ class DiffHandler(Handler):
|
||||
def __init__(self, args, opts, left, right):
|
||||
self.state = INITIALIZING
|
||||
self.opts = opts
|
||||
self.left, self.right = map(os.path.abspath, (left, right))
|
||||
self.left, self.right = left, right
|
||||
self.report_traceback_on_exit = None
|
||||
self.args = args
|
||||
self.scroll_pos = self.max_scroll_pos = 0
|
||||
|
||||
@ -120,9 +120,18 @@ def highlight_boundaries(ltype):
|
||||
return start, stop
|
||||
|
||||
|
||||
def title_lines(left_path, args, columns, margin_size):
|
||||
name = fit_in(sanitize(path_name_map[left_path]), columns - 2 * margin_size)
|
||||
yield title_format(place_in(' ' + name, columns))
|
||||
def title_lines(left_path, right_path, args, columns, margin_size):
|
||||
m = ' ' * margin_size
|
||||
left_name, right_name = map(path_name_map.get, (left_path, right_path))
|
||||
if right_name and right_name != left_name:
|
||||
n1 = fit_in(m + sanitize(left_name), columns // 2 - margin_size)
|
||||
n1 = place_in(n1, columns // 2)
|
||||
n2 = fit_in(m + sanitize(right_name), columns // 2 - margin_size)
|
||||
n2 = place_in(n2, columns // 2)
|
||||
name = n1 + n2
|
||||
else:
|
||||
name = place_in(m + sanitize(left_name), columns)
|
||||
yield title_format(place_in(name, columns))
|
||||
yield title_format('━' * columns)
|
||||
|
||||
|
||||
@ -354,7 +363,7 @@ def render_diff(collection, diff_map, args, columns):
|
||||
for path, item_type, other_path in collection:
|
||||
item_ref = Reference(path)
|
||||
is_binary = isinstance(data_for_path(path), bytes)
|
||||
yield from yield_lines_from(title_lines(path, args, columns, margin_size), item_ref)
|
||||
yield from yield_lines_from(title_lines(path, other_path, args, columns, margin_size), item_ref)
|
||||
if item_type == 'diff':
|
||||
if is_binary:
|
||||
ans = yield_lines_from(binary_lines(path, other_path, columns, margin_size), item_ref)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user