diff --git a/docs/changelog_3_4_0.rst b/docs/changelog_3_4_0.rst index 5764d6eb7..2811feba4 100644 --- a/docs/changelog_3_4_0.rst +++ b/docs/changelog_3_4_0.rst @@ -1580,5 +1580,5 @@ Miscellaneous - Updated features list in ``[p]serverinfo`` with the latest changes from Discord (:issue:`4116`) - Simple version of ``[p]serverinfo`` now shows info about more detailed ``[p]serverinfo 1`` (:issue:`4121`) - ``[p]set nickname``, ``[p]set serverprefix``, ``[p]streamalert``, and ``[p]streamset`` commands now can be run by users with permissions related to the actions they're making (:issue:`4109`) -- `bordered()` now uses ``+`` for corners if keyword argument ``ascii_border`` is set to `True` (:issue:`4097`) +- ``bordered()`` now uses ``+`` for corners if keyword argument ``ascii_border`` is set to `True` (:issue:`4097`) - Fixed timestamp storage in few places in Red (:issue:`4017`) diff --git a/redbot/core/events.py b/redbot/core/events.py index 8aaed3e90..beb1eabab 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -31,7 +31,7 @@ from .utils._internal_utils import ( fetch_latest_red_version_info, send_to_owners_with_prefix_replaced, ) -from .utils.chat_formatting import inline, bordered, format_perms_list, humanize_timedelta +from .utils.chat_formatting import inline, format_perms_list, humanize_timedelta import rich from rich import box diff --git a/redbot/core/utils/chat_formatting.py b/redbot/core/utils/chat_formatting.py index 8a97c42f4..a36fb761d 100644 --- a/redbot/core/utils/chat_formatting.py +++ b/redbot/core/utils/chat_formatting.py @@ -200,71 +200,6 @@ def spoiler(text: str, escape_formatting: bool = True) -> str: return f"||{escape(text, formatting=escape_formatting)}||" -def bordered(*columns: Sequence[str], ascii_border: bool = False) -> str: - """Get two blocks of text inside borders. - - Note - ---- - This will only work with a monospaced font. - - Parameters - ---------- - *columns : `sequence` of `str` - The columns of text, each being a list of lines in that column. - ascii_border : bool - Whether or not the border should be pure ASCII. - - Returns - ------- - str - The bordered text. - - """ - borders = { - "TL": "+" if ascii_border else "┌", # Top-left - "TR": "+" if ascii_border else "┐", # Top-right - "BL": "+" if ascii_border else "└", # Bottom-left - "BR": "+" if ascii_border else "┘", # Bottom-right - "HZ": "-" if ascii_border else "─", # Horizontal - "VT": "|" if ascii_border else "│", # Vertical - } - - sep = " " * 4 # Separator between boxes - widths = tuple(max(len(row) for row in column) + 9 for column in columns) # width of each col - colsdone = [False] * len(columns) # whether or not each column is done - lines = [sep.join("{TL}" + "{HZ}" * width + "{TR}" for width in widths)] - - for line in itertools.zip_longest(*columns): - row = [] - for colidx, column in enumerate(line): - width = widths[colidx] - done = colsdone[colidx] - if column is None: - if not done: - # bottom border of column - column = "{HZ}" * width - row.append("{BL}" + column + "{BR}") - colsdone[colidx] = True # mark column as done - else: - # leave empty - row.append(" " * (width + 2)) - else: - column += " " * (width - len(column)) # append padded spaces - row.append("{VT}" + column + "{VT}") - - lines.append(sep.join(row)) - - final_row = [] - for width, done in zip(widths, colsdone): - if not done: - final_row.append("{BL}" + "{HZ}" * width + "{BR}") - else: - final_row.append(" " * (width + 2)) - lines.append(sep.join(final_row)) - - return "\n".join(lines).format(**borders) - - def pagify( text: str, delims: Sequence[str] = ["\n"], diff --git a/tests/core/test_utils.py b/tests/core/test_utils.py index 2bfe05900..69d22efd4 100644 --- a/tests/core/test_utils.py +++ b/tests/core/test_utils.py @@ -1,9 +1,7 @@ import asyncio import pytest import random -import textwrap from redbot.core.utils import ( - chat_formatting, bounded_gather, bounded_gather_iter, deduplicate_iterables, @@ -11,60 +9,6 @@ from redbot.core.utils import ( ) -def test_bordered_symmetrical(): - expected = textwrap.dedent( - """\ - ┌──────────────┐ ┌─────────────┐ - │one │ │four │ - │two │ │five │ - │three │ │six │ - └──────────────┘ └─────────────┘""" - ) - col1, col2 = ["one", "two", "three"], ["four", "five", "six"] - assert chat_formatting.bordered(col1, col2) == expected - - -def test_bordered_asymmetrical(): - expected = textwrap.dedent( - """\ - ┌──────────────┐ ┌──────────────┐ - │one │ │four │ - │two │ │five │ - │three │ │six │ - └──────────────┘ │seven │ - └──────────────┘""" - ) - col1, col2 = ["one", "two", "three"], ["four", "five", "six", "seven"] - assert chat_formatting.bordered(col1, col2) == expected - - -def test_bordered_asymmetrical_2(): - expected = textwrap.dedent( - """\ - ┌──────────────┐ ┌─────────────┐ - │one │ │five │ - │two │ │six │ - │three │ └─────────────┘ - │four │ - └──────────────┘ """ - ) - col1, col2 = ["one", "two", "three", "four"], ["five", "six"] - assert chat_formatting.bordered(col1, col2) == expected - - -def test_bordered_ascii(): - expected = textwrap.dedent( - """\ - +--------------+ +-------------+ - |one | |four | - |two | |five | - |three | |six | - +--------------+ +-------------+""" - ) - col1, col2 = ["one", "two", "three"], ["four", "five", "six"] - assert chat_formatting.bordered(col1, col2, ascii_border=True) == expected - - def test_deduplicate_iterables(): expected = [1, 2, 3, 4, 5] inputs = [[1, 2, 1], [3, 1, 2, 4], [5, 1, 2]]