@@ -18,6 +18,10 @@ class Bar:
18
18
gradient: Optional gradient object.
19
19
"""
20
20
21
+ HALF_BAR_LEFT : str = "╺"
22
+ BAR : str = "━"
23
+ HALF_BAR_RIGHT : str = "╸"
24
+
21
25
def __init__ (
22
26
self ,
23
27
highlight_range : tuple [float , float ] = (0 , 0 ),
@@ -40,10 +44,6 @@ def __rich_console__(
40
44
highlight_style = console .get_style (self .highlight_style )
41
45
background_style = console .get_style (self .background_style )
42
46
43
- half_bar_right = "╸"
44
- half_bar_left = "╺"
45
- bar = "━"
46
-
47
47
width = self .width or options .max_width
48
48
start , end = self .highlight_range
49
49
@@ -53,7 +53,7 @@ def __rich_console__(
53
53
output_bar = Text ("" , end = "" )
54
54
55
55
if start == end == 0 or end < 0 or start > end :
56
- output_bar .append (Text (bar * width , style = background_style , end = "" ))
56
+ output_bar .append (Text (self . BAR * width , style = background_style , end = "" ))
57
57
yield output_bar
58
58
return
59
59
@@ -67,34 +67,40 @@ def __rich_console__(
67
67
68
68
# Initial non-highlighted portion of bar
69
69
output_bar .append (
70
- Text (bar * (int (start - 0.5 )), style = background_style , end = "" )
70
+ Text (self . BAR * (int (start - 0.5 )), style = background_style , end = "" )
71
71
)
72
72
if not half_start and start > 0 :
73
- output_bar .append (Text (half_bar_right , style = background_style , end = "" ))
73
+ output_bar .append (Text (self . HALF_BAR_RIGHT , style = background_style , end = "" ))
74
74
75
75
highlight_bar = Text ("" , end = "" )
76
76
# The highlighted portion
77
77
bar_width = int (end ) - int (start )
78
78
if half_start :
79
79
highlight_bar .append (
80
80
Text (
81
- half_bar_left + bar * (bar_width - 1 ), style = highlight_style , end = ""
81
+ self .HALF_BAR_LEFT + self .BAR * (bar_width - 1 ),
82
+ style = highlight_style ,
83
+ end = "" ,
82
84
)
83
85
)
84
86
else :
85
- highlight_bar .append (Text (bar * bar_width , style = highlight_style , end = "" ))
87
+ highlight_bar .append (
88
+ Text (self .BAR * bar_width , style = highlight_style , end = "" )
89
+ )
86
90
if half_end :
87
- highlight_bar .append (Text (half_bar_right , style = highlight_style , end = "" ))
91
+ highlight_bar .append (
92
+ Text (self .HALF_BAR_RIGHT , style = highlight_style , end = "" )
93
+ )
88
94
89
95
if self .gradient is not None :
90
96
_apply_gradient (highlight_bar , self .gradient , width )
91
97
output_bar .append (highlight_bar )
92
98
93
99
# The non-highlighted tail
94
100
if not half_end and end - width != 0 :
95
- output_bar .append (Text (half_bar_left , style = background_style , end = "" ))
101
+ output_bar .append (Text (self . HALF_BAR_LEFT , style = background_style , end = "" ))
96
102
output_bar .append (
97
- Text (bar * (int (width ) - int (end ) - 1 ), style = background_style , end = "" )
103
+ Text (self . BAR * (int (width ) - int (end ) - 1 ), style = background_style , end = "" )
98
104
)
99
105
100
106
# Fire actions when certain ranges are clicked (e.g. for tabs)
0 commit comments