mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-24 16:23:36 +05:00
refactor: make format_dialog_content method public, use it in the extensions menu
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -12,13 +12,14 @@ import inspect
|
||||
import json
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, Type
|
||||
from typing import Dict, List, Optional, Type
|
||||
|
||||
from core.menus import Option
|
||||
from core.menus.base_menu import BaseMenu
|
||||
from extensions import EXTENSION_ROOT
|
||||
from extensions.base_extension import BaseExtension
|
||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||
from utils.logger import Logger
|
||||
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@@ -129,11 +130,14 @@ class ExtensionSubmenu(BaseMenu):
|
||||
header = f" [ {self.extension.metadata.get('display_name')} ] "
|
||||
color = COLOR_YELLOW
|
||||
count = 62 - len(color) - len(RESET_FORMAT)
|
||||
|
||||
wrapper = textwrap.TextWrapper(55, initial_indent="| ", subsequent_indent="| ")
|
||||
lines = wrapper.wrap(self.extension.metadata.get("description"))
|
||||
formatted_lines = [f"{line:<55} |" for line in lines]
|
||||
description_text = "\n".join(formatted_lines)
|
||||
line_width = 53
|
||||
description: List[str] = self.extension.metadata.get("description", [])
|
||||
description_text = Logger.format_content(
|
||||
description,
|
||||
line_width,
|
||||
border_left="|",
|
||||
border_right="|",
|
||||
)
|
||||
|
||||
menu = textwrap.dedent(
|
||||
f"""
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
"module": "gcode_shell_cmd_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "G-Code Shell Command",
|
||||
"description": "Allows to run a shell command from gcode."
|
||||
"description": ["Run a shell commands from gcode."]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"module": "klipper_backup_extension",
|
||||
"maintained_by": "Staubgeborener",
|
||||
"display_name": "Klipper-Backup",
|
||||
"description": "Backup all your klipper files in GitHub",
|
||||
"description": ["Backup all your Klipper files to GitHub"],
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
"module": "mainsail_theme_installer_extension",
|
||||
"maintained_by": "dw-0",
|
||||
"display_name": "Mainsail Theme Installer",
|
||||
"description": "Install Mainsail Themes maintained by the community."
|
||||
"description": ["Install Mainsail Themes maintained by the Mainsail community."]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"module": "pretty_gcode_extension",
|
||||
"maintained_by": "Kragrathea",
|
||||
"display_name": "PrettyGCode for Klipper",
|
||||
"description": "3D G-Code viewer for Klipper",
|
||||
"description": ["3D G-Code viewer for Klipper"],
|
||||
"updates": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"module": "moonraker_telegram_bot_extension",
|
||||
"maintained_by": "nlef",
|
||||
"display_name": "Moonraker Telegram Bot",
|
||||
"description": "Allows to control your printer with the Telegram messenger app.",
|
||||
"description": ["Control your printer with the Telegram messenger app."],
|
||||
"project_url": "https://github.com/nlef/moonraker-telegram-bot",
|
||||
"updates": true
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class Logger:
|
||||
dialog_color = Logger._get_dialog_color(title, custom_color)
|
||||
dialog_title = Logger._get_dialog_title(title, custom_title)
|
||||
dialog_title_formatted = Logger._format_dialog_title(dialog_title)
|
||||
dialog_content = Logger._format_dialog_content(content, LINE_WIDTH)
|
||||
dialog_content = Logger.format_content(content, LINE_WIDTH)
|
||||
top = Logger._format_top_border(dialog_color)
|
||||
bottom = Logger._format_bottom_border()
|
||||
|
||||
@@ -140,9 +140,12 @@ class Logger:
|
||||
return "\n"
|
||||
|
||||
@staticmethod
|
||||
def _format_dialog_content(content: List[str], line_width: int) -> str:
|
||||
border_left = "┃"
|
||||
border_right = "┃"
|
||||
def format_content(
|
||||
content: List[str],
|
||||
line_width: int,
|
||||
border_left: str = "┃",
|
||||
border_right: str = "┃",
|
||||
) -> str:
|
||||
wrapper = textwrap.TextWrapper(line_width)
|
||||
|
||||
lines = []
|
||||
|
||||
Reference in New Issue
Block a user