From 59743fd7a1f66c4e3dbbd9d5a49be0f325a3189c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Jun 2018 14:43:39 +0530 Subject: [PATCH] diff kitten: Allow theming the selection background/foreground as well --- kittens/diff/config_data.py | 4 +++- kittens/diff/main.py | 14 +++++++++----- kittens/tui/operations.py | 27 ++++++++++++++------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/kittens/diff/config_data.py b/kittens/diff/config_data.py index 532b8a2ac..3312f6423 100644 --- a/kittens/diff/config_data.py +++ b/kittens/diff/config_data.py @@ -83,8 +83,10 @@ c('filler_bg', '#fafbfc', long_text=_('Filler (empty) line background')) c('hunk_margin_bg', '#dbedff', long_text=_('Hunk header colors')) c('hunk_bg', '#f1f8ff') -c('search_bg', '#444', long_text=_('Search highlighting')) +c('search_bg', '#444', long_text=_('Highlighting')) c('search_fg', 'white') +c('select_bg', '#B4D5FE') +c('select_fg', 'black') g('shortcuts') k('quit', 'q', 'quit', _('Quit')) diff --git a/kittens/diff/main.py b/kittens/diff/main.py index 1ebb54b07..b0688a51f 100644 --- a/kittens/diff/main.py +++ b/kittens/diff/main.py @@ -205,9 +205,17 @@ class DiffHandler(Handler): def init_terminal_state(self): self.cmd.set_line_wrapping(False) self.cmd.set_window_title(main.title) - self.cmd.set_default_colors(self.opts.foreground, self.opts.background, self.opts.foreground) + self.cmd.set_default_colors( + fg=self.opts.foreground, bg=self.opts.background, + cursor=self.opts.foreground, select_fg=self.opts.select_fg, + select_bg=self.opts.select_bg) self.cmd.set_cursor_shape('bar') + def finalize(self): + self.cmd.set_default_colors() + self.cmd.set_cursor_visible(True) + self.cmd.set_scrolling_region() + def initialize(self): self.init_terminal_state() self.set_scrolling_region() @@ -217,10 +225,6 @@ class DiffHandler(Handler): def enforce_cursor_state(self): self.cmd.set_cursor_visible(self.state > DIFFED) - def finalize(self): - self.cmd.set_cursor_visible(True) - self.cmd.set_scrolling_region() - def draw_lines(self, num, offset=0): offset += self.scroll_pos image_involved = False diff --git a/kittens/tui/operations.py b/kittens/tui/operations.py index c7a6aaa9d..6c0a07eb2 100644 --- a/kittens/tui/operations.py +++ b/kittens/tui/operations.py @@ -227,20 +227,21 @@ def alternate_screen(f=None): print(reset_mode('ALTERNATE_SCREEN'), end='', file=f) -def set_default_colors(fg=None, bg=None, cursor=None) -> str: +def set_default_colors(fg=None, bg=None, cursor=None, select_bg=None, select_fg=None) -> str: ans = '' - if fg is None: - ans += '\x1b]110\x1b\\' - else: - ans += '\x1b]10;{}\x1b\\'.format(color_as_sharp(fg if isinstance(fg, Color) else to_color(fg))) - if cursor is None: - ans += '\x1b]112\x1b\\' - else: - ans += '\x1b]12;{}\x1b\\'.format(color_as_sharp(cursor if isinstance(cursor, Color) else to_color(cursor))) - if bg is None: - ans += '\x1b]111\x1b\\' - else: - ans += '\x1b]11;{}\x1b\\'.format(color_as_sharp(bg if isinstance(bg, Color) else to_color(bg))) + + def item(which, num): + nonlocal ans + if item is None: + ans += '\x1b]1{}\x1b\\'.format(num) + else: + ans += '\x1b]{};{}\x1b\\'.format(num, color_as_sharp(which if isinstance(which, Color) else to_color(which))) + + item(fg, 10) + item(bg, 11) + item(cursor, 12) + item(select_bg, 17) + item(select_fg, 19) return ans