lupaxa-draw-lines 0.1.0__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,24 @@
1
+ # OS
2
+ .DS_Store
3
+
4
+ # Cursor
5
+ .cursor/
6
+ .superpowers/
7
+ .worktrees/
8
+ cursor-docs
9
+
10
+ # Make
11
+ .makefiles/
12
+
13
+ # MkDocs
14
+ site/
15
+
16
+ # Python
17
+ .venv/
18
+ __pycache__/
19
+ .mypy_cache/
20
+ .ruff_cache/
21
+ .pytest_cache/
22
+ dist/
23
+ build/
24
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) The Lupaxa Project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.5
2
+ Name: lupaxa-draw-lines
3
+ Version: 0.1.0
4
+ Summary: Draw coloured lines in the terminal with optional text on the left, centre, or right.
5
+ Project-URL: Homepage, https://github.com/lupaxa-developers-toolbox/draw-lines
6
+ Project-URL: Documentation, https://github.com/lupaxa-developers-toolbox/draw-lines
7
+ Project-URL: Repository, https://github.com/lupaxa-developers-toolbox/draw-lines
8
+ Project-URL: Issues, https://github.com/lupaxa-developers-toolbox/draw-lines/issues
9
+ Author: The Lupaxa Project
10
+ License: MIT License
11
+
12
+ Copyright (c) The Lupaxa Project
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENCE
32
+ Keywords: ansi,colorama,console,terminal
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Environment :: Console
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Programming Language :: Python :: 3.14
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Classifier: Topic :: Terminals
46
+ Classifier: Topic :: Utilities
47
+ Requires-Python: >=3.10
48
+ Requires-Dist: colorama>=0.4.6
49
+ Provides-Extra: dev
50
+ Requires-Dist: bump-my-version>=1.2.0; extra == 'dev'
51
+ Requires-Dist: hatch>=1.12.0; extra == 'dev'
52
+ Requires-Dist: mypy>=1.12.0; extra == 'dev'
53
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
54
+ Requires-Dist: pytest>=8.0; extra == 'dev'
55
+ Requires-Dist: ruff>=0.6.0; extra == 'dev'
56
+ Provides-Extra: test
57
+ Requires-Dist: pytest-cov>=5.0; extra == 'test'
58
+ Requires-Dist: pytest>=8.0; extra == 'test'
59
+ Description-Content-Type: text/markdown
60
+
61
+ <p align="center">
62
+ <a href="https://github.com/lupaxa-developers-toolbox">
63
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/developers-toolbox/readme-logo.png" alt="Developers Toolbox" />
64
+ </a>
65
+ </p>
66
+
67
+ <h1 align="center">Draw Lines</h1>
68
+
69
+ Draw a coloured rule in the terminal. Put optional text on the left, in the
70
+ centre, or on the right. The fill character, padding, width, and colour are
71
+ all optional.
72
+
73
+ ## Install
74
+
75
+ ```bash
76
+ pip install lupaxa-draw-lines
77
+ ```
78
+
79
+ Requires Python 3.10+. The only runtime dependency is `colorama`.
80
+
81
+ ## Library
82
+
83
+ ```python
84
+ from lupaxa.draw_lines import draw_line
85
+ ```
86
+
87
+ ### Solid Rule
88
+
89
+ Empty text draws one unbroken line. This one is 90 dashes.
90
+
91
+ ```python
92
+ print(draw_line(width=90))
93
+ ```
94
+
95
+ ### Centred Text
96
+
97
+ The words sit in the middle. `fill_char=" "` uses spaces instead of dashes.
98
+
99
+ ```python
100
+ print(draw_line(text="Hello, World!", position="center", fill_char=" ", width=90))
101
+ ```
102
+
103
+ ### Text on the Left
104
+
105
+ The words sit flush left. The default `pad` of `2` puts two dashes before them, then a space.
106
+
107
+ ```python
108
+ print(draw_line(text="Hello, World!", position="left", width=90))
109
+ ```
110
+
111
+ ### Text on the Right
112
+
113
+ The same padding sits on the right edge, and the dashes fill in from the left.
114
+
115
+ ```python
116
+ print(draw_line(text="Hello, World!", position="right", width=90))
117
+ ```
118
+
119
+ ### Cyan Text
120
+
121
+ Only the words are coloured. The dashes stay plain.
122
+
123
+ ```python
124
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan"))
125
+ ```
126
+
127
+ ### Bold Text
128
+
129
+ `bold` is a bright style with no hue of its own.
130
+
131
+ ```python
132
+ print(draw_line(text="Hello, World!", position="right", width=90, color="bold"))
133
+ ```
134
+
135
+ ### Cyan and Bold
136
+
137
+ Join a colour and `bold` with `+`. Order can be `cyan+bold` or `bold+cyan`.
138
+
139
+ ```python
140
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan+bold"))
141
+ ```
142
+
143
+ ### Colour with Extra Characters
144
+
145
+ Spaces and punctuation are ignored, so this is the same call as `cyan+bold`.
146
+
147
+ ```python
148
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan + bold#$%"))
149
+ ```
150
+
151
+ ### Terminal Width
152
+
153
+ Leave `width` at its default of `-1` and the line matches the terminal, minus one column.
154
+
155
+ ```python
156
+ print(draw_line(text="Hello, World!", position="center"))
157
+ ```
158
+
159
+ ### No Side Padding
160
+
161
+ `pad=0` drops the extra dashes beside left or right text. A single space still separates the words from the rule.
162
+
163
+ ```python
164
+ print(draw_line(text="Hello, World!", position="left", pad=0, width=90))
165
+ ```
166
+
167
+ ### Parameters
168
+
169
+ | Parameter | Default | What it Does |
170
+ | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
171
+ | `text` | `""` | Text on the line. An empty string draws one unbroken rule. |
172
+ | `position` | `center` | `left`, `center`, or `right`. Any other value raises `ValueError`. |
173
+ | `fill_char` | `-` | Rule and padding character. Only the first character is used. |
174
+ | `pad` | `2` | Fill characters beside left or right text. Centred text always has one space on each side. A negative value raises `ValueError`. |
175
+ | `width` | `-1` | Column count. `-1` uses the terminal width minus one column. `0` returns an empty string. |
176
+ | `color` | `""` | Colour of the text. A name, `bold`, or both joined with `+`. Empty leaves the text uncoloured. |
177
+
178
+ ## Colour
179
+
180
+ Pass a colour name, `bold`, or both joined with `+`. Spaces and punctuation
181
+ are ignored, so `cyan + bold#$%` is the same as `cyan+bold`.
182
+
183
+ | Name | What it Does |
184
+ | --------- | ------------------------------------------------------------------------ |
185
+ | `black` | Black foreground. |
186
+ | `blue` | Blue foreground. |
187
+ | `cyan` | Cyan foreground. |
188
+ | `green` | Green foreground. |
189
+ | `grey` | Grey foreground. |
190
+ | `magenta` | Magenta foreground. |
191
+ | `red` | Red foreground. |
192
+ | `white` | White foreground. |
193
+ | `yellow` | Yellow foreground. |
194
+ | `bold` | Bright style. Use alone, or with a colour as `cyan+bold` or `bold+cyan`. |
195
+ | `reset` | Clears colour and style. |
196
+
197
+ ## Development
198
+
199
+ ```bash
200
+ make init
201
+ make python-install-dev
202
+ make python-check
203
+ ```
204
+
205
+ <a href="https://github.com/the-lupaxa-project">
206
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
207
+ </a>
@@ -0,0 +1,147 @@
1
+ <p align="center">
2
+ <a href="https://github.com/lupaxa-developers-toolbox">
3
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/developers-toolbox/readme-logo.png" alt="Developers Toolbox" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">Draw Lines</h1>
8
+
9
+ Draw a coloured rule in the terminal. Put optional text on the left, in the
10
+ centre, or on the right. The fill character, padding, width, and colour are
11
+ all optional.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install lupaxa-draw-lines
17
+ ```
18
+
19
+ Requires Python 3.10+. The only runtime dependency is `colorama`.
20
+
21
+ ## Library
22
+
23
+ ```python
24
+ from lupaxa.draw_lines import draw_line
25
+ ```
26
+
27
+ ### Solid Rule
28
+
29
+ Empty text draws one unbroken line. This one is 90 dashes.
30
+
31
+ ```python
32
+ print(draw_line(width=90))
33
+ ```
34
+
35
+ ### Centred Text
36
+
37
+ The words sit in the middle. `fill_char=" "` uses spaces instead of dashes.
38
+
39
+ ```python
40
+ print(draw_line(text="Hello, World!", position="center", fill_char=" ", width=90))
41
+ ```
42
+
43
+ ### Text on the Left
44
+
45
+ The words sit flush left. The default `pad` of `2` puts two dashes before them, then a space.
46
+
47
+ ```python
48
+ print(draw_line(text="Hello, World!", position="left", width=90))
49
+ ```
50
+
51
+ ### Text on the Right
52
+
53
+ The same padding sits on the right edge, and the dashes fill in from the left.
54
+
55
+ ```python
56
+ print(draw_line(text="Hello, World!", position="right", width=90))
57
+ ```
58
+
59
+ ### Cyan Text
60
+
61
+ Only the words are coloured. The dashes stay plain.
62
+
63
+ ```python
64
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan"))
65
+ ```
66
+
67
+ ### Bold Text
68
+
69
+ `bold` is a bright style with no hue of its own.
70
+
71
+ ```python
72
+ print(draw_line(text="Hello, World!", position="right", width=90, color="bold"))
73
+ ```
74
+
75
+ ### Cyan and Bold
76
+
77
+ Join a colour and `bold` with `+`. Order can be `cyan+bold` or `bold+cyan`.
78
+
79
+ ```python
80
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan+bold"))
81
+ ```
82
+
83
+ ### Colour with Extra Characters
84
+
85
+ Spaces and punctuation are ignored, so this is the same call as `cyan+bold`.
86
+
87
+ ```python
88
+ print(draw_line(text="Hello, World!", position="right", width=90, color="cyan + bold#$%"))
89
+ ```
90
+
91
+ ### Terminal Width
92
+
93
+ Leave `width` at its default of `-1` and the line matches the terminal, minus one column.
94
+
95
+ ```python
96
+ print(draw_line(text="Hello, World!", position="center"))
97
+ ```
98
+
99
+ ### No Side Padding
100
+
101
+ `pad=0` drops the extra dashes beside left or right text. A single space still separates the words from the rule.
102
+
103
+ ```python
104
+ print(draw_line(text="Hello, World!", position="left", pad=0, width=90))
105
+ ```
106
+
107
+ ### Parameters
108
+
109
+ | Parameter | Default | What it Does |
110
+ | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |
111
+ | `text` | `""` | Text on the line. An empty string draws one unbroken rule. |
112
+ | `position` | `center` | `left`, `center`, or `right`. Any other value raises `ValueError`. |
113
+ | `fill_char` | `-` | Rule and padding character. Only the first character is used. |
114
+ | `pad` | `2` | Fill characters beside left or right text. Centred text always has one space on each side. A negative value raises `ValueError`. |
115
+ | `width` | `-1` | Column count. `-1` uses the terminal width minus one column. `0` returns an empty string. |
116
+ | `color` | `""` | Colour of the text. A name, `bold`, or both joined with `+`. Empty leaves the text uncoloured. |
117
+
118
+ ## Colour
119
+
120
+ Pass a colour name, `bold`, or both joined with `+`. Spaces and punctuation
121
+ are ignored, so `cyan + bold#$%` is the same as `cyan+bold`.
122
+
123
+ | Name | What it Does |
124
+ | --------- | ------------------------------------------------------------------------ |
125
+ | `black` | Black foreground. |
126
+ | `blue` | Blue foreground. |
127
+ | `cyan` | Cyan foreground. |
128
+ | `green` | Green foreground. |
129
+ | `grey` | Grey foreground. |
130
+ | `magenta` | Magenta foreground. |
131
+ | `red` | Red foreground. |
132
+ | `white` | White foreground. |
133
+ | `yellow` | Yellow foreground. |
134
+ | `bold` | Bright style. Use alone, or with a colour as `cyan+bold` or `bold+cyan`. |
135
+ | `reset` | Clears colour and style. |
136
+
137
+ ## Development
138
+
139
+ ```bash
140
+ make init
141
+ make python-install-dev
142
+ make python-check
143
+ ```
144
+
145
+ <a href="https://github.com/the-lupaxa-project">
146
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
147
+ </a>
@@ -0,0 +1,23 @@
1
+ <p align="center">
2
+ <a href="https://github.com/lupaxa-developers-toolbox">
3
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/organisations/developers-toolbox/readme-logo.png" alt="Organisation Logo" />
4
+ </a>
5
+ </p>
6
+
7
+ <h1 align="center">Core Documentation</h1>
8
+
9
+ The following documents define the standards that apply across **The Lupaxa Project**:
10
+
11
+ | Document | Purpose |
12
+ | :------------------------------------ | :---------------------------------------------------------------- |
13
+ | [Code of Conduct](CODE_OF_CONDUCT.md) | Expected behaviour and reporting procedures. |
14
+ | [How to Contribute](CONTRIBUTING.md) | Development workflow, coding standards, and contribution process. |
15
+ | [Governance](GOVERNANCE.md) | Project governance, roles, and decision-making. |
16
+ | [Maintainers](MAINTAINERS.md) | Maintainer responsibilities and expectations. |
17
+ | [Projects Overview](PROJECTS.md) | Overview of organisations, repositories, and project structure. |
18
+ | [Security Policy](SECURITY.md) | Responsible disclosure and secure development practices. |
19
+ | [Support Guide](SUPPORT.md) | How to obtain help and support. |
20
+
21
+ <a href="https://github.com/the-lupaxa-project">
22
+ <img src="https://raw.githubusercontent.com/the-lupaxa-project/brand-assets/master/logos/components/footer-for-child-orgs.svg" alt="The Lupaxa Project Footer" width="100%" />
23
+ </a>
@@ -0,0 +1,98 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.18"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "lupaxa-draw-lines"
7
+ dynamic = ["version"]
8
+ description = "Draw coloured lines in the terminal with optional text on the left, centre, or right."
9
+ readme = "README.md"
10
+ license = { file = "LICENCE" }
11
+ requires-python = ">=3.10"
12
+
13
+ authors = [
14
+ { name = "The Lupaxa Project" }
15
+ ]
16
+
17
+ keywords = ["terminal", "ansi", "colorama", "console"]
18
+
19
+ dependencies = [
20
+ "colorama>=0.4.6",
21
+ ]
22
+
23
+ classifiers = [
24
+ "Development Status :: 3 - Alpha",
25
+ "Environment :: Console",
26
+ "Intended Audience :: Developers",
27
+ "License :: OSI Approved :: MIT License",
28
+ "Operating System :: OS Independent",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Programming Language :: Python :: 3.13",
34
+ "Programming Language :: Python :: 3.14",
35
+ "Topic :: Software Development :: Libraries :: Python Modules",
36
+ "Topic :: Terminals",
37
+ "Topic :: Utilities",
38
+ ]
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/lupaxa-developers-toolbox/draw-lines"
42
+ Documentation = "https://github.com/lupaxa-developers-toolbox/draw-lines"
43
+ Repository = "https://github.com/lupaxa-developers-toolbox/draw-lines"
44
+ Issues = "https://github.com/lupaxa-developers-toolbox/draw-lines/issues"
45
+
46
+ [project.optional-dependencies]
47
+ dev = [
48
+ "pytest>=8.0",
49
+ "pytest-cov>=5.0",
50
+ "ruff>=0.6.0",
51
+ "mypy>=1.12.0",
52
+ "hatch>=1.12.0",
53
+ "bump-my-version>=1.2.0",
54
+ ]
55
+ test = [
56
+ "pytest>=8.0",
57
+ "pytest-cov>=5.0",
58
+ ]
59
+
60
+ [tool.hatch.version]
61
+ path = "src/lupaxa/draw_lines/version.py"
62
+
63
+ [tool.hatch.build.targets.sdist]
64
+ include = [
65
+ "src/**",
66
+ "README.md",
67
+ "LICENCE",
68
+ ]
69
+
70
+ [tool.hatch.build.targets.wheel]
71
+ packages = ["src/lupaxa"]
72
+
73
+ [tool.ruff]
74
+ line-length = 100
75
+ target-version = "py310"
76
+
77
+ [tool.ruff.lint]
78
+ select = ["E", "F", "I", "B", "UP", "SIM"]
79
+
80
+ [tool.ruff.lint.isort]
81
+ known-first-party = ["lupaxa"]
82
+
83
+ [tool.ruff.format]
84
+ quote-style = "double"
85
+
86
+ [tool.mypy]
87
+ python_version = "3.10"
88
+ files = ["src", "tests"]
89
+ mypy_path = "src"
90
+ explicit_package_bases = true
91
+ namespace_packages = true
92
+ warn_unused_configs = true
93
+ ignore_missing_imports = true
94
+
95
+ [tool.pytest.ini_options]
96
+ addopts = "-ra -q --disable-warnings"
97
+ testpaths = ["tests"]
98
+ pythonpath = ["src"]
@@ -0,0 +1,17 @@
1
+ """lupaxa.draw_lines — coloured rules for the terminal.
2
+
3
+ ``draw_line()`` returns one line. Place optional text on the left, in the
4
+ centre, or on the right, and colour it with a name such as ``cyan`` or
5
+ ``cyan+bold``.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from .lines import draw_line
11
+ from .version import __version__, get_version
12
+
13
+ __all__ = [
14
+ "__version__",
15
+ "draw_line",
16
+ "get_version",
17
+ ]
@@ -0,0 +1,132 @@
1
+ """Draw a coloured rule across the terminal, with optional text."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import shutil
7
+
8
+ import colorama
9
+
10
+ colorama.just_fix_windows_console()
11
+
12
+ _COLORS: dict[str, str] = {
13
+ "black": colorama.Fore.BLACK,
14
+ "blue": colorama.Fore.BLUE,
15
+ "cyan": colorama.Fore.CYAN,
16
+ "green": colorama.Fore.GREEN,
17
+ "grey": colorama.Fore.LIGHTBLACK_EX,
18
+ "magenta": colorama.Fore.MAGENTA,
19
+ "red": colorama.Fore.RED,
20
+ "white": colorama.Fore.WHITE,
21
+ "yellow": colorama.Fore.YELLOW,
22
+ "bold": colorama.Style.BRIGHT,
23
+ "reset": colorama.Style.RESET_ALL,
24
+ }
25
+
26
+ _POSITIONS = frozenset({"left", "center", "right"})
27
+ _COLOR_CLEAN = re.compile(r"[^a-zA-Z+]")
28
+
29
+
30
+ def _first_character(text: str) -> str:
31
+ """Return the first character of ``text``, or an empty string."""
32
+ if text:
33
+ return text[0]
34
+ return ""
35
+
36
+
37
+ def _color_codes(color: str) -> tuple[str, str]:
38
+ """Return ``(colour_code, reset_code)`` for a colour expression.
39
+
40
+ Accepted forms are ``colour``, ``colour+bold``, ``bold+colour``, and
41
+ ``bold``. Anything other than letters and ``+`` is ignored.
42
+ """
43
+ if not color:
44
+ return "", ""
45
+
46
+ sanitized = _COLOR_CLEAN.sub("", color).lower()
47
+ parts = sanitized.split("+")
48
+ if len(parts) > 2 or (len(parts) == 2 and "bold" not in parts):
49
+ raise ValueError("Invalid color format. Use 'color', 'color+bold', or 'bold'.")
50
+
51
+ color_code = ""
52
+ for part in parts:
53
+ if part not in _COLORS:
54
+ allowed = ", ".join(_COLORS)
55
+ raise ValueError(f"Invalid color component '{part}'. Allowed values are: {allowed}")
56
+ color_code += _COLORS[part]
57
+
58
+ reset_code = _COLORS["reset"] if color_code else ""
59
+ return color_code, reset_code
60
+
61
+
62
+ def _display_text(
63
+ text: str,
64
+ position: str,
65
+ fill_char: str,
66
+ pad: int,
67
+ color_code: str,
68
+ reset_code: str,
69
+ ) -> str:
70
+ """Build the text segment, including padding and colour codes."""
71
+ if position == "left":
72
+ gap = " " if pad > 0 else ""
73
+ return f"{fill_char * pad}{gap}{color_code}{text}{reset_code} "
74
+ if position == "right":
75
+ gap = " " if pad > 0 else ""
76
+ return f" {color_code}{text}{reset_code}{gap}{fill_char * pad}"
77
+ return f" {color_code}{text}{reset_code} "
78
+
79
+
80
+ def draw_line(
81
+ text: str = "",
82
+ position: str = "center",
83
+ fill_char: str = "-",
84
+ pad: int = 2,
85
+ width: int = -1,
86
+ color: str = "",
87
+ ) -> str:
88
+ """Draw a line with optional text on the left, centre, or right.
89
+
90
+ Args:
91
+ text: Text to place on the line. An empty string draws a solid rule.
92
+ position: ``left``, ``center``, or ``right``.
93
+ fill_char: Character used for the rule and for side padding. Only the
94
+ first character is used.
95
+ pad: Fill characters beside the text. Used for ``left`` and ``right``.
96
+ ``center`` always keeps a single space on each side of the text.
97
+ width: Line width. ``-1`` uses the terminal width minus one column.
98
+ ``0`` returns an empty string.
99
+ color: Colour name, ``bold``, or ``colour+bold`` (for example
100
+ ``cyan+bold``). Punctuation and spaces are ignored.
101
+
102
+ Returns:
103
+ The constructed line, including ANSI colour codes when ``color`` is set.
104
+ """
105
+ if width == 0:
106
+ return ""
107
+ if pad < 0:
108
+ raise ValueError("pad must be zero or greater")
109
+ if position not in _POSITIONS:
110
+ raise ValueError("position must be 'left', 'center', or 'right'")
111
+
112
+ terminal_width = shutil.get_terminal_size().columns - 1 if width < 0 else width
113
+
114
+ fill = _first_character(fill_char)
115
+ if not text:
116
+ return fill * terminal_width
117
+
118
+ color_code, reset_code = _color_codes(color)
119
+ segment = _display_text(text, position, fill, pad, color_code, reset_code)
120
+ text_len = len(segment) - len(color_code) - len(reset_code)
121
+ if text_len >= terminal_width:
122
+ return segment
123
+
124
+ remaining = terminal_width - text_len
125
+ if position == "left":
126
+ return f"{segment}{fill * remaining}"
127
+ if position == "right":
128
+ return f"{fill * remaining}{segment}"
129
+
130
+ left_padding = remaining // 2
131
+ right_padding = remaining - left_padding
132
+ return f"{fill * left_padding}{segment}{fill * right_padding}"
File without changes
@@ -0,0 +1,10 @@
1
+ """Version information for the ``lupaxa.draw_lines`` package."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __version__ = "0.1.0"
6
+
7
+
8
+ def get_version() -> str:
9
+ """Return the current package version string."""
10
+ return __version__