MCPcopy Create free account
hub / github.com/daniel2005d/mapXplore / AnsiPrint

Class AnsiPrint

utils/ansiprint.py:8–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import i18n.locale as locale
7
8class AnsiPrint:
9
10 @staticmethod
11 def printSetting(section:str):
12
13 title_message = Color.format(locale.get("config.table_key_title"))
14 title_value = Color.format(locale.get("config.table_value_title"))
15 data_list= []
16 option = Settings.setting[section]
17
18 for key in option:
19 key_color = Color.format(f"[blue]{key}[reset]")
20 key_value = Color.format(f"[green]{option[key]}[reset]")
21 data_list.append([key_color, key_value])
22
23 table_format = "mixed_outline"
24 table = tabulate(data_list, headers=[title_message, title_value], tablefmt=table_format)
25 print(table)
26
27
28 @staticmethod
29 def printResult(result:Result):
30 if result is not None:
31 table = tabulate(result.formatted_rows if result.formatted_len > 0 else result.rows, headers=result.headers, tablefmt="rounded_grid")
32 print(table)
33
34 @staticmethod
35 def print(text:str, end:str='\r\n')->None:
36 print(Color.format(text), end=end)
37
38 @staticmethod
39 def print_info(text:str)->None:
40 AnsiPrint.print(f"[yellow][!][bold] {text}[reset]")
41
42 @staticmethod
43 def print_error(text:str)->None:
44 AnsiPrint.print(f"[red][-][bold] {text}[reset]")
45 AnsiPrint.print_debug(text)
46
47
48 @staticmethod
49 def print_debug(exception:Exception=None):
50 if GeneralSetting().isDebug:
51 message = ""
52 if isinstance(exception,Exception):
53 import traceback
54 traceback.print_exc()
55 # exc_type, exc_value, exc_traceback = sys.exc_info()
56 # if exc_traceback:
57 # message = f"{exc_value} {exc_traceback}"
58 else:
59 message = str(exception)
60 AnsiPrint.print(f"[bold][yellow][debug][reset] [yellow]{message} [reset]")
61
62 @staticmethod
63 def print_success(text:str)->None:
64 AnsiPrint.print(f"[green][+][bold] {text}[reset]")
65

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected