mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Remove bordered() utility function (#5692)
This commit is contained in:
parent
0f20f15c26
commit
51fa3f502e
@ -1580,5 +1580,5 @@ Miscellaneous
|
|||||||
- Updated features list in ``[p]serverinfo`` with the latest changes from Discord (:issue:`4116`)
|
- 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`)
|
- 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`)
|
- ``[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`)
|
- Fixed timestamp storage in few places in Red (:issue:`4017`)
|
||||||
|
|||||||
@ -31,7 +31,7 @@ from .utils._internal_utils import (
|
|||||||
fetch_latest_red_version_info,
|
fetch_latest_red_version_info,
|
||||||
send_to_owners_with_prefix_replaced,
|
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
|
import rich
|
||||||
from rich import box
|
from rich import box
|
||||||
|
|||||||
@ -200,71 +200,6 @@ def spoiler(text: str, escape_formatting: bool = True) -> str:
|
|||||||
return f"||{escape(text, formatting=escape_formatting)}||"
|
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(
|
def pagify(
|
||||||
text: str,
|
text: str,
|
||||||
delims: Sequence[str] = ["\n"],
|
delims: Sequence[str] = ["\n"],
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
import random
|
import random
|
||||||
import textwrap
|
|
||||||
from redbot.core.utils import (
|
from redbot.core.utils import (
|
||||||
chat_formatting,
|
|
||||||
bounded_gather,
|
bounded_gather,
|
||||||
bounded_gather_iter,
|
bounded_gather_iter,
|
||||||
deduplicate_iterables,
|
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():
|
def test_deduplicate_iterables():
|
||||||
expected = [1, 2, 3, 4, 5]
|
expected = [1, 2, 3, 4, 5]
|
||||||
inputs = [[1, 2, 1], [3, 1, 2, 4], [5, 1, 2]]
|
inputs = [[1, 2, 1], [3, 1, 2, 4], [5, 1, 2]]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user