From a75314d2ad3878af69cd90d45decb1360353ab75 Mon Sep 17 00:00:00 2001 From: OleSTEEP Date: Sat, 19 Oct 2024 02:44:51 +0300 Subject: [PATCH] vnrecode: ignore ansi escapes for string cleaning --- vnrecode/printer.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vnrecode/printer.py b/vnrecode/printer.py index a6046f9..19650aa 100644 --- a/vnrecode/printer.py +++ b/vnrecode/printer.py @@ -3,6 +3,7 @@ from pathlib import Path import colorama import sys import os +import re class Printer: """ @@ -26,7 +27,8 @@ class Printer: :param string: String to "clean" :return: "Clean" string """ - return string + " " * (os.get_terminal_size().columns - len(string)) + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + return string + " " * (os.get_terminal_size().columns - len(ansi_escape.sub('', string))) @staticmethod def win_ascii_esc(): @@ -56,18 +58,18 @@ class Printer: def warning(self, string: str): """ - Method prints string with decor for warning messages - :param string: String to print - :return: None - """ + Method prints string with decor for warning messages + :param string: String to print + :return: None + """ self.bar_print(self.clean_str(f"\r\033[93m!\033[0m {string}\033[49m")) def error(self, string: str): """ - Method prints string with decor for error messages - :param string: String to print - :return: None - """ + Method prints string with decor for error messages + :param string: String to print + :return: None + """ self.bar_print(self.clean_str(f"\r\033[31m\u2715\033[0m {string}\033[49m")) def files(self, source_path: Path, output_path: Path, comment: str):