Skip to content

Commit

Permalink
Merge pull request #4505 from mon/customise-scrollbar
Browse files Browse the repository at this point in the history
Allow more easily customisable scrollbar glyphs
  • Loading branch information
willmcgugan authored Jun 2, 2024
2 parents 3f3e11e + 0ebbf05 commit fabef81
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/textual/scrollbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit fabef81

Please sign in to comment.