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 json
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path
|
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 import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from extensions import EXTENSION_ROOT
|
from extensions import EXTENSION_ROOT
|
||||||
from extensions.base_extension import BaseExtension
|
from extensions.base_extension import BaseExtension
|
||||||
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
|
||||||
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
@@ -129,11 +130,14 @@ class ExtensionSubmenu(BaseMenu):
|
|||||||
header = f" [ {self.extension.metadata.get('display_name')} ] "
|
header = f" [ {self.extension.metadata.get('display_name')} ] "
|
||||||
color = COLOR_YELLOW
|
color = COLOR_YELLOW
|
||||||
count = 62 - len(color) - len(RESET_FORMAT)
|
count = 62 - len(color) - len(RESET_FORMAT)
|
||||||
|
line_width = 53
|
||||||
wrapper = textwrap.TextWrapper(55, initial_indent="| ", subsequent_indent="| ")
|
description: List[str] = self.extension.metadata.get("description", [])
|
||||||
lines = wrapper.wrap(self.extension.metadata.get("description"))
|
description_text = Logger.format_content(
|
||||||
formatted_lines = [f"{line:<55} |" for line in lines]
|
description,
|
||||||
description_text = "\n".join(formatted_lines)
|
line_width,
|
||||||
|
border_left="|",
|
||||||
|
border_right="|",
|
||||||
|
)
|
||||||
|
|
||||||
menu = textwrap.dedent(
|
menu = textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
"module": "gcode_shell_cmd_extension",
|
"module": "gcode_shell_cmd_extension",
|
||||||
"maintained_by": "dw-0",
|
"maintained_by": "dw-0",
|
||||||
"display_name": "G-Code Shell Command",
|
"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",
|
"module": "klipper_backup_extension",
|
||||||
"maintained_by": "Staubgeborener",
|
"maintained_by": "Staubgeborener",
|
||||||
"display_name": "Klipper-Backup",
|
"display_name": "Klipper-Backup",
|
||||||
"description": "Backup all your klipper files in GitHub",
|
"description": ["Backup all your Klipper files to GitHub"],
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
"module": "mainsail_theme_installer_extension",
|
"module": "mainsail_theme_installer_extension",
|
||||||
"maintained_by": "dw-0",
|
"maintained_by": "dw-0",
|
||||||
"display_name": "Mainsail Theme Installer",
|
"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",
|
"module": "pretty_gcode_extension",
|
||||||
"maintained_by": "Kragrathea",
|
"maintained_by": "Kragrathea",
|
||||||
"display_name": "PrettyGCode for Klipper",
|
"display_name": "PrettyGCode for Klipper",
|
||||||
"description": "3D G-Code viewer for Klipper",
|
"description": ["3D G-Code viewer for Klipper"],
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"module": "moonraker_telegram_bot_extension",
|
"module": "moonraker_telegram_bot_extension",
|
||||||
"maintained_by": "nlef",
|
"maintained_by": "nlef",
|
||||||
"display_name": "Moonraker Telegram Bot",
|
"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",
|
"project_url": "https://github.com/nlef/moonraker-telegram-bot",
|
||||||
"updates": true
|
"updates": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,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_dialog_content(content, LINE_WIDTH)
|
dialog_content = Logger.format_content(content, LINE_WIDTH)
|
||||||
top = Logger._format_top_border(dialog_color)
|
top = Logger._format_top_border(dialog_color)
|
||||||
bottom = Logger._format_bottom_border()
|
bottom = Logger._format_bottom_border()
|
||||||
|
|
||||||
@@ -140,9 +140,12 @@ class Logger:
|
|||||||
return "\n"
|
return "\n"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format_dialog_content(content: List[str], line_width: int) -> str:
|
def format_content(
|
||||||
border_left = "┃"
|
content: List[str],
|
||||||
border_right = "┃"
|
line_width: int,
|
||||||
|
border_left: str = "┃",
|
||||||
|
border_right: str = "┃",
|
||||||
|
) -> str:
|
||||||
wrapper = textwrap.TextWrapper(line_width)
|
wrapper = textwrap.TextWrapper(line_width)
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
|
|||||||
Reference in New Issue
Block a user