diff --git a/rich/bar.py b/rich/bar.py index e2fbf3d7..8ea7fef8 100644 --- a/rich/bar.py +++ b/rich/bar.py @@ -77,7 +77,7 @@ class Bar(JupyterMixin): Returns: List[Segment]: A list of segments, one segment per character. """ - bar = "█" if legacy_windows else "━" + bar = "─" if legacy_windows else "━" segments: List[Segment] = [] if color_system != "truecolor": @@ -86,13 +86,11 @@ class Bar(JupyterMixin): return segments append = segments.append - fore_color = ( fore_style.color.get_truecolor() if fore_style.color else ColorTriplet(255, 0, 255) ) - back_color = ( back_style.color.get_truecolor() if back_style.color @@ -160,8 +158,8 @@ class Bar(JupyterMixin): completed = min(self.total, max(0, self.completed)) legacy_windows = console.legacy_windows - bar = "▓" if legacy_windows else "━" - half_bar_right = "░" if legacy_windows else "╸" + bar = "─" if legacy_windows else "━" + half_bar_right = " " if legacy_windows else "╸" half_bar_left = " " if legacy_windows else "╺" complete_halves = ( int(width * 2 * completed / self.total) if self.total else width * 2 diff --git a/rich/box.py b/rich/box.py index 92cb492e..f100d8b1 100644 --- a/rich/box.py +++ b/rich/box.py @@ -143,6 +143,24 @@ class Box: return "".join(parts) +class PlatformDefaultBox(Box): + """A sentinel to be replaced with an appropriate box for the platform.""" + + +PLATFORM_DEFAULT: Box = PlatformDefaultBox( + """\ ++--+ +| || +|-+| +| || +|-+| +|-+| +| || ++--+ +""" +) + + ASCII: Box = Box( """\ +--+ @@ -334,13 +352,10 @@ DOUBLE_EDGE: Box = Box( if __name__ == "__main__": # pragma: no cover from .console import Console - from .panel import Panel from .table import Table from .text import Text from . import box - import sys - console = Console(record=True) table = Table(width=80, show_footer=True, style="dim", border_style="not dim") diff --git a/rich/console.py b/rich/console.py index 2e49eef4..6ebe686e 100644 --- a/rich/console.py +++ b/rich/console.py @@ -934,6 +934,7 @@ class Console: output: List[str] = [] append = output.append color_system = self._color_system + legacy_windows = self.legacy_windows buffer = self._buffer[:] if self.record: with self._record_buffer_lock: @@ -943,7 +944,13 @@ class Console: for line in Segment.split_and_crop_lines(buffer, self.width, pad=False): for text, style, is_control in line: if style and not is_control: - append(style.render(text, color_system=color_system)) + append( + style.render( + text, + color_system=color_system, + legacy_windows=legacy_windows, + ) + ) else: if not (not_terminal and is_control): append(text) diff --git a/rich/rule.py b/rich/rule.py index 661683d4..e5bfd423 100644 --- a/rich/rule.py +++ b/rich/rule.py @@ -35,7 +35,7 @@ class Rule(JupyterMixin): ) -> RenderResult: width = options.max_width - character = "-" if console.legacy_windows else (self.character or "─") + character = self.character or "─" if not self.title: yield Text(character * width, self.style) diff --git a/rich/style.py b/rich/style.py index b54ad5d4..bc4f85a4 100644 --- a/rich/style.py +++ b/rich/style.py @@ -491,6 +491,7 @@ class Style: text: str = "", *, color_system: Optional[ColorSystem] = ColorSystem.TRUECOLOR, + legacy_windows: bool = False, ) -> str: """Render the ANSI codes for the style. @@ -505,7 +506,7 @@ class Style: return text attrs = self._make_ansi_codes(color_system) rendered = f"\x1b[{attrs}m{text}\x1b[0m" if attrs else text - if self._link: + if self._link and not legacy_windows: rendered = ( f"\x1b]8;id={self._link_id};{self._link}\x1b\\{rendered}\x1b]8;;\x1b\\" ) diff --git a/rich/table.py b/rich/table.py index ccee4203..6204e0a7 100644 --- a/rich/table.py +++ b/rich/table.py @@ -30,7 +30,6 @@ if TYPE_CHECKING: RenderableType, RenderResult, ) - from .containers import Lines @dataclass @@ -123,7 +122,7 @@ class Table(JupyterMixin): title: TextType = None, caption: TextType = None, width: int = None, - box: Optional[box.Box] = box.HEAVY_HEAD, + box: Optional[box.Box] = box.PLATFORM_DEFAULT, padding: PaddingDimensions = (0, 1), collapse_padding: bool = False, pad_edge: bool = True, @@ -532,9 +531,13 @@ class Table(JupyterMixin): ) ) ) - _box: Optional[box.Box] = ( - box.SQUARE if (console.legacy_windows and self.box) else self.box + + _box = ( + (box.SQUARE if console.legacy_windows else box.HEAVY_HEAD) + if isinstance(self.box, box.PlatformDefaultBox) + else self.box ) + # _box = self.box new_line = Segment.line() columns = self.columns @@ -563,7 +566,7 @@ class Table(JupyterMixin): ), ] if show_edge: - yield Segment(_box.get_top(widths), border_style) + yield _Segment(_box.get_top(widths), border_style) yield new_line else: box_segments = []