33# e-mail: Behii@tutanota.com
44# ____________________________________________
55
6- # import part
6+ # ======== # import built-in library # ======== #
77from random import choice
88from os import name
99from json import load
1010
11- # random color
12-
13- def color ( * user_input ):
11+ # ======== # random front color # ======== #
12+ def color ( * user_input ) -> str :
13+ ''''''
1414 try :
15- # Opening json file that contain colors code in windows and linux
16- if name == 'nt' :
17- json_paths = __file__ .replace ('Rcolor.py' , 'colors\colors.json' )
15+ # ====== # Opening json file that contain colors code in windows and linux # ====== #
16+ if ( name == 'nt' ) :
17+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors\ \ colors.json' )
1818 else :
19- json_paths = __file__ .replace ('Rcolor.py' , 'colors/colors.json' )
19+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors/colors.json' )
2020 with open (json_paths , 'r' ) as f :
21- colors = load (f ).get ("colors" )
21+ colors : list [ str ] = load (f ).get ("colors" )
2222 user_input = list (user_input )
23- # make all item in user_input list to string
23+
24+ # ======== # make all item in user_input list to string # ======== #
2425 for i in user_input :
2526 if type (i ) == str :
2627 pass
2728 else :
2829 user_input [user_input .index (i )] = str (i )
2930
3031 user_input = '' .join (user_input )
31- random_color = choice (colors )
32+ random_color : str = choice (colors )
3233
3334 return random_color + user_input + '\033 [0m'
3435 except FileNotFoundError :
@@ -38,27 +39,27 @@ def color (*user_input):
3839 pass
3940 return ('\33 [31m' + f'Input type { type (i )} is not supported' + '\033 [0m' )
4041
41- # random background color
42- def background (* user_input ):
42+ # ======== # random background color # ======== #
43+ def background (* user_input ) -> str :
4344 try :
44- # Opening json file that contain colors code in windows and linux
45+ # ====== # Opening json file that contain colors code in windows and linux # ====== #
4546 if name == 'nt' :
46- json_paths = __file__ .replace ('Rcolor.py' , 'colors\b ackground_color.json' )
47+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors\b ackground_color.json' )
4748 else :
48- json_paths = __file__ .replace ('Rcolor.py' , 'colors/background_color.json' )
49+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors/background_color.json' )
4950 with open (json_paths , 'r' ) as f :
50- background_color = load (f ).get ("background_color" )
51+ background_color : list [ str ] = load (f ).get ("background_color" )
5152 user_input = list (user_input )
5253
53- # make all item in user_input list to string
54+ # ======== # make all item in user_input list to string # ======== #
5455 for i in user_input :
5556 if type (i ) == str :
5657 pass
5758 else :
5859 user_input [user_input .index (i )] = str (i )
5960
6061 user_input = '' .join (user_input )
61- random_color = choice (background_color )
62+ random_color : str = choice (background_color )
6263 return random_color + user_input + '\033 [0m'
6364 except FileNotFoundError :
6465 pass
@@ -67,19 +68,19 @@ def background (*user_input):
6768 pass
6869 return ('\33 [31m' + f'Input type { type (i )} is not supported' + '\033 [0m' )
6970
70- # random Windows color
71- def windows_color (* user_input ):
71+ # ======== # Random Windows color # ======== #
72+ def windows_color (* user_input ) -> str :
7273 try :
73- # Opening json file that contain colors code in windows and linux
74+ # ====== # Opening json file that contain colors code in windows and linux # ====== #
7475 if name == 'nt' :
75- json_paths = __file__ .replace ('Rcolor.py' , 'colors\Windows_color.json' )
76+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors\ \ Windows_color.json' )
7677 else :
77- json_paths = __file__ .replace ('Rcolor.py' , 'colors/Windows_color.json' )
78+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors/Windows_color.json' )
7879 with open (json_paths , 'r' ) as f :
79- windows_color = load (f ).get ("Windows_color" )
80+ windows_color : list [ str ] = load (f ).get ("Windows_color" )
8081 user_input = list (user_input )
8182
82- # make all item in user_input list to string
83+ # ======== # make all item in user_input list to string # ======== #
8384 for i in user_input :
8485 if type (i ) == str :
8586 pass
@@ -88,7 +89,7 @@ def windows_color(*user_input):
8889 from colorama import init
8990 init ()
9091 user_input = '' .join (user_input )
91- random_color = choice (windows_color )
92+ random_color : str = choice (windows_color )
9293 return random_color + user_input + '\033 [0m'
9394 except FileNotFoundError :
9495 pass
@@ -97,29 +98,29 @@ def windows_color(*user_input):
9798 pass
9899 return ('\33 [31m' + f'Input type { type (i )} is not supported' + '\033 [0m' )
99100
100- # random Windows background color
101- def windows_background (* user_input ):
101+ # ======== # Random Windows background color # ======== #
102+ def windows_background (* user_input ) -> str :
102103 try :
103- # Opening json file that contain colors code in windows and linux
104+ # ====== # Opening json file that contain colors code in windows and linux # ====== #
104105 if name == 'nt' :
105- json_paths = __file__ .replace ('Rcolor.py' , 'colors\Windows_background.json' )
106+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors\ \ Windows_background.json' )
106107 else :
107- json_paths = __file__ .replace ('Rcolor.py' , 'colors/Windows_background.json' )
108+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors/Windows_background.json' )
108109 with open (json_paths , 'r' ) as f :
109- Windows_background = load (f ).get ("Windows_background" )
110+ Windows_background : list [ str ] = load (f ).get ("Windows_background" )
110111 from colorama import init
111112 init ()
112113 user_input = list (user_input )
113114
114- # make all item in user input_list to string
115+ # ======== # make all item in user input_list to string # ======== #
115116 for i in user_input :
116117 if type (i ) == str :
117118 pass
118119 else :
119120 user_input [user_input .index (i )] = str (i )
120121
121122 user_input = '' .join (user_input )
122- random_color = choice (Windows_background )
123+ random_color : str = choice (Windows_background )
123124 return random_color + user_input + '\033 [0m'
124125 except FileNotFoundError :
125126 pass
@@ -128,26 +129,28 @@ def windows_background(*user_input):
128129 pass
129130 return ('\33 [31m' + f'Input type { type (i )} is not supported' + '\033 [0m' )
130131
131- # random style
132- def style (* user_input ):
133- # Opening json file that contain colors code in windows and linux
134- if name == 'nt' :
135- json_paths = __file__ .replace ('Rcolor.py' , 'colors\style1.json' )
136- else :
137- json_paths = __file__ .replace ('Rcolor.py' , 'colors/style1.json' )
138- try :
132+ # ======== # Random style # ======== #
133+ def style (* user_input ) -> str :
134+
135+ try :
136+ # ====== # Opening json file that contain colors code in windows and linux # ====== #
137+ if name == 'nt' :
138+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors\\ style1.json' )
139+ else :
140+ json_paths : str = __file__ .replace ('Rcolor.py' , 'colors/style1.json' )
139141 with open (json_paths , 'r' ) as f :
140- style1 = load (f ).get ("style1" )
142+ style1 : list [ str ] = load (f ).get ("style1" )
141143 user_input = list (user_input )
142- # make all item in user_input list to string
144+
145+ # ======== # make all item in user_input list to string # ======== #
143146 for i in user_input :
144147 if type (i ) == str :
145148 pass
146149 else :
147150 user_input [user_input .index (i )] = str (i )
148151
149152 user_input = '' .join (user_input )
150- random_color = choice (style1 )
153+ random_color : str = choice (style1 )
151154 return random_color + user_input + '\033 [0m'
152155 except FileNotFoundError :
153156 pass
@@ -156,8 +159,8 @@ def style(*user_input):
156159 pass
157160 return ('\33 [31m' + f'Input type { type (i )} is not supported' + '\033 [0m' )
158161
159- # Automatically detects the operating system and return the correct color
160- def auto_color (* user_input ):
162+ # ======== # Automatically detects the operating system and return the correct color # ======== #
163+ def auto_color (* user_input ) -> str :
161164 user_input = list (user_input )
162165 for i in user_input :
163166 if type (i ) == str :
@@ -171,8 +174,8 @@ def auto_color(*user_input):
171174 else :
172175 return color (user_input )
173176
174- # Automatically detects the operating system and return the correct background color
175- def auto_background (* user_input ):
177+ # ======== # Automatically detects the operating system and return the correct background color # ======== #
178+ def auto_background (* user_input ) -> str :
176179 user_input = list (user_input )
177180 for i in user_input :
178181 if type (i ) == str :
@@ -186,8 +189,8 @@ def auto_background(*user_input):
186189 else :
187190 return background (user_input )
188191
189- # return random color and background color
190- def color_background (* user_input ):
192+ # ======== # return random color and background color # ======== #
193+ def color_background (* user_input ) -> str :
191194 user_input = list (user_input )
192195 for i in user_input :
193196 if type (i ) == str :
@@ -198,8 +201,8 @@ def color_background (*user_input):
198201 user_input = '' .join (user_input )
199202 return auto_color (auto_background (user_input ))
200203
201- # return random color and style
202- def color_style (* user_input ):
204+ # ======== # return random color and style # ======== #
205+ def color_style (* user_input ) -> str :
203206 user_input = list (user_input )
204207 for i in user_input :
205208 if type (i ) == str :
@@ -210,8 +213,8 @@ def color_style (*user_input):
210213 user_input = '' .join (user_input )
211214 return auto_color (style (user_input ))
212215
213- # return random background color and style
214- def background_style (* user_input ):
216+ # ======== # return random background color and style # ======== #
217+ def background_style (* user_input ) -> str :
215218 user_input = list (user_input )
216219 for i in user_input :
217220 if type (i ) == str :
@@ -222,8 +225,8 @@ def background_style (*user_input):
222225 user_input = '' .join (user_input )
223226 return auto_background (style (user_input ))
224227
225- # return random color and background color and style
226- def color_background_style (* user_input ):
228+ # ======== # return random color and background color and style # ======== #
229+ def color_background_style (* user_input ) -> str :
227230 user_input = list (user_input )
228231 for i in user_input :
229232 if type (i ) == str :
0 commit comments