printcolored 2.0__tar.gz → 2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.4
2
+ Name: printcolored
3
+ Version: 2.1
4
+ Requires-Dist: platformdirs
@@ -1,3 +1,5 @@
1
1
  from .core import printColored, colorGen, printl, printRGB, printRGBV, Theme, ThemeRGBV, formatfinder
2
+ from .guide import func_guide
3
+ from .display import display_formats
2
4
 
3
- __all__ = ["printColored", "colorGen", "printl", "printRGB", "printRGBV", "Theme", "ThemeRGBV", "formatfinder"]
5
+ __all__ = ["printColored", "colorGen", "printl", "printRGB", "printRGBV", "Theme", "ThemeRGBV", "formatfinder", "func_guide", "display_formats"]
@@ -0,0 +1,5 @@
1
+ from .guide import func_guide
2
+
3
+ if __name__ == '__main__':
4
+ func_guide()
5
+
@@ -11,17 +11,38 @@ except ImportError:
11
11
 
12
12
 
13
13
  from pathlib import Path
14
- from os.path import exists
15
14
  import json
15
+ from platformdirs import user_config_dir
16
16
 
17
- script_dir = Path(__file__).parent
18
- path = script_dir / "custom.json"
19
- with open(path, "r") as file:
20
- custom_formats = json.load(file)
17
+ CONFIG_DIR = Path(user_config_dir("printColored"))
18
+ CUSTOM_FORMATS_PATH = CONFIG_DIR / "custom.json"
19
+
20
+
21
+ def load_custom_formats():
22
+ if CUSTOM_FORMATS_PATH.exists():
23
+ with open(CUSTOM_FORMATS_PATH, "r") as file:
24
+ return json.load(file)
25
+ return {}
26
+
27
+
28
+ def save_custom_formats(formats):
29
+ CONFIG_DIR.mkdir(parents=True, exist_ok=True)
30
+ with open(CUSTOM_FORMATS_PATH, "w") as file:
31
+ json.dump(formats, file, indent=4)
32
+
33
+
34
+ def add_custom_format(name, value):
35
+ formats = load_custom_formats()
36
+ formats[name] = value
37
+ save_custom_formats(formats)
38
+ return formats
39
+
40
+
41
+ custom_formats = load_custom_formats()
21
42
 
22
43
 
23
44
  from . import Fonter
24
- from .formats import ansi_formats, html_colors
45
+ from formats import ansi_formats, html_colors
25
46
 
26
47
  _default_source_order = ("ansi_format","rgb_format","custom_format")
27
48
 
@@ -71,8 +92,10 @@ def _build_code(*formats_used, html_view="", source_order=()):
71
92
  return ";".join(code_list)
72
93
 
73
94
  def _rgb_validation(r,g,b):
74
- if r == "" or g == "" or b == "":
75
- raise ValueError("You cant enter an empty value!")
95
+ if r == "" and g == "" and b == "":
96
+ return ""
97
+ elif r == "" or g == "" or b == "":
98
+ raise ValueError("One or more RGB values are missing!")
76
99
  elif not r.isdigit() or not g.isdigit() or not b.isdigit():
77
100
  raise ValueError("You cant enter a non-digit!")
78
101
  elif int(r) > 255 or int(r) < 0 or int(g) > 255 or int(g) < 0 or int(b) > 255 or int(b) < 0:
@@ -250,9 +273,15 @@ def formatfinder(min, max): # made this to find new formats, theres nothing beyo
250
273
  elif min == "font" or max == "font":
251
274
  for key, value in Fonter.fonts.items():
252
275
  print(f"{key}: {value}")
276
+ elif min == "decors" or max == "decors":
253
277
  for key, value in Fonter.decorators.items():
254
278
  print(f"{key}: {value}")
255
- else:
279
+ elif min == "ansi_dict" or max == "ansi_dict":
256
280
  for key, value in ansi_formats.items():
257
281
  print(f"\033[{value}m{key}\033[0m")
258
-
282
+ elif min == "html_dict" or max == "html_dict":
283
+ for key, value in html_colors.items():
284
+ print(f"\033[38;2;{value}m{key}\033[0m")
285
+ elif min == "custom_dict" or max == "custom_dict":
286
+ for key, value in custom_formats.items():
287
+ print(f"\033[{value}m{key}\033[0m")
@@ -0,0 +1,45 @@
1
+ from .core import formatfinder
2
+
3
+ def ansi_range():
4
+ print("All possible formats in range of 1-107:")
5
+ formatfinder("1","107")
6
+
7
+ def all_ansi_dict_formats():
8
+ print("All available formats:")
9
+ formatfinder("ansi_dict","")
10
+
11
+ def all_html_formats():
12
+ print("All HTML formats:")
13
+ formatfinder("html_dict","")
14
+
15
+ def all_custom_formats():
16
+ print("All custom formats:")
17
+ formatfinder("custom_dict","")
18
+
19
+ def all_fonts():
20
+ print("All fonts available:")
21
+ formatfinder(" ","font")
22
+
23
+ def all_decors():
24
+ print("All decorators available:")
25
+ formatfinder(" ","decors")
26
+
27
+ display = {
28
+ "all_ansi_formats": ansi_range,
29
+ "ansi_dict": all_ansi_dict_formats,
30
+ "html_dict": all_html_formats,
31
+ "custom_dict": all_custom_formats,
32
+ "fonts": all_fonts,
33
+ "decorators": all_decors
34
+ }
35
+
36
+
37
+ def display_formats(selected_source=None):
38
+ if selected_source:
39
+ if selected_source in display:
40
+ display[selected_source]()
41
+ else:
42
+ raise ValueError(f"{selected_source} Not a valid format source!")
43
+ else:
44
+ for source in display:
45
+ display[source]()
@@ -0,0 +1,134 @@
1
+ from . import core as pc
2
+ from .core import printColored, colorGen, printl, printRGB, printRGBV, Theme, ThemeRGBV
3
+
4
+ _deco = pc.Theme("green", "bold")
5
+ _deco2 = pc.Theme("bright_blue", "bold")
6
+ _deco3 = pc.Theme("bright_yellow")
7
+ _border = "--------------------------------"
8
+
9
+
10
+ def _guide_printColored():
11
+ _deco.print(_border)
12
+ print("printColored()")
13
+ printColored("Example use of printColored()".center(32), "green", "bold", "italic")
14
+ print("Main function, enter text, then formats, and the text will come formatted based on the provided formats")
15
+ print("Take a look at the dictionary and enter formats to use")
16
+ _deco.print(_border)
17
+
18
+
19
+ def _guide_colorGen():
20
+ _deco.print(_border)
21
+ print("colorGen()")
22
+ print(
23
+ f"{colorGen('red', 'bold')} Example use "
24
+ f"{colorGen('', 'strikethrough', 'blue')}of colorGen()"
25
+ f"{colorGen('')}"
26
+ )
27
+
28
+ genformat1 = colorGen("bright_white", "highlight_blue")
29
+ genformat2 = colorGen("", "yellow", "highlight_green", "underline")
30
+ print(f" {genformat1}Example 2 {genformat2}of colorGen(){colorGen('')}")
31
+ print("This is used to enter many formats in the same line")
32
+ _deco.print(_border)
33
+
34
+
35
+ def _guide_printl():
36
+ _deco.print(_border)
37
+ print("printl()")
38
+ printl(("Example", "use", "of", "printl()"), ("green", ("36", "italic"), "yellow", "magenta"), sepr=" ")
39
+ print("Printl is used to print many text in same line each with their own formats")
40
+ _deco.print(_border)
41
+
42
+
43
+ def _guide_printRGB():
44
+ _deco.print(_border)
45
+ print("printRGB()")
46
+ printRGB("Example use of printRGB()".center(32), "255", "0", "255", "bold", view="")
47
+ printRGB("Example 2 of printRGB()".center(32), "0", "255", "255", view="bg")
48
+ print("Notice how it can only display either")
49
+ print("foreground or background at one time")
50
+ print("You can also add formats to it".center(32))
51
+ _deco.print(_border)
52
+
53
+
54
+ def _guide_printRGBV():
55
+ _deco.print(_border)
56
+ print("printRGBV()")
57
+ printRGBV("Example use of printRGBV()".center(32), "0", "255", "0", "0", "0", "255", "")
58
+ printRGBV("Example 2 of printRGBV()".center(32), "0", "0", "0", "255", "0", "255", "italic")
59
+ print("It can display both foreground and background")
60
+ print("and also add formats".center(32))
61
+ print("Note that sometimes the background")
62
+ print("color blocks the foreground color")
63
+ _deco.print(_border)
64
+
65
+
66
+ def _guide_theme():
67
+ _deco.print(_border)
68
+ print("Theme")
69
+ deadly = Theme("brightred", "double_underline", "bold")
70
+ deadly.print("Example use of Theme class")
71
+ print("It can be used for formats that you use many times")
72
+
73
+ deadly.add("strikethrough")
74
+ deadly.print("Example of add(*formats)")
75
+
76
+ deadly.remove("double_underline", "strikethrough")
77
+ deadly.print("Example of remove(*formats)")
78
+
79
+ deadly.overwrite("highlight_brightred", "underline")
80
+ deadly.print("Example of overwrite(*formats)")
81
+
82
+ deadly.showUsed()
83
+ print("showUsed() displays the current formats")
84
+ _deco.print(_border)
85
+
86
+
87
+ def _guide_theme_rgbv():
88
+ _deco.print(_border)
89
+ print("ThemeRGBV")
90
+ classified = ThemeRGBV("255", "255", "255", "0", "0", "0", "")
91
+ classified.print("Example of printRGBV(r,g,b,r2,g2,b2,*formats)")
92
+ print("It can change both foreground and background")
93
+ print("and you can choose to use one or both")
94
+
95
+ classified.add("bold", "underline")
96
+ classified.print("Example of add(*formats)")
97
+
98
+ classified.remove("underline")
99
+ classified.print("Example of remove(*formats)")
100
+ print("Adding/removing only affects formats")
101
+
102
+ classified.overwrite("0", "0", "0", "255", "255", "255", "strikethrough")
103
+ classified.print("Example of overwrite(r,g,b,r2,g2,b2,*new)")
104
+ print("Overwrite rewrites the whole object")
105
+
106
+ classified.showUsed()
107
+ print("showUsed() displays the current settings")
108
+ _deco.print(_border)
109
+
110
+
111
+ GUIDE = {
112
+ "printColored": _guide_printColored,
113
+ "colorGen": _guide_colorGen,
114
+ "printl": _guide_printl,
115
+ "printRGB": _guide_printRGB,
116
+ "printRGBV": _guide_printRGBV,
117
+ "Theme": _guide_theme,
118
+ "ThemeRGBV": _guide_theme_rgbv,
119
+ }
120
+
121
+
122
+ def func_guide(selected_function=None):
123
+ if selected_function:
124
+ if selected_function in GUIDE:
125
+ GUIDE[selected_function]()
126
+ else:
127
+ raise ValueError(f"{selected_function} Not a valid guide section!")
128
+ else:
129
+ for section in GUIDE:
130
+ GUIDE[section]()
131
+ _deco.print(_border)
132
+ _deco2.print(_border)
133
+ print("Thanks for reading!")
134
+ _deco2.print(_border)
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.4
2
+ Name: printcolored
3
+ Version: 2.1
4
+ Requires-Dist: platformdirs
@@ -3,8 +3,11 @@ printColored/Fonter.py
3
3
  printColored/__init__.py
4
4
  printColored/__main__.py
5
5
  printColored/core.py
6
+ printColored/display.py
6
7
  printColored/formats.py
8
+ printColored/guide.py
7
9
  printcolored.egg-info/PKG-INFO
8
10
  printcolored.egg-info/SOURCES.txt
9
11
  printcolored.egg-info/dependency_links.txt
12
+ printcolored.egg-info/requires.txt
10
13
  printcolored.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ platformdirs
@@ -0,0 +1,8 @@
1
+ [project]
2
+ name = "printcolored"
3
+ version = "2.1"
4
+ dependencies = ["platformdirs"]
5
+
6
+ [build-system]
7
+ requires = ["setuptools"]
8
+ build-backend = "setuptools.build_meta"
printcolored-2.0/PKG-INFO DELETED
@@ -1,3 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: printcolored
3
- Version: 2.0
@@ -1,163 +0,0 @@
1
- from .core import *
2
-
3
- if __name__ == '__main__':
4
- deco = Theme("green", "bold")
5
- deco2 = Theme("bright_blue", "bold")
6
- deco3 = Theme("bright_yellow")
7
- border = "--------------------------------"
8
- deco.print(border)
9
-
10
- choice = True if input("Do you want to see all available formats?(Y/N): ").lower() == "y" else False
11
- if choice:
12
- print("All available formats:")
13
- formatfinder(" "," ")
14
-
15
- deco.print(border)
16
- choice = True if input("Do you want to see all existing formats in range 1-107?(Y/N): ").lower() == "y" else False
17
- if choice:
18
- print("All possible formats in range of 1-107:")
19
- formatfinder("1","107")
20
-
21
- deco.print(border)
22
- choice = True if input("Do you want to see all Fonter and decorators in the extra file?(Y/N): ").lower() == "y" else False
23
- if choice:
24
- print("All Fonter + decorators available:")
25
- formatfinder(" ","font")
26
-
27
- deco.print(border)
28
-
29
- deco2.print(border)
30
- print("Guide for using the functions:")
31
- deco2.print(border)
32
-
33
- # main functions:
34
-
35
- # printColored()
36
- deco.print(border)
37
- print("Page 1:")
38
- printColored("Example use of printColored()".center(32), "green","bold","italic")
39
- print("Main function, enter text, then formats, and the text will come formatted based on the provided formats")
40
- print("Take a look at the dictionary and enter formats to use")
41
- deco.print(border)
42
- input("Press enter to continue...")
43
-
44
-
45
- # colorGen()
46
- deco.print(border)
47
- print("Page 2:")
48
- print(
49
- f"{colorGen('red', 'bold')} Example use "
50
- f"{colorGen('', 'strikethrough', 'blue')}of colorGen()"
51
- f"{colorGen('')}"
52
- )
53
-
54
-
55
- genformat1 = colorGen("bright_white", "highlight_blue")
56
- genformat2 = colorGen("", "yellow", "highlight_green", "underline")
57
- print(f" {genformat1}Example 2 {genformat2}of colorGen(){colorGen('')}")
58
- print("This is used to enter many formats in the same line")
59
- deco.print(border)
60
- input("Press enter to continue...")
61
-
62
-
63
- # printl()
64
- deco.print(border)
65
- print("Page 3:")
66
- printl(("Example", "use", "of", "printl()"),("green", ("36", "italic"), "yellow", "magenta"), sepr=" ")
67
- print("Printl is used to print many text in same line each with their own formats")
68
- deco.print(border)
69
- input("Press enter to continue...")
70
-
71
- # printRGB()
72
- deco.print(border)
73
- print("Page 4:")
74
- printRGB("Example use of printRGB()".center(32), "255", "0", "255", "bold"," ")
75
- printRGB("Example 2 of printRGB()".center(32), "0", "255", "255", "","bg")
76
- print("Notice how it can only display either")
77
- print("foreground or background at one time")
78
- print("You can also add formats to it".center(32))
79
- deco.print(border)
80
- input("Press enter to continue...")
81
-
82
-
83
- # printRGBV()
84
- deco.print(border)
85
- print("Page 5:")
86
- printRGBV("Example use of printRGBV()".center(32), "0", "255", "0", "0", "0", "255", "")
87
- printRGBV("Example 2 of printRGBV()".center(32), "0", "0", "0", "255", "0", "255", "italic")
88
- print("It can display both foreground and background")
89
- print("and also add formats".center(32))
90
- print("Note that sometimes the background")
91
- print("color blocks the foreground color")
92
- deco.print(border)
93
- input("Press enter to continue...")
94
-
95
-
96
- # Theme
97
- deco.print(border)
98
- print("Page 6:")
99
- deadly = Theme("brightred", "double_underline", "bold")
100
- deadly.print("Example use of Theme class")
101
- print("It can be used for formats that you use many times")
102
-
103
- deadly.add("strikethrough")
104
- deadly.print("Example of add(*formats)")
105
-
106
- deadly.remove("double_underline", "strikethrough")
107
- deadly.print("Example of remove(*formats)")
108
-
109
- deadly.overwrite("highlight_brightred", "underline")
110
- deadly.print("Example of overwrite(*formats)")
111
-
112
- deadly.showUsed()
113
- print("showUsed() displays the current formats")
114
- deco.print(border)
115
- input("Press enter to continue...")
116
-
117
-
118
- # ThemeRGBV
119
- deco.print(border)
120
- print("Page 7:")
121
- classified = ThemeRGBV("255", "255", "255", "0", "0", "0", "")
122
- classified.print("Example of printRGBV(r,g,b,r2,g2,b2,*formats)")
123
- print("It can change both foreground and background")
124
- print("and you can choose to use one or both")
125
-
126
- classified.add("bold", "underline")
127
- classified.print("Example of add(*formats)")
128
-
129
- classified.remove("underline")
130
- classified.print("Example of remove(*formats)")
131
- print("Adding/removing only affects formats")
132
-
133
- classified.overwrite("0", "0", "0", "255", "255", "255", "strikethrough")
134
- classified.print("Example of overwrite(r,g,b,r2,g2,b2,*new)")
135
- print("Overwrite rewrites the whole object")
136
-
137
- classified.showUsed()
138
- print("showUsed() displays the current settings")
139
- deco.print(border)
140
- input("Press enter to continue...")
141
-
142
-
143
- deco.print(border)
144
- deco2.print(border)
145
- print("Thanks for reading!")
146
- deco2.print(border)
147
-
148
- deco3.print(border)
149
- print("BONUS: Custom formats using either ANSI or RGB")
150
- key = "placeholder"
151
- while key.lower() != "_exit_":
152
- key = input("Enter new key (_exit_ to leave): ")
153
- if key.lower() != "_exit_":
154
- custom_formats[key] = input(f"Enter a value for {key}: ")
155
- while custom_formats[key].replace(";", "").isdigit() == False:
156
- print("Invalid code!")
157
- print("The code must have digits only (; is an exception)")
158
- custom_formats[key] = input(f"Enter a value for {key}: ")
159
- else:
160
- break
161
- with open("custom.json", "w") as file:
162
- json.dump(custom_formats, file, indent=4)
163
- deco3.print(border)
@@ -1,3 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: printcolored
3
- Version: 2.0
@@ -1,7 +0,0 @@
1
- [project]
2
- name = "printcolored"
3
- version = "2.0"
4
-
5
- [build-system]
6
- requires = ["setuptools"]
7
- build-backend = "setuptools.build_meta"
File without changes