diff --git a/tests/text/test_format.py b/tests/text/test_format.py new file mode 100644 index 0000000..60cb362 --- /dev/null +++ b/tests/text/test_format.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 + +from wobbl_tools.text.format import format_string +from wobbl_tools.text import format + +formats = list(format.color_ansi.keys()) +formats.remove("rs") +formats.remove("reset") + +print("\n\nIs this shit looking right?\n") + +for format_name in formats: + print(f"{format_name.title().replace("_", " ")} text: {format_string(f"§{format_name}Text")}") diff --git a/wobbl_tools/text/text.py b/wobbl_tools/text/format.py similarity index 53% rename from wobbl_tools/text/text.py rename to wobbl_tools/text/format.py index 5208275..0bb15b3 100644 --- a/wobbl_tools/text/text.py +++ b/wobbl_tools/text/format.py @@ -1,17 +1,15 @@ #!/usr/bin/python3 import random -from . import buntcheck +from .buntcheck import color_ansi, get_text_colors def format_string( - text: str, - prefix: str = "§", - suffix: str = "", - auto_rs: bool = True + text: str, + prefix: str = "§", + suffix: str = "", + auto_rs: bool = True ): # formats the text e.g. text after "§red" is colored red - color_ansi = buntcheck.color_ansi - for color in color_ansi: text = text.replace(prefix + color + suffix, color_ansi[color]) @@ -21,23 +19,8 @@ def format_string( return text -msg_types_ncl = { - "info": "[info]: ", - "ok": format_string("[OK]: "), - "warning": format_string("[WARNING]: "), - "error": format_string("[ERROR]: ") -} - -msg_types = { - "info": "[info]: ", - "ok": format_string("[§green§boldOK§rs]: "), - "warning": format_string("§yellow§bold[WARNING]: ", auto_rs=False), - "error": format_string("§red§bold[ERROR]: ", auto_rs=False) -} - - def rainbow(text): # makes the string rainbow-colored - color_codes = buntcheck.get_text_colors() + color_codes = get_text_colors() text_out = "" @@ -59,42 +42,6 @@ def example(): # just an example of this script print(format_string(text)) -class Log: - def __init__(self, log_path: str=None, no_console: bool=False, no_colors: bool=False): - self.log_path = log_path - self.no_console = no_console - self.no_colors = no_colors - self.log = "" - - def write(self, msg: str, msg_type: str = "info", prefix: str = ""): - if self.no_colors: - msg = prefix + msg_types_ncl[msg_type] + msg - - else: - msg = prefix + msg_types[msg_type] + msg - msg += format_string("§rs") - - if not self.no_console: - print(msg) - - if self.log_path is not None: - log_file = open(self.log_path, "a") - log_file.write(msg + "\n") - log_file.close() - - self.log += msg + "\n" - - def read(self): - if self.log_path is not None: - log_file = open(self.log_path, "r") - log_content = log_file.read() - log_file.close() - return log_content - - else: - return self.log - - def asap(old: str, add: str, position: int): """ ASAP = Add String At Position @@ -138,7 +85,3 @@ def find_nth_occurrence(string: str, substring: str, n: int): rep = "b" * len(substring) return string.replace(substring, rep, n).find(substring) - - -if __name__ == "__main__": - example() diff --git a/wobbl_tools/text/log.py b/wobbl_tools/text/log.py new file mode 100644 index 0000000..55b74af --- /dev/null +++ b/wobbl_tools/text/log.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 + +from .format import format_string + +msg_types_ncl = { + "info": "[info]: ", + "ok": format_string("[OK]: "), + "warning": format_string("[WARNING]: "), + "error": format_string("[ERROR]: ") +} + +msg_types = { + "info": "[info]: ", + "ok": format_string("[§green§boldOK§rs]: "), + "warning": format_string("§yellow§bold[WARNING]: ", auto_rs=False), + "error": format_string("§red§bold[ERROR]: ", auto_rs=False) +} + + +class Log: + def __init__(self, log_path: str = None, no_console: bool = False, no_colors: bool = False): + self.log_path = log_path + self.no_console = no_console + self.no_colors = no_colors + self.log = "" + + def write(self, msg: str, msg_type: str = "info", prefix: str = ""): + if self.no_colors: + msg = prefix + msg_types_ncl[msg_type] + msg + + else: + msg = prefix + msg_types[msg_type] + msg + msg += format_string("§rs") + + if not self.no_console: + print(msg) + + if self.log_path is not None: + log_file = open(self.log_path, "a") + log_file.write(msg + "\n") + log_file.close() + + self.log += msg + "\n" + + def read(self): + if self.log_path is not None: + log_file = open(self.log_path, "r") + log_content = log_file.read() + log_file.close() + return log_content + + else: + return self.log \ No newline at end of file