From e8fa75d25f51f62b552072a12a18d2074d079f95 Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Sat, 11 May 2024 22:09:29 +1000 Subject: [PATCH 1/2] Allow more easily customisable scrollbar glyphs --- src/textual/scrollbar.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index 2700419192..38eaadb1f3 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -70,6 +70,13 @@ def __rich_repr__(self) -> rich.repr.Result: class ScrollBarRender: + _vertical_bars: ClassVar[list[str]] = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", " "] + """Glyphs used for vertical scrollbar ends, for smoother display.""" + _horizontal_bars: ClassVar[list[str]] = ["▉", "▊", "▋", "▌", "▍", "▎", "▏", " "] + """Glyphs used for horizontal scrollbar ends, for smoother display.""" + _blank_glyph: ClassVar[str] = " " + """Glyph used for the main body of the scrollbar""" + def __init__( self, virtual_size: int = 100, @@ -99,9 +106,9 @@ def render_bar( bar_color: Color = Color.parse("bright_magenta"), ) -> Segments: if vertical: - bars = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", " "] + bars = cls._vertical_bars else: - bars = ["▉", "▊", "▋", "▌", "▍", "▎", "▏", " "] + bars = cls._horizontal_bars back = back_color bar = bar_color @@ -112,7 +119,7 @@ def render_bar( _Segment = Segment _Style = Style - blank = " " * width_thickness + blank = cls._blank_glyph * width_thickness foreground_meta = {"@mouse.down": "grab"} if window_size and size and virtual_size and size != virtual_size: From 0ebbf05d13ddb220997ff38409aad1ce09f10124 Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Mon, 27 May 2024 08:25:46 +1000 Subject: [PATCH 2/2] ScrollBarRender: change class constants to SCREAMING_SNAKE_CASE --- src/textual/scrollbar.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index 38eaadb1f3..a105aa8370 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -70,11 +70,11 @@ def __rich_repr__(self) -> rich.repr.Result: class ScrollBarRender: - _vertical_bars: ClassVar[list[str]] = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", " "] + VERTICAL_BARS: ClassVar[list[str]] = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", " "] """Glyphs used for vertical scrollbar ends, for smoother display.""" - _horizontal_bars: ClassVar[list[str]] = ["▉", "▊", "▋", "▌", "▍", "▎", "▏", " "] + HORIZONTAL_BARS: ClassVar[list[str]] = ["▉", "▊", "▋", "▌", "▍", "▎", "▏", " "] """Glyphs used for horizontal scrollbar ends, for smoother display.""" - _blank_glyph: ClassVar[str] = " " + BLANK_GLYPH: ClassVar[str] = " " """Glyph used for the main body of the scrollbar""" def __init__( @@ -106,9 +106,9 @@ def render_bar( bar_color: Color = Color.parse("bright_magenta"), ) -> Segments: if vertical: - bars = cls._vertical_bars + bars = cls.VERTICAL_BARS else: - bars = cls._horizontal_bars + bars = cls.HORIZONTAL_BARS back = back_color bar = bar_color @@ -119,7 +119,7 @@ def render_bar( _Segment = Segment _Style = Style - blank = cls._blank_glyph * width_thickness + blank = cls.BLANK_GLYPH * width_thickness foreground_meta = {"@mouse.down": "grab"} if window_size and size and virtual_size and size != virtual_size: