From 0af1d7680a27e44d5001f357d925c4ceabc8f3c4 Mon Sep 17 00:00:00 2001 From: lasseedfast Date: Thu, 18 Sep 2025 15:13:35 +0200 Subject: [PATCH] Add initial implementation of color printing utility with functions for various colors and error handling --- .env | 2 + __init__.py | 7 ++ __pycache__/__init__.cpython-310.pyc | Bin 0 -> 394 bytes build/lib/colorprinter/__init__.py | 0 build/lib/colorprinter/print_color.py | 102 ++++++++++++++++++ colorprinter.egg-info/PKG-INFO | 63 +++++++++++ colorprinter.egg-info/SOURCES.txt | 9 ++ colorprinter.egg-info/dependency_links.txt | 1 + colorprinter.egg-info/top_level.txt | 1 + .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 187 bytes .../__pycache__/print_color.cpython-310.pyc | Bin 0 -> 2683 bytes 11 files changed, 185 insertions(+) create mode 100644 .env create mode 100644 __init__.py create mode 100644 __pycache__/__init__.cpython-310.pyc create mode 100644 build/lib/colorprinter/__init__.py create mode 100644 build/lib/colorprinter/print_color.py create mode 100644 colorprinter.egg-info/PKG-INFO create mode 100644 colorprinter.egg-info/SOURCES.txt create mode 100644 colorprinter.egg-info/dependency_links.txt create mode 100644 colorprinter.egg-info/top_level.txt create mode 100644 colorprinter/__pycache__/__init__.cpython-310.pyc create mode 100644 colorprinter/__pycache__/print_color.cpython-310.pyc diff --git a/.env b/.env new file mode 100644 index 0000000..d878548 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ + +ARANGO_PWD_ENV_MANAGER=jagskoterenv(Y) \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..802e415 --- /dev/null +++ b/__init__.py @@ -0,0 +1,7 @@ +try: + from colorprinter.colorprinter.print_color import * +except ImportError: + try: + from colorprinter.print_color import * + except ImportError: + print("Could not import colorprinter module") \ No newline at end of file diff --git a/__pycache__/__init__.cpython-310.pyc b/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..75e886d533b9d1f65c0c98e8239b5e3adc43a20d GIT binary patch literal 394 zcmZ{eu};G<5QfibP%BDN#l)C_B88!T0fdl%0SQ$=L5L}eunB=Uj?Rv%X6@53@ESY< zLslkU0SUpy83+Ss`M2)A^WCpUqjjKoS-n2I(fi&c-564GNY~6rs=ffhGPr^p5WPA0 zAlY)4L365sV_w5ea3}x( literal 0 HcmV?d00001 diff --git a/build/lib/colorprinter/__init__.py b/build/lib/colorprinter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/build/lib/colorprinter/print_color.py b/build/lib/colorprinter/print_color.py new file mode 100644 index 0000000..40c351e --- /dev/null +++ b/build/lib/colorprinter/print_color.py @@ -0,0 +1,102 @@ +def choose_color(last_color_index): + """ + Selects the next color in a predefined sequence of colors. + + Args: + last_color_index (int): The index of the last color used. + + Returns: + tuple: A tuple containing the ANSI escape code for the selected color (str) + and the index of the selected color (int). + """ + colors = { + "blue": "\033[94m", + "green": "\033[92m", + "yellow": "\033[93m", + "red": "\033[91m", + "purple": "\033[95m", + } + color_keys = list(colors.keys()) + color_index = (last_color_index + 1) % len(color_keys) + color = color_keys[color_index] + return colors[color], color_index + + +def print_green(*args): + """ + Prints the provided arguments in green. + """ + text = "" + for arg in args: + text += str(arg) + " " + print(f"\033[92m{text}\033[0m") + + +def print_red(*args): + """ + Prints the provided arguments in red. + """ + text = "" + for arg in args: + text += str(arg) + " " + print(f"\033[91m{text}\033[0m") + + +def print_yellow(*args): + """ + Prints the provided arguments in yellow. + """ + text = "" + for arg in args: + text += str(arg) + " " + print(f"\033[93m{text}\033[0m") + + +def print_blue(*args): + """ + Prints the provided arguments in blue. + """ + text = "" + for arg in args: + text += str(arg) + " " + print(f"\033[94m{text}\033[0m") + + +def print_purple(*args): + """ + Prints the provided arguments in purple. + """ + text = "" + for arg in args: + text += str(arg) + " " + print(f"\033[95m{text}\033[0m") + + +def print_rainbow(*args): + """ + Prints the provided arguments in a rainbow of colors. + + Args: + *args: Variable length argument list. Each argument can be a string, list, or dictionary. + - If the argument is a list, each element in the list will be printed in a different color. + - If the argument is a dictionary, each key-value pair will be printed in a different color. + - If the argument is a string or any other type, it will be printed in a different color. + + Returns: + None + """ + color_index = -1 + text = "" + for arg in args: + if isinstance(arg, list): + for i in arg: + color_code, color_index = choose_color(color_index) + text += f"{color_code}{i}\033[0m " + elif isinstance(arg, dict): + for k, v in arg.items(): + color_code, color_index = choose_color(color_index) + text += f"{color_code}{k}: {v}\033[0m " + else: + color_code, color_index = choose_color(color_index) + text += f"{color_code}{arg}\033[0m " + print(text) diff --git a/colorprinter.egg-info/PKG-INFO b/colorprinter.egg-info/PKG-INFO new file mode 100644 index 0000000..d013c45 --- /dev/null +++ b/colorprinter.egg-info/PKG-INFO @@ -0,0 +1,63 @@ +Metadata-Version: 2.4 +Name: colorprinter +Version: 0.1.0 +Summary: A simple utility for printing text in various colors to the terminal +Home-page: https://github.com/lasseedfast/colorprinter +Author: Lasse Edfast +Author-email: lasse@edfast.se +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.6 +Description-Content-Type: text/markdown +License-File: LICENSE +Dynamic: author +Dynamic: author-email +Dynamic: classifier +Dynamic: description +Dynamic: description-content-type +Dynamic: home-page +Dynamic: license-file +Dynamic: requires-python +Dynamic: summary + +# Colorful Print Utility + +This Python module provides a simple utility for printing text in various colors to the terminal. It supports printing in green, red, yellow, blue, and purple, as well as a special "rainbow" mode that cycles through colors for each argument. +Use it as as you normaly use ```print()```. + +## Functions + +- `print_green(*args)`: Prints the given arguments in green color. +- `print_red(*args)`: Prints the given arguments in red color. +- `print_yellow(*args)`: Prints the given arguments in yellow color. +- `print_blue(*args)`: Prints the given arguments in blue color. +- `print_purple(*args)`: Prints the given arguments in purple color. +- `print_rainbow(*args)`: Prints each argument in a different color, cycling through the available colors. Supports nested lists and dictionaries. + +## Usage + +To use this module, simply import it and call the desired function with the text you want to print as arguments. Here's an example: + +`git clone https://github.com/lasseedfast/colorprinter` + +This will clone this repo as a folder to your computer. When you want to use the colorprinter, make sure that folder is in the same folder as you're working. Then you can use it like: + +```python +from colorprinter.print_color import print_green, print_rainbow + +print_green("This is in green!") +print_rainbow("This", "will", "be", "in", "multiple", "colors!") +``` + +Alternatively, you can import all functions at once using from print_color import \*. However, be cautious when using this approach as it imports all public names defined in the module, which can lead to conflicts with other modules or variables in your namespace.* + +## Customization +The colors are defined using ANSI escape codes. You can modify the choose_color function or the color codes within each print function if you wish to customize the colors. + +## Requirements +This module uses standard Python libraries only and should work on any system that supports Python and ANSI escape codes for terminal colors. + +## License +This project is open-sourced under the MIT License. Feel free to use, modify, and distribute as you see fit. + diff --git a/colorprinter.egg-info/SOURCES.txt b/colorprinter.egg-info/SOURCES.txt new file mode 100644 index 0000000..550f195 --- /dev/null +++ b/colorprinter.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +LICENSE +README.md +setup.py +colorprinter/__init__.py +colorprinter/print_color.py +colorprinter.egg-info/PKG-INFO +colorprinter.egg-info/SOURCES.txt +colorprinter.egg-info/dependency_links.txt +colorprinter.egg-info/top_level.txt \ No newline at end of file diff --git a/colorprinter.egg-info/dependency_links.txt b/colorprinter.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/colorprinter.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/colorprinter.egg-info/top_level.txt b/colorprinter.egg-info/top_level.txt new file mode 100644 index 0000000..a370d53 --- /dev/null +++ b/colorprinter.egg-info/top_level.txt @@ -0,0 +1 @@ +colorprinter diff --git a/colorprinter/__pycache__/__init__.cpython-310.pyc b/colorprinter/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..70660d2a6c74559ae6c1de0700846f245f0c0ce5 GIT binary patch literal 187 zcmd1j<>g`kg5`1tGC=fW5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;x_qerR!OQL(;H zVsUY*zDr_Beo=aAZfag}Vs43kKv8~rQDSaxYEfohdT~KfepYIBiGFa9ep+dPesX?J reo+BXrX;lpl@lMInU`4-AFo$Xd5gm)H$SB`C)EyQZ!r^)U||3N3`H@v literal 0 HcmV?d00001 diff --git a/colorprinter/__pycache__/print_color.cpython-310.pyc b/colorprinter/__pycache__/print_color.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dbcdc5f65d2b96ebfe8e3c56af95dd059a668821 GIT binary patch literal 2683 zcmb_e&u<(x6dup7-EKB*C?RbK6jMOzLYhqrs3NLRqZXm6)v9WMLkg-UYwu?0?99fV zO`2%-6#k1+sXd`w`3sQvFXqarXKqCTzGo+4n}D(hyz;Zh_Iv(pzxTe)CMRnS%1;-5 zS^pKi-{@nsxcIn%s;@%`N3b89RY$nOL(7CO0<^9OMFp)Vs^Sz{U)00|+CbFBB-&7% zUU3>{+6*QRN`Ov?dJ|ROfDnwVl0^~z7z|nN6zmy$?(DLmTR5U}&dJ@v-DNY*&@0@+ zn{|eM!3uxYDZGvg`_*Ux8`L<;icDlX*F0aBJe7}g-p-Ot@i^rX?<*-}Cr+i{T5b$v z+Lk=)*cE!AX7ra;S1*|!SxX|FKQtB|#;K5x`K36`8%z8vShoYvr>$t={#FAm#lEro zG9RdP#9lt=Cvu4|bJKxBnn!UOr(I)YxwUeeOWlt85>rC*4v>>|Z4L$4_Ar-pt{VIh zBmqTE_)?YuUUN<(cZro=kPr%bWL9)>TojCl#(w_f_`2e3Um=?l(Jwe$$xg zVC+FZRw zf*yPX;VFv{>hICSyCg0`oQUh{c(|-5AA?3udJ?p{g=Q^WK14@2Peivk9y$uTW7x<$ zPr_ES*hv4{A+qS*`Pm$jZ*qa*!J(uT39|r_rXzg$G^d2Q%}9@sAX)*XU8KoG$br|=PI-ct{u=Wd+Y2#t;hotuUC%zsXn zX0SdSR{ljdq#!LS#zJ5$d;|-}_wYvc2=jo#{UEHP3gUCT$BwuH2drgVCvee+6x2)n zn@GjcS^~SKvN=%fO4EbS(Z^cPMdl?Tz_A-ns;!Z~@T52-#xLf@L zZhu2C#pTTiUd{Vatp3-%?9I@XMCmrqa2{~(c3;l(c-%vocRt4Ttt^#h=EYwqCjae# za~FGj$6eyBMp)Kj9j7{v@IOS=;pm29N}o<&25~NXTFqg&QB`l#>=cO$B;J82S$x2w z^k1Q5k4muN~r%~%*cc7*@gg@zn(`ts-rkVR^&6@(ly@_7kpC+!OwAN}=3?Rb? tCiyDLaf;H3qNp{iMs_qQ-0(~FdM^`$M1F1<^)%L2o$C2&&Hn1OzX1#yqI3WN literal 0 HcmV?d00001