feat(bot): 💄 Align differences in p.stats.
This commit is contained in:
@@ -369,8 +369,9 @@ class Mods(base.Cog):
|
||||
diff = value - prev_value
|
||||
|
||||
rows_with_diff[stat_i].append(
|
||||
str(value)
|
||||
+ (f" ({"+" if diff > 0 else ""}{diff})" if diff != 0 else "")
|
||||
value
|
||||
if diff == 0
|
||||
else (value, f"({"+" if diff > 0 else ""}{diff})")
|
||||
)
|
||||
|
||||
table = fmt.monospace_table(
|
||||
|
||||
@@ -57,7 +57,7 @@ def monospace_grid(values: list[str], space: int = 14) -> str:
|
||||
|
||||
|
||||
def monospace_table(
|
||||
rows: list[tuple],
|
||||
rows: list[list[str | tuple[str, str]]],
|
||||
headers: list | None = None,
|
||||
column_separator: str = "|",
|
||||
header_separator: str = "-",
|
||||
@@ -66,12 +66,17 @@ def monospace_table(
|
||||
) -> str:
|
||||
"""Creates a monospace table.
|
||||
|
||||
Creates a monospace table. Row columns can be either a string with the column's content, or a
|
||||
tuple with two items, being the first one aligned to the left and the second one aligned to the
|
||||
right. Non-string values will be converted to string using `str(value)`.
|
||||
|
||||
Args:
|
||||
rows (list[tuple]): The rows.
|
||||
rows (list[list[str | tuple[str, str]]]): The rows.
|
||||
headers (list | None, optional): The headers.
|
||||
column_separator (str, optional): The column separator. Defaults to "|".
|
||||
header_separator (str, optional): The header separator. Defaults to "-".
|
||||
intersection (str, optional): The intersection character where column and row separators meet.
|
||||
intersection (str, optional): The intersection character where column and row separators
|
||||
meet.
|
||||
padding (int, optional): The padding that each column has at its sides.
|
||||
|
||||
Returns:
|
||||
@@ -81,7 +86,14 @@ def monospace_table(
|
||||
max_sizes = [
|
||||
max(
|
||||
*(
|
||||
[len(str(row[i])) for row in rows]
|
||||
[
|
||||
(
|
||||
len(str(row[i]))
|
||||
if not isinstance(row[i], tuple)
|
||||
else (sum(len(str(item)) for item in row[i]) + 1)
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
+ ([len(headers[i])] if headers is not None else [])
|
||||
)
|
||||
)
|
||||
@@ -92,8 +104,15 @@ def monospace_table(
|
||||
return column_separator.join(
|
||||
[
|
||||
(" " * padding)
|
||||
+ str(col)
|
||||
+ (" " * (max_sizes[i] - len(str(col))))
|
||||
+ (
|
||||
(str(col) + (" " * (max_sizes[i] - len(str(col)))))
|
||||
if not isinstance(col, tuple)
|
||||
else (
|
||||
str(col[0])
|
||||
+ (" " * (max_sizes[i] - len(str(col[0])) - len(str(col[1]))))
|
||||
+ str(col[1])
|
||||
)
|
||||
)
|
||||
+ (" " * padding)
|
||||
for i, col in enumerate(row)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user