refactor: allow content to consist of paragraphs

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-05-03 20:00:48 +02:00
parent 40e382c9a1
commit 09dc961646

View File

@@ -8,6 +8,7 @@
# ======================================================================= # # ======================================================================= #
import textwrap import textwrap
from enum import Enum from enum import Enum
from typing import List
from utils.constants import ( from utils.constants import (
COLOR_WHITE, COLOR_WHITE,
@@ -85,7 +86,7 @@ class Logger:
@staticmethod @staticmethod
def print_dialog( def print_dialog(
title: DialogType, title: DialogType,
content: str, content: List[str],
custom_title: str = None, custom_title: str = None,
custom_color: DialogCustomColor = None, custom_color: DialogCustomColor = None,
) -> None: ) -> None:
@@ -138,11 +139,18 @@ class Logger:
return "\n" return "\n"
@staticmethod @staticmethod
def _format_dialog_content(content: str, line_width: int) -> str: def _format_dialog_content(content: List[str], line_width: int) -> str:
border_left = "" border_left = ""
border_right = "" border_right = ""
wrapper = textwrap.TextWrapper(line_width) wrapper = textwrap.TextWrapper(line_width)
lines = wrapper.wrap(content)
lines = []
for i, c in enumerate(content):
paragraph = wrapper.wrap(c)
lines.extend(paragraph)
if i < len(content) - 1:
lines.append(" " * line_width)
formatted_lines = [ formatted_lines = [
f"{border_left} {line:<{line_width}} {border_right}" for line in lines f"{border_left} {line:<{line_width}} {border_right}" for line in lines
] ]