eapyTool 0.3.1__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: eapyTool
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: A Python utility library for math, algebra, data structures, and everyday tools
5
5
  Project-URL: Homepage, https://github.com/eapy/eapy
6
6
  Project-URL: Repository, https://github.com/eapy/eapy
@@ -147,6 +147,11 @@ A Python utility library that extends the standard library with math, algebra, d
147
147
  ### Local Storage
148
148
  - `Storage` — persistent key-value store with subpath support
149
149
 
150
+ ### Colored Text
151
+ - `Color` — ANSI color codes (foreground, background, styles)
152
+ - `colorText(text, color, style, bg)` — return colored text string
153
+ - `printColor(text, color, style, bg)` — print colored text
154
+
150
155
  ## Installation
151
156
 
152
157
  ```bash
@@ -124,6 +124,11 @@ A Python utility library that extends the standard library with math, algebra, d
124
124
  ### Local Storage
125
125
  - `Storage` — persistent key-value store with subpath support
126
126
 
127
+ ### Colored Text
128
+ - `Color` — ANSI color codes (foreground, background, styles)
129
+ - `colorText(text, color, style, bg)` — return colored text string
130
+ - `printColor(text, color, style, bg)` — print colored text
131
+
127
132
  ## Installation
128
133
 
129
134
  ```bash
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "eapyTool"
7
- version = "0.3.1"
7
+ version = "0.3.2"
8
8
  description = "A Python utility library for math, algebra, data structures, and everyday tools"
9
9
  readme = "README.md"
10
10
  license = "MPL-2.0"
@@ -1,6 +1,6 @@
1
1
  """eapy - A Python utility library for math, algebra, data structures, and everyday tools."""
2
2
 
3
- __version__ = "0.3.1"
3
+ __version__ = "0.3.2"
4
4
 
5
5
  from eapy.core import (
6
6
  # Timer
@@ -90,4 +90,6 @@ from eapy.core import (
90
90
  dotProduct, crossProduct, normalize,
91
91
  # Local storage
92
92
  Storage,
93
+ # Colored text
94
+ Color, colorText, printColor,
93
95
  )
@@ -2188,4 +2188,63 @@ class Storage:
2188
2188
  os.makedirs(self.base_path, exist_ok=True)
2189
2189
 
2190
2190
  def __repr__(self):
2191
- return f"Storage(base_path='{self.base_path}')"
2191
+ return f"Storage(base_path='{self.base_path}')"
2192
+
2193
+
2194
+ # ======================================================== Colored text ========================================================
2195
+
2196
+ class Color:
2197
+ """ANSI color codes for terminal output."""
2198
+ RESET = "\033[0m"
2199
+ # Foreground colors
2200
+ BLACK = "\033[30m"
2201
+ RED = "\033[31m"
2202
+ GREEN = "\033[32m"
2203
+ YELLOW = "\033[33m"
2204
+ BLUE = "\033[34m"
2205
+ MAGENTA = "\033[35m"
2206
+ CYAN = "\033[36m"
2207
+ WHITE = "\033[37m"
2208
+ # Bright foreground
2209
+ BRIGHT_RED = "\033[91m"
2210
+ BRIGHT_GREEN = "\033[92m"
2211
+ BRIGHT_YELLOW = "\033[93m"
2212
+ BRIGHT_BLUE = "\033[94m"
2213
+ BRIGHT_MAGENTA = "\033[95m"
2214
+ BRIGHT_CYAN = "\033[96m"
2215
+ BRIGHT_WHITE = "\033[97m"
2216
+ # Styles
2217
+ BOLD = "\033[1m"
2218
+ DIM = "\033[2m"
2219
+ ITALIC = "\033[3m"
2220
+ UNDERLINE = "\033[4m"
2221
+ # Background colors
2222
+ BG_BLACK = "\033[40m"
2223
+ BG_RED = "\033[41m"
2224
+ BG_GREEN = "\033[42m"
2225
+ BG_YELLOW = "\033[43m"
2226
+ BG_BLUE = "\033[44m"
2227
+ BG_MAGENTA = "\033[45m"
2228
+ BG_CYAN = "\033[46m"
2229
+ BG_WHITE = "\033[47m"
2230
+
2231
+
2232
+ def colorText(text: str, color: str = "", style: str = "", bg: str = "") -> str:
2233
+ """Return text wrapped with ANSI color codes.
2234
+
2235
+ Args:
2236
+ text: The text to colorize.
2237
+ color: Foreground color (e.g., Color.RED, Color.BLUE).
2238
+ style: Style (e.g., Color.BOLD, Color.UNDERLINE).
2239
+ bg: Background color (e.g., Color.BG_RED).
2240
+
2241
+ Returns:
2242
+ Colored text string.
2243
+ """
2244
+ codes = style + bg + color
2245
+ return f"{codes}{text}{Color.RESET}"
2246
+
2247
+
2248
+ def printColor(text: str, color: str = "", style: str = "", bg: str = ""):
2249
+ """Print colored text to terminal."""
2250
+ print(colorText(text, color, style, bg))
@@ -36,6 +36,7 @@ from eapy.core import (
36
36
  isNumber, isString, isList, isDict, isCallable,
37
37
  dotProduct, crossProduct, normalize,
38
38
  Storage,
39
+ Color, colorText, printColor,
39
40
  )
40
41
  from math import pi
41
42
  import os
@@ -725,3 +726,27 @@ class TestStorage:
725
726
  self.store.set("x", 1)
726
727
  self.store.clear()
727
728
  assert self.store.exists("x") is False
729
+
730
+
731
+ # ======================================================== Colored text ========================================================
732
+
733
+ class TestColor:
734
+ def test_colorText(self):
735
+ result = colorText("hello", Color.RED)
736
+ assert Color.RED in result
737
+ assert Color.RESET in result
738
+ assert "hello" in result
739
+
740
+ def test_colorText_with_style(self):
741
+ result = colorText("bold", Color.GREEN, Color.BOLD)
742
+ assert Color.BOLD in result
743
+ assert Color.GREEN in result
744
+
745
+ def test_colorText_with_bg(self):
746
+ result = colorText("bg", bg=Color.BG_BLUE)
747
+ assert Color.BG_BLUE in result
748
+
749
+ def test_printColor(self, capsys):
750
+ printColor("test", Color.YELLOW)
751
+ captured = capsys.readouterr()
752
+ assert "test" in captured.out
File without changes
File without changes
File without changes
File without changes
File without changes