mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-09 02:42:30 -05:00
Remove bordered() utility function (#5692)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in New Issue
Block a user