editor: Fix highlighting lines on themes with bright backgrounds
- For bright backgrounds brightening the line doesn't stand out, so darken the line instead.
This commit is contained in:
parent
c049aeeee7
commit
07e0ce9f56
1 changed files with 19 additions and 10 deletions
|
|
@ -32,13 +32,6 @@ def highlight_str(line, bg_color, transparency=0.6):
|
||||||
return termstr.TermStr(line).transform_style(blend_style)
|
return termstr.TermStr(line).transform_style(blend_style)
|
||||||
|
|
||||||
|
|
||||||
def highlight_line(line):
|
|
||||||
return highlight_str(line, termstr.Color.white, 0.8)
|
|
||||||
|
|
||||||
|
|
||||||
NATIVE_STYLE = pygments.styles.get_style_by_name("paraiso-dark")
|
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=500)
|
@functools.lru_cache(maxsize=500)
|
||||||
def parse_rgb(hex_rgb):
|
def parse_rgb(hex_rgb):
|
||||||
if hex_rgb.startswith("#"):
|
if hex_rgb.startswith("#"):
|
||||||
|
|
@ -46,6 +39,21 @@ def parse_rgb(hex_rgb):
|
||||||
return tuple(int("0x" + hex_rgb[index:index+2], base=16) for index in [0, 2, 4])
|
return tuple(int("0x" + hex_rgb[index:index+2], base=16) for index in [0, 2, 4])
|
||||||
|
|
||||||
|
|
||||||
|
@functools.cache
|
||||||
|
def is_bright_theme(theme):
|
||||||
|
return sum(parse_rgb(theme.background_color)) > (255 * 3 / 2)
|
||||||
|
|
||||||
|
|
||||||
|
def highlight_line(line, theme=None):
|
||||||
|
if theme is not None and is_bright_theme(theme):
|
||||||
|
return highlight_str(line, termstr.Color.black, 0.8)
|
||||||
|
else:
|
||||||
|
return highlight_str(line, termstr.Color.white, 0.8)
|
||||||
|
|
||||||
|
|
||||||
|
NATIVE_STYLE = pygments.styles.get_style_by_name("paraiso-dark")
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=500)
|
@functools.lru_cache(maxsize=500)
|
||||||
def char_style_for_token_type(token_type, style):
|
def char_style_for_token_type(token_type, style):
|
||||||
default_bg_color = parse_rgb(style.background_color)
|
default_bg_color = parse_rgb(style.background_color)
|
||||||
|
|
@ -319,7 +327,8 @@ class Parts:
|
||||||
appearance, coords = wrap_text(parts, width - 1, pad_char)
|
appearance, coords = wrap_text(parts, width - 1, pad_char)
|
||||||
line_num = coords[self.cursor][0] // (width - 1)
|
line_num = coords[self.cursor][0] // (width - 1)
|
||||||
if self.is_focused:
|
if self.is_focused:
|
||||||
appearance[line_num] = highlight_line(appearance[line_num])
|
appearance[line_num] = highlight_line(appearance[line_num],
|
||||||
|
self.editor.text_widget.theme)
|
||||||
view_widget = fill3.View.from_widget(fill3.Fixed(appearance))
|
view_widget = fill3.View.from_widget(fill3.Fixed(appearance))
|
||||||
if line_num >= height:
|
if line_num >= height:
|
||||||
x, y = view_widget.portal.position
|
x, y = view_widget.portal.position
|
||||||
|
|
@ -329,7 +338,7 @@ class Parts:
|
||||||
else:
|
else:
|
||||||
if self.is_focused:
|
if self.is_focused:
|
||||||
line_num = coords[self.cursor][0] // width
|
line_num = coords[self.cursor][0] // width
|
||||||
result[line_num] = highlight_line(result[line_num])
|
result[line_num] = highlight_line(result[line_num], self.editor.text_widget.theme)
|
||||||
fg_color = termstr.Color.grey_100
|
fg_color = termstr.Color.grey_100
|
||||||
bg_color = parse_rgb(self.editor.text_widget.theme.background_color)
|
bg_color = parse_rgb(self.editor.text_widget.theme.background_color)
|
||||||
result.append(termstr.TermStr("─").bg_color(bg_color).fg_color(fg_color) * width)
|
result.append(termstr.TermStr("─").bg_color(bg_color).fg_color(fg_color) * width)
|
||||||
|
|
@ -440,7 +449,7 @@ class TextEditor:
|
||||||
return appearance
|
return appearance
|
||||||
if self.mark is None:
|
if self.mark is None:
|
||||||
if 0 <= cursor_y < len(appearance):
|
if 0 <= cursor_y < len(appearance):
|
||||||
appearance[cursor_y] = highlight_line(appearance[cursor_y])
|
appearance[cursor_y] = highlight_line(appearance[cursor_y], self.text_widget.theme)
|
||||||
else:
|
else:
|
||||||
self._highlight_selection(appearance)
|
self._highlight_selection(appearance)
|
||||||
if self.cursor_x >= len(appearance[0]):
|
if self.cursor_x >= len(appearance[0]):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue