txwrap 1.0.0__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.
txwrap/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .formatter import format_block, align_columns, dedent, fill, format_header, format_status
txwrap/formatter.py ADDED
@@ -0,0 +1,49 @@
1
+ import textwrap
2
+ import shutil
3
+
4
+ def format_block(text, width=None, indent=0):
5
+ """
6
+ Wraps text to the specified width, defaulting to the terminal width.
7
+ """
8
+ if not width:
9
+ # Get terminal width, fallback to 80
10
+ width = shutil.get_terminal_size((80, 20)).columns
11
+
12
+ prefix = " " * indent
13
+ wrapper = textwrap.TextWrapper(
14
+ width=width,
15
+ initial_indent=prefix,
16
+ subsequent_indent=prefix,
17
+ break_long_words=False,
18
+ replace_whitespace=False
19
+ )
20
+ return wrapper.fill(text)
21
+
22
+ def align_columns(data, padding=4):
23
+ """
24
+ Simple helper to align list data into columns.
25
+ """
26
+ if not data:
27
+ return ""
28
+ col_width = max(len(str(x)) for x in data) + padding
29
+ return "".join(str(x).ljust(col_width) for x in data)
30
+
31
+ def dedent(text):
32
+ """
33
+ Dedents text by removing common leading whitespace.
34
+ """
35
+ return textwrap.dedent(text)
36
+
37
+ def fill(text, width=70):
38
+ """Standard fill functionality."""
39
+ return textwrap.fill(text, width=width)
40
+
41
+ def format_header(text):
42
+ """Creates a stylized header for CLI tools."""
43
+ width = 60
44
+ border = "=" * width
45
+ return f"\n{border}\n{text.center(width)}\n{border}"
46
+
47
+ def format_status(text):
48
+ """Formats a status message with a prefix."""
49
+ return f"[+] {text}"
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: txwrap
3
+ Version: 1.0.0
4
+ Summary: Small helpers around the stdlib textwrap module: terminal-aware wrapping, column alignment, and simple CLI formatting.
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Topic :: Text Processing :: General
9
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
10
+ Classifier: Intended Audience :: Developers
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ Dynamic: classifier
14
+ Dynamic: description
15
+ Dynamic: description-content-type
16
+ Dynamic: requires-python
17
+ Dynamic: summary
18
+
19
+ # txwrap
20
+
21
+ Thin utilities on top of Python's `textwrap` and `shutil.get_terminal_size`:
22
+
23
+ - **format_block** — wrap text to terminal width (or a fixed width) with optional indent
24
+ - **align_columns** — pad list items into aligned columns
25
+ - **dedent** / **fill** — thin wrappers around `textwrap.dedent` / `textwrap.fill`
26
+ - **format_header** / **format_status** — simple CLI banners and status lines
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install txwrap
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```python
37
+ from txwrap import format_block, align_columns, format_header
38
+
39
+ print(format_block("Long line of text...", indent=2))
40
+ print(align_columns(["a", "bb", "ccc"]))
41
+ print(format_header("Done"))
42
+ ```
@@ -0,0 +1,6 @@
1
+ txwrap/__init__.py,sha256=nqZMT4YoJ7OEnqwYUHINwWvLApYDs8ZeD-3YcYxYIQk,95
2
+ txwrap/formatter.py,sha256=_LsDja8bMdeTJLKBWkL3tHYHj-lyp059qdE91gZl2H8,1304
3
+ txwrap-1.0.0.dist-info/METADATA,sha256=7UFCI0UQL-7WgR018ypAyjzdqTSYcsb00r6-v6VWLLk,1335
4
+ txwrap-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ txwrap-1.0.0.dist-info/top_level.txt,sha256=m8i4EyTU_U3PsN9dFeRZMvOZAc3GIAIeN_2szdr77OI,7
6
+ txwrap-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ txwrap