py3toolset 1.2.18__py3-none-any.whl

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,168 @@
1
+ """
2
+ Module to print colored text in a terminal.
3
+ """
4
+ import shutil
5
+
6
+
7
+ class Color:
8
+ RED = '\033[91m'
9
+ GREEN = '\033[92m'
10
+ YELLOW = '\033[93m'
11
+ BLUE = '\033[94m'
12
+ END = '\033[0m'
13
+
14
+
15
+ class Style:
16
+ BOLD = "\033[1m"
17
+
18
+
19
+ def col(col, txt):
20
+ """
21
+ Colorizes txt using ANSI escape code (encoded in :class:`.Color`).
22
+
23
+ Args:
24
+ col: ``int``
25
+ ``Color.RED``, ``Color.GREEN``, ``Color.YELLOW``, ``Color.BLUE``.
26
+ txt: ``str``
27
+ the txt to colorize.
28
+
29
+ Return:
30
+ ``txt`` encoded in ``col`` color.
31
+
32
+ """
33
+ if col not in [Color.BLUE, Color.YELLOW, Color.GREEN, Color.RED]:
34
+ raise Exception("Not valid color")
35
+ return col + txt.replace(Color.END, Color.END+""+col) + Color.END
36
+
37
+
38
+ def frame(title, col=Color.BLUE, centering=True):
39
+ """Frames the text ``title`` in color.
40
+
41
+ The enclosing frame is made of colored dash characters.
42
+
43
+ Args:
44
+ title: ``str``
45
+ The text to frame.
46
+ col: ``int``
47
+ ``Color.RED``, ``Color.GREEN``, ``Color.YELLOW``, ``Color.BLUE``
48
+ (default).
49
+ centering: ``bool``
50
+ ``True`` (default) for centered ``title`` in terminal,
51
+ ``False`` otherwise.
52
+
53
+ Return:
54
+ ``title`` encoded in ``col`` color with dash characters above and
55
+ below.
56
+ """
57
+ return (col + "-"*get_width() + "\n" +
58
+ Style.BOLD+(centering and center(title) or title) + "\n" +
59
+ Color.END + col + "-"*get_width() + Color.END)
60
+
61
+
62
+ def big_frame(title, col=Color.RED, centering=True):
63
+ """Frames the text ``title`` in color.
64
+
65
+ Same as :func:`.frame` but text in red by default with enclosing frame
66
+ made of ``=`` characters.
67
+ """
68
+ return (col + "="*get_width() + "\n" +
69
+ Style.BOLD+(centering and center(title) or title) + "\n" +
70
+ Color.END + col + "="*get_width() + Color.END)
71
+
72
+
73
+ def center(txt):
74
+ """Centers a text according to the terminal number of columns.
75
+
76
+ The centering is made by space insertions.
77
+
78
+ Return:
79
+ The centered text of ``txt``.
80
+ """
81
+ return " "*((get_width() - len(txt)) // 2) + txt
82
+
83
+
84
+ def print_center(txt):
85
+ """ Centers and prints text ``txt``.
86
+
87
+ .. seealso::
88
+ :func:`.center`
89
+ """
90
+ print(center(txt))
91
+
92
+
93
+ def print_frame(title, col=Color.BLUE, centering=True):
94
+ """Prints ``title`` enclosed in frame (dash characters).
95
+
96
+ .. seealso::
97
+ :func:`.frame`
98
+ """
99
+ print(frame(title, col, centering))
100
+
101
+
102
+ def get_width():
103
+ "Gets the terminal number of columns."
104
+ return shutil.get_terminal_size()[0]
105
+
106
+
107
+ def print_big_frame(title, col=Color.RED, centering=True):
108
+ """Prints ``title`` enclosed in big frame (``=`` characters).
109
+
110
+ .. seealso::
111
+ :func:`.big_frame`
112
+ """
113
+ print(big_frame(title, col, centering))
114
+
115
+
116
+ def bold(txt):
117
+ "Returns txt in bold style (for terminal display)"
118
+ return Style.BOLD + txt + Color.END
119
+
120
+
121
+ def warn(msg):
122
+ "Formats and print ``msg`` as a warning message (prefix 'WARNING:' in red)"
123
+ print(col(Color.RED, "WARNING: ")+msg)
124
+
125
+
126
+ def err(msg):
127
+ """Formats a msg as an error message.
128
+
129
+ Format: prefix 'Error:' in bold style and all message in red.
130
+ """
131
+ if not msg.lower().startswith("error"):
132
+ msg = bold("Error: ") + msg
133
+ print_frame(msg, Color.RED, centering=False)
134
+
135
+
136
+ def red(txt):
137
+ """
138
+ Returns ``txt`` as red ``str`` (see ``col``).
139
+ """
140
+ return col(Color.RED, txt)
141
+
142
+
143
+ def green(txt):
144
+ """
145
+ Returns ``txt`` as green ``str`` (see ``col``).
146
+ """
147
+ return col(Color.GREEN, txt)
148
+
149
+
150
+ def blue(txt):
151
+ """
152
+ Returns ``txt`` as blue ``str`` (see ``col``).
153
+ """
154
+ return col(Color.BLUE, txt)
155
+
156
+
157
+ def yellow(txt):
158
+ """
159
+ Returns ``txt`` as yellow ``str`` (see ``col``).
160
+ """
161
+ return col(Color.YELLOW, txt)
162
+
163
+
164
+ # def alias color functions
165
+ r = red
166
+ g = green
167
+ b = blue
168
+ y = yellow
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: py3toolset
3
+ Version: 1.2.18
4
+ Summary: Python utility modules.
5
+ Home-page:
6
+ License: 3-clause BSD 2.0
7
+ Classifier: License :: OSI Approved :: BSD License
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Topic :: Software Development
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE.md
12
+ Requires-Dist: numpy>=2
13
+ Dynamic: classifier
14
+ Dynamic: description
15
+ Dynamic: description-content-type
16
+ Dynamic: license
17
+ Dynamic: license-file
18
+ Dynamic: requires-dist
19
+ Dynamic: summary
20
+
21
+ Python collection of utility modules: [bash_autocomp](https://lpg-umr6112.fr//api.html#module-0), [cmd_interact](https://lpg-umr6112.fr//api.html#module-1), [dep](https://lpg-umr6112.fr//api.html#module-2), [file_backup](https://lpg-umr6112.fr//api.html#module-3), [fs](https://lpg-umr6112.fr//api.html#module-4), [nmath](https://lpg-umr6112.fr//api.html#module-5), [tuple_file](https://lpg-umr6112.fr//api.html#module-6), [txt_color](https://lpg-umr6112.fr//api.html#module-7)...
22
+
23
+ This package software engineering has been funded by the [Laboratoire de Planétologie et Géosciences](https://lpg-umr6112.fr/), Nantes (France).
24
+
@@ -0,0 +1,16 @@
1
+ py3toolset/LICENSE.md,sha256=vm9EOiT_FH8ZkfAlTcGf_aYTaqyp3XtWLQk-Nw1_5Ug,1487
2
+ py3toolset/__init__.py,sha256=OsEpnz6RA6ToHhem7m_1iQqm0C-EddSft_dZtxOKhOw,24
3
+ py3toolset/bash_autocomp.py,sha256=AJI2ilnS0s8X2IE9KIlRuOYOKiKODl6NmnUwBVwXrO4,2677
4
+ py3toolset/cmd_interact.py,sha256=xGQtK4OGcyoQThmlJ_40DleMHE9F9jWaYpGRufrG6uU,3542
5
+ py3toolset/dep.py,sha256=WgkWSAQOH37rokMxXZJbqXe6DCDPk_X8W_LdRwPLKRA,4760
6
+ py3toolset/file_backup.py,sha256=971w2ZUjjalVUSfGzW59ke4zhUgfX_0eVOHiU3PxuFw,4407
7
+ py3toolset/fs.py,sha256=VgkeioxZqmna3JCcfkNR_ieKXIBdBRYKjVQqP0e4lH0,16065
8
+ py3toolset/nmath.py,sha256=SRZBj3mmno3p3tzUKC327DK1mLFD41VGQcq8snlpKzs,13595
9
+ py3toolset/setup.py,sha256=lHXURiDo5ujPYpnXSovEFwEjkiK01X9xca_cmEkLQ_c,1167
10
+ py3toolset/tuple_file.py,sha256=DfdEFM5EvTIjsrFbMxQ3nGVWmmYSZRMp7wMudcAHaOI,3197
11
+ py3toolset/txt_color.py,sha256=ml5QRqSOA9Kcbt6B89b7-wKNCRcluN0x2lKcH0no0Z8,3854
12
+ py3toolset-1.2.18.dist-info/licenses/LICENSE.md,sha256=vm9EOiT_FH8ZkfAlTcGf_aYTaqyp3XtWLQk-Nw1_5Ug,1487
13
+ py3toolset-1.2.18.dist-info/METADATA,sha256=Lw4seCJhph0kHpI02id6MIFMyDI93mbSJwC0-2fJLHU,1145
14
+ py3toolset-1.2.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ py3toolset-1.2.18.dist-info/top_level.txt,sha256=qvAiIlJzi4hfz3GOt5HT_zr_XCyukWdNuBqDtxpBKO0,11
16
+ py3toolset-1.2.18.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,11 @@
1
+ Copyright 2017-2023 Éric Beucler, Hakim Hadj-Djilani
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ py3toolset