From 9cab8a2de57a3ec7bdd927d0bb9e65c83485a002 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 20 May 2018 08:51:41 +0530 Subject: [PATCH] diff kitten: Do not specify the default foreground color in formatting codes. Fixes an issue with foreground color being incorrect after a highlighted segment if the syntax highlight does not specify a foreground color at the boundary. --- kittens/diff/collect.py | 5 +++++ kittens/diff/config.py | 6 +++--- kittens/diff/patch.py | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kittens/diff/collect.py b/kittens/diff/collect.py index 66be7376b..ac35b95de 100644 --- a/kittens/diff/collect.py +++ b/kittens/diff/collect.py @@ -19,6 +19,11 @@ class Segment: self.start = start self.start_code = start_code + def __repr__(self): + return 'Segment(start={!r}, start_code={!r}, end={!r}, end_code={!r})'.format( + self.start, self.start_code, getattr(self, 'end', None), getattr(self, 'end_code', None) + ) + class Collection: diff --git a/kittens/diff/config.py b/kittens/diff/config.py index ccb49e628..ea9d516f6 100644 --- a/kittens/diff/config.py +++ b/kittens/diff/config.py @@ -24,13 +24,13 @@ formats = { def set_formats(opts): - formats['text'] = '38' + color_as_sgr(opts.foreground) + ';48' + color_as_sgr(opts.background) + formats['text'] = '48' + color_as_sgr(opts.background) formats['title'] = '38' + color_as_sgr(opts.title_fg) + ';48' + color_as_sgr(opts.title_bg) + ';1' formats['margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.margin_bg) formats['added_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.added_margin_bg) formats['removed_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.removed_margin_bg) - formats['added'] = '38' + color_as_sgr(opts.foreground) + ';48' + color_as_sgr(opts.added_bg) - formats['removed'] = '38' + color_as_sgr(opts.foreground) + ';48' + color_as_sgr(opts.removed_bg) + formats['added'] = '48' + color_as_sgr(opts.added_bg) + formats['removed'] = '48' + color_as_sgr(opts.removed_bg) formats['filler'] = '48' + color_as_sgr(opts.filler_bg) formats['hunk_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_margin_bg) formats['hunk'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_bg) diff --git a/kittens/diff/patch.py b/kittens/diff/patch.py index 6573d85d4..c520f5e49 100644 --- a/kittens/diff/patch.py +++ b/kittens/diff/patch.py @@ -69,7 +69,10 @@ class Chunk: def finalize(self): if not self.is_context and self.left_count == self.right_count: - self.centers = tuple(changed_center(left_lines[self.left_start + i], right_lines[self.right_start + i]) for i in range(self.left_count)) + self.centers = tuple( + changed_center(left_lines[self.left_start + i], right_lines[self.right_start + i]) + for i in range(self.left_count) + ) def __repr__(self): return 'Chunk(is_context={}, left_start={}, left_count={}, right_start={}, right_count={})'.format(