Change the default background of scrollbars.

- Also hacked the cursor row highlighting to not highlight the
  scrollbar. Highlighting the widget inside the view widget is
  much more difficult.
This commit is contained in:
Andrew Hamilton 2018-07-20 08:57:18 +10:00
parent 07ffb403f5
commit dd0b763dab
4 changed files with 19 additions and 12 deletions

View file

@ -74,7 +74,8 @@ class WidgetTests(unittest.TestCase):
def assert_string2(self, appearance, expected_string):
self.assertEqual(
("\n".join(line.data for line in appearance),
"".join("i" if style.fg_color==termstr.Color.black else " "
"".join("i" if style.fg_color==
fill3.ScrollBar.DEFAULT_BACKGROUND_COLOR else " "
for line in appearance for style in line.style)),
expected_string)

View file

@ -346,8 +346,9 @@ class Summary:
def _highlight_cursor_row(self, appearance, cursor_y):
scroll_x, scroll_y = self._view_widget.position
highlighted_y = cursor_y - scroll_y
appearance[highlighted_y] = highlight_str(
appearance[highlighted_y], termstr.Color.white, 0.85)
appearance[highlighted_y] = (highlight_str(
appearance[highlighted_y][:-1], termstr.Color.white, 0.85)
+ appearance[highlighted_y][-1])
return appearance
def appearance(self, dimensions):

View file

@ -181,27 +181,31 @@ class ScrollBar:
_HORIZONTAL_CHARS = [" ", "", "", "", "", "", "", ""]
_VERTICAL_CHARS = ["", "", "", "", "", "", "", ""]
DEFAULT_BAR_COLOR = termstr.Color.grey_100
DEFAULT_BACKGROUND_COLOR = termstr.Color.grey_30
def __init__(self, is_horizontal, interval=(0, 0),
bar_color=termstr.Color.grey_100,
background_color=termstr.Color.black):
def __init__(self, is_horizontal, interval=(0, 0), bar_color=None,
background_color=None):
self._is_horizontal = is_horizontal
self.interval = interval
self.bar_color = bar_color
self.background_color = background_color
bar_color = (ScrollBar.DEFAULT_BAR_COLOR if bar_color is None
else bar_color)
background_color = (ScrollBar.DEFAULT_BACKGROUND_COLOR
if background_color is None
else background_color)
self.bar_char = termstr.TermStr("").fg_color(bar_color)
self.background_char = termstr.TermStr(" ").bg_color(background_color)
self.start_h_chars = [termstr.TermStr(char).fg_color(
self.background_color).bg_color(self.bar_color)
background_color).bg_color(bar_color)
for char in self._HORIZONTAL_CHARS]
self.end_h_chars = [termstr.TermStr(char).fg_color(
self.bar_color).bg_color(self.background_color)
bar_color).bg_color(background_color)
for char in self._HORIZONTAL_CHARS]
self.start_v_chars = [termstr.TermStr(char).fg_color(
self.bar_color).bg_color(self.background_color)
bar_color).bg_color(background_color)
for char in self._VERTICAL_CHARS]
self.end_v_chars = [termstr.TermStr(char).fg_color(
self.background_color).bg_color(self.bar_color)
background_color).bg_color(bar_color)
for char in self._VERTICAL_CHARS]
def appearance(self, dimensions):

View file

@ -49,6 +49,7 @@ class Color:
blue = (0, 135, 189)
lime = (0, 255, 0)
yellow = (255, 211, 0)
grey_30 = (30, 30, 30)
grey_50 = (50, 50, 50)
grey_100 = (100, 100, 100)
grey_150 = (150, 150, 150)