mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 00:33:37 +05:00
feat: implement option to center content in dialogs
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -87,6 +87,7 @@ class Logger:
|
|||||||
def print_dialog(
|
def print_dialog(
|
||||||
title: DialogType,
|
title: DialogType,
|
||||||
content: List[str],
|
content: List[str],
|
||||||
|
center_content: bool = False,
|
||||||
custom_title: str = None,
|
custom_title: str = None,
|
||||||
custom_color: DialogCustomColor = None,
|
custom_color: DialogCustomColor = None,
|
||||||
end: str = "\n",
|
end: str = "\n",
|
||||||
@@ -94,7 +95,7 @@ class Logger:
|
|||||||
dialog_color = Logger._get_dialog_color(title, custom_color)
|
dialog_color = Logger._get_dialog_color(title, custom_color)
|
||||||
dialog_title = Logger._get_dialog_title(title, custom_title)
|
dialog_title = Logger._get_dialog_title(title, custom_title)
|
||||||
dialog_title_formatted = Logger._format_dialog_title(dialog_title)
|
dialog_title_formatted = Logger._format_dialog_title(dialog_title)
|
||||||
dialog_content = Logger.format_content(content, LINE_WIDTH)
|
dialog_content = Logger.format_content(content, LINE_WIDTH, center_content)
|
||||||
top = Logger._format_top_border(dialog_color)
|
top = Logger._format_top_border(dialog_color)
|
||||||
bottom = Logger._format_bottom_border()
|
bottom = Logger._format_bottom_border()
|
||||||
|
|
||||||
@@ -143,6 +144,7 @@ class Logger:
|
|||||||
def format_content(
|
def format_content(
|
||||||
content: List[str],
|
content: List[str],
|
||||||
line_width: int,
|
line_width: int,
|
||||||
|
center_content: bool = False,
|
||||||
border_left: str = "┃",
|
border_left: str = "┃",
|
||||||
border_right: str = "┃",
|
border_right: str = "┃",
|
||||||
) -> str:
|
) -> str:
|
||||||
@@ -158,7 +160,13 @@ class Logger:
|
|||||||
if c == "\n\n" and i < len(content) - 1:
|
if c == "\n\n" and i < len(content) - 1:
|
||||||
lines.append(" " * line_width)
|
lines.append(" " * line_width)
|
||||||
|
|
||||||
formatted_lines = [
|
if not center_content:
|
||||||
f"{border_left} {line:<{line_width}} {border_right}" for line in lines
|
formatted_lines = [
|
||||||
]
|
f"{border_left} {line:<{line_width}} {border_right}" for line in lines
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
formatted_lines = [
|
||||||
|
f"{border_left} {line:^{line_width}} {border_right}" for line in lines
|
||||||
|
]
|
||||||
|
|
||||||
return "\n".join(formatted_lines)
|
return "\n".join(formatted_lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user