paramspecli 0.3.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: paramspecli
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Type-safe facade for the venerable argparse
5
5
  Author: jkmnt
6
6
  Requires-Python: >=3.12
@@ -1,6 +1,6 @@
1
1
  """Type-safe facade for the venerable argparse"""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.3.1"
4
4
 
5
5
 
6
6
  from .acts import custom_action as custom_action
@@ -15,7 +15,7 @@ from .cli import Handler as Handler
15
15
  from .cli import Missing as Missing
16
16
  from .cli import Route as Route
17
17
  from .cli import help_action as help_action
18
- from .const import const as const
18
+ from .consts import const as const
19
19
  from .conv import PathConv as PathConv
20
20
  from .exc import ParseAgain as ParseAgain
21
21
  from .fake import Context as Context
@@ -0,0 +1,115 @@
1
+ # simple terminal escape codes.
2
+ # color names are tailwind-inspired
3
+
4
+ import os
5
+ from typing import Literal
6
+
7
+ Token = Literal[
8
+ #
9
+ "text-black",
10
+ "text-red",
11
+ "text-green",
12
+ "text-yellow",
13
+ "text-blue",
14
+ "text-magenta",
15
+ "text-cyan",
16
+ "text-white",
17
+ #
18
+ "bg-black",
19
+ "bg-red",
20
+ "bg-green",
21
+ "bg-yellow",
22
+ "bg-blue",
23
+ "bg-magenta",
24
+ "bg-cyan",
25
+ "bg-white",
26
+ #
27
+ "text-bold",
28
+ #
29
+ "text-black-bright",
30
+ "text-red-bright",
31
+ "text-green-bright",
32
+ "text-yellow-bright",
33
+ "text-blue-bright",
34
+ "text-magenta-bright",
35
+ "text-cyan-bright",
36
+ "text-white-bright",
37
+ #
38
+ "bg-black-bright",
39
+ "bg-red-bright",
40
+ "bg-green-bright",
41
+ "bg-yellow-bright",
42
+ "bg-blue-bright",
43
+ "bg-magenta-bright",
44
+ "bg-cyan-bright",
45
+ "bg-white-bright",
46
+ ]
47
+
48
+
49
+ CODES: dict[Token, int] = {
50
+ "text-black": 30,
51
+ "text-red": 31,
52
+ "text-green": 32,
53
+ "text-yellow": 33,
54
+ "text-blue": 34,
55
+ "text-magenta": 35,
56
+ "text-cyan": 36,
57
+ "text-white": 37,
58
+ #
59
+ "text-bold": 1,
60
+ #
61
+ "bg-black": 40,
62
+ "bg-red": 41,
63
+ "bg-green": 42,
64
+ "bg-yellow": 43,
65
+ "bg-blue": 44,
66
+ "bg-magenta": 45,
67
+ "bg-cyan": 46,
68
+ "bg-white": 47,
69
+ #
70
+ "text-black-bright": 90,
71
+ "text-red-bright": 91,
72
+ "text-green-bright": 92,
73
+ "text-yellow-bright": 93,
74
+ "text-blue-bright": 94,
75
+ "text-magenta-bright": 95,
76
+ "text-cyan-bright": 96,
77
+ "text-white-bright": 97,
78
+ #
79
+ "bg-black-bright": 100,
80
+ "bg-red-bright": 101,
81
+ "bg-green-bright": 102,
82
+ "bg-yellow-bright": 103,
83
+ "bg-blue-bright": 104,
84
+ "bg-magenta-bright": 105,
85
+ "bg-cyan-bright": 106,
86
+ "bg-white-bright": 107,
87
+ }
88
+
89
+
90
+ def enable(*, stdin: bool = True, stderr: bool = True) -> None:
91
+ """Enable color output with escape sequences on Windows"""
92
+ if os.name != "nt":
93
+ return
94
+
95
+ from ctypes import byref, windll, wintypes
96
+
97
+ defs: list[int] = []
98
+ if stdin:
99
+ defs.append(-11)
100
+ if stderr:
101
+ defs.append(-12)
102
+
103
+ # set ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING
104
+ for d in defs:
105
+ hnd = windll.kernel32.GetStdHandle(d)
106
+ mode = wintypes.DWORD()
107
+ windll.kernel32.GetConsoleMode(hnd, byref(mode))
108
+ windll.kernel32.SetConsoleMode(hnd, mode.value | 0x0004 | 0x0001)
109
+
110
+
111
+ def style(text: str, *tokens: Token | int) -> str:
112
+ if not tokens:
113
+ return text
114
+ code = ";".join(str(CODES[tok] if isinstance(tok, str) else tok) for tok in tokens)
115
+ return f"\x1b[{code}m{text}\x1b[0m"
File without changes
File without changes
File without changes