1- import sys
2- import traceback # for tcprint .err()
3- # colorama определяет ansi-коды, изменяет output, добавляет синтаксис. кроссплатформенная
1+ import sys # for ctprint.err()
2+ import traceback # for ctprint .err()
3+ # colorama - makes ANSI escape character sequences (for producing colored terminal text and cursor positioning) work under MS Windows.
44from colorama import init , Fore , Back
5- from help_message import help_message as h_m # класс со стрингами
6- # colorama autoreset автоматически возвращает к дефолтным системным параметрам
5+ from . help_message import h_m # экземпляр класса со стрингами
6+ # colorama autoreset=True - automatically back to default color
77init (autoreset = True )
88
9- # from tcprint import tcp, tdecode, terr, tlog # tcprint imports
9+ # from ctprint import ctp, ctdecode, cterr, ctlog # ctprint imports
1010
1111
1212tags : dict [str , dict [str , str ]] = {
2929}
3030
3131
32- class tcprint ():
32+ class ctprint ():
3333
34- def __init__ (self , string : str = None ) -> None :
34+ def __init__ (self , * strings : str ) -> None :
3535 self .tags = tags
3636
37- if string :
38- print (self .decode (string ))
37+ if strings :
38+ print (self .decode (* strings ))
3939
40- def decode (self , * strings : str ) -> str : # *args for tcprint .decode(string1, string2, string3)
40+ def decode (self , * strings : str ) -> str : # *args for ctprint .decode(string1, string2, string3)
4141
4242 result_string = ''
4343 for string in strings :
@@ -49,14 +49,14 @@ def decode(self, *strings: str) -> str: # *args for tcprint.decode(string1, str
4949 result_string += string # натягивает стринги друг на друга
5050 return result_string
5151
52- def err (self , exception = None , comment :any = '' ) -> None :
52+ def err (self , exception = None , comment : any = '' ) -> None :
5353 if comment :
5454 comment = f" comment: { str (comment )} "
5555 exc_type , exc_value , exc_traceback = sys .exc_info ()
5656 # берёт тб последней ошибки. хорошо бы добавить проверку по exception
5757 ex_tb = traceback .extract_tb (exc_traceback , limit = 1 )[0 ]
5858
59- print (self .decode ( # exception не проходит через decode(), чтобы в exception были видны теги
59+ print (self .decode ( # the exception is not decoded so that the tags are visible in it
6060 f"\n <bw>>>>>>>[Error]>>>> in: { ex_tb .name } line: { ex_tb .lineno } -> /> <red>{ ex_tb .line } <bw>>{ comment } <plain><white>" ), str (exception ), self .decode (f"\n <bg_white><black>[file]>> <plain> { ex_tb .filename } " ))
6161
6262 def log (self , ** vars ) -> None :
@@ -66,44 +66,40 @@ def log(self, **vars) -> None:
6666
6767 def help () -> None :
6868 help_msg = h_m .help_info + h_m .description + h_m .tags + h_m .methods
69- print (tcprint ().decode (help_msg ).replace (
70- 'PRE' , '' )) # PRE - разделяет теги
69+ print (ctprint ().decode (help_msg ).replace (
70+ 'PRE' , '' )) # PRE - separates the tags
7171
72- if input (tdecode ("""
72+ if input (ctdecode ("""
7373 <magenta>Press <bw> Y /><magenta> if u wanna see short live example: />""" )).lower () == 'y' :
7474
75- print (tcprint ().decode (h_m .test_example ).replace ('PRE' , '' ))
76- tcprint ("<info> def test() output:/>\n " )
75+ print (ctprint ().decode (h_m .test_example ).replace ('PRE' , '' ))
76+ ctprint ("<info> def test() output:/>\n " )
7777 test ()
7878
79- tcprint (h_m .ending )
79+ ctprint (h_m .ending )
8080
8181
8282# for imports
83- tcp = tcprint
84- terr = tcp ().err
85- tdecode = tcp ().decode
86- tlog = tcp ().log
83+ ctp = ctprint
84+ cterr = ctp ().err
85+ ctdecode = ctp ().decode
86+ ctlog = ctp ().log
8787
8888# example:
8989# ./test.py
90- # from tcprint import tcp, terr, tdecode
90+ # from ctprint import ctp, cterr, ctdecode
9191
92- # tcp .help() # print help message
92+ # ctp .help() # print help message
9393
9494
9595def test (): # usage example
9696
9797 try :
9898
99- tcp ('<bw> b&w !!! /><magenta> magenta <plain> plain <green>green />etc' )
99+ ctp ('<bw> b&w !!! /><magenta> magenta <plain> plain <green>green />etc' )
100100 1 / 0 # for error's view example
101101
102102 except Exception as _ex :
103103
104- # terr(Exception, your_comment)
105- terr (_ex , [{'excepted' : 3.1415926535 }])
106-
107-
108- if __name__ == '__main__' :
109- tcp .help ()
104+ # cterr(Exception, your_comment)
105+ cterr (_ex , [{'excepted' : 3.1415926535 }])
0 commit comments