flexablelib 3.0.0__tar.gz → 3.0.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.
- {flexablelib-3.0.0 → flexablelib-3.0.1}/CHANGELOG.md +16 -0
- {flexablelib-3.0.0/flexablelib.egg-info → flexablelib-3.0.1}/PKG-INFO +1 -1
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/merges.py +5 -2
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/text_width.py +19 -1
- {flexablelib-3.0.0 → flexablelib-3.0.1/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib.egg-info/SOURCES.txt +1 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/package.json +1 -1
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_issues.py +1 -1
- flexablelib-3.0.1/tests/test_v232_merge_ansi.py +113 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/LICENSE +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/MANIFEST.in +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/README.md +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/__init__.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/_speedups.c +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/_width_tables.h +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/cells.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/colors.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/columns.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/fast.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/options.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/py.typed +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/readers.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/style_compositions.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/table.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/table_strings.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/utils.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib/writers.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/pytest.ini +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/setup.cfg +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/setup.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/style_examples.md +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/conftest.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/helpers.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_align_indicators.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_cells.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_columns.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_excel.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_merges.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_public_api_edges.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_readme_examples.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_stress_matrix.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_style_line_widths.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_styles.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_text_width.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_upstream_issues.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v211_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v213_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v214_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v215_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v216_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v217_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v218_features.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v219_coverage.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v219_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v220_exports.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v221_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v222_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v223_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v224_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v230_none.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v231_fixes.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tests/test_v300_style_names.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/benchmark.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/generate_width_tables.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/readme_gallery.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/stress_matrix.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/style_examples.py +0 -0
- {flexablelib-3.0.0 → flexablelib-3.0.1}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [3.0.1] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- A merged region drawn over a cell with ANSI colour no longer leaves a
|
|
9
|
+
stray `ESC[0m` in the output. The reset is now added only when a colour is
|
|
10
|
+
actually still open where the merge starts.
|
|
11
|
+
- Slicing coloured text (`slice_by_width`, and merges that use it) no longer
|
|
12
|
+
appends a second reset after text that already closed its colour.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- `text_width.sgr_is_open(text)` reports whether text leaves a colour or
|
|
16
|
+
attribute switched on.
|
|
17
|
+
- Tests for merge/slice escape handling and for `from_markdown` / `from_html`
|
|
18
|
+
edge cases (prose around a table, corrupt or malformed embedded payloads,
|
|
19
|
+
rowspans in the body and across the header).
|
|
20
|
+
|
|
5
21
|
## [3.0.0] - 2026-11-10
|
|
6
22
|
|
|
7
23
|
### Changed (breaking)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 54 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -21,6 +21,7 @@ import re
|
|
|
21
21
|
from typing import List, NamedTuple, Optional
|
|
22
22
|
|
|
23
23
|
from .colors import background_hex, colorize
|
|
24
|
+
from .text_width import sgr_is_open
|
|
24
25
|
from .fast import (
|
|
25
26
|
has_ansi,
|
|
26
27
|
pad_to_width,
|
|
@@ -43,7 +44,8 @@ _RESET = '\x1b[0m'
|
|
|
43
44
|
def _repaint(line, start, end, replacement):
|
|
44
45
|
"""Replace the visible columns [start, end) of a line, ending any colour."""
|
|
45
46
|
before, removed, after = partition_by_width(line, start, end)
|
|
46
|
-
if has_ansi(removed) and
|
|
47
|
+
if (has_ansi(removed) and sgr_is_open(before)
|
|
48
|
+
and not replacement.startswith(_RESET)):
|
|
47
49
|
replacement = _RESET + replacement
|
|
48
50
|
return before + replacement + after
|
|
49
51
|
|
|
@@ -702,7 +704,8 @@ def paint_rule_cell_backgrounds(line, layout, column_specs, border_color=None):
|
|
|
702
704
|
if not plain:
|
|
703
705
|
continue
|
|
704
706
|
painted = colorize(plain, spec)
|
|
705
|
-
if has_ansi(chunk) and
|
|
707
|
+
if (has_ansi(chunk) and sgr_is_open(before)
|
|
708
|
+
and not painted.startswith(_RESET)):
|
|
706
709
|
painted = _RESET + painted
|
|
707
710
|
rewritten = before + painted + after
|
|
708
711
|
return rewritten
|
|
@@ -45,6 +45,24 @@ _ANSI_RE = re.compile(
|
|
|
45
45
|
|
|
46
46
|
_RESET = '\x1b[0m'
|
|
47
47
|
|
|
48
|
+
# Select Graphic Rendition: the CSI escapes (final byte 'm') that set colour
|
|
49
|
+
# and attributes. Only these leave state open that a reset has to close.
|
|
50
|
+
_SGR_RE = re.compile(r'\x1b\[([0-9;:]*)m')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def sgr_is_open(text: str) -> bool:
|
|
54
|
+
"""
|
|
55
|
+
Whether `text` leaves a colour or attribute switched on at its end.
|
|
56
|
+
|
|
57
|
+
True when the last SGR escape in the text is anything other than a full
|
|
58
|
+
reset (``ESC[0m`` or ``ESC[m``). Partial resets such as ``ESC[39m`` count
|
|
59
|
+
as open: closing them again is harmless, leaving them open is not.
|
|
60
|
+
"""
|
|
61
|
+
last = None
|
|
62
|
+
for last in _SGR_RE.finditer(text):
|
|
63
|
+
pass
|
|
64
|
+
return last is not None and last.group(1) not in ('', '0')
|
|
65
|
+
|
|
48
66
|
# U+FE0F asks for the emoji presentation of the character before it. It has no
|
|
49
67
|
# width of its own; what it does is make that character two columns wide.
|
|
50
68
|
VARIATION_SELECTOR_16 = '\ufe0f'
|
|
@@ -269,7 +287,7 @@ def slice_by_width(text: str, start: int, end: int) -> str:
|
|
|
269
287
|
next.
|
|
270
288
|
"""
|
|
271
289
|
_, inside, _ = partition_by_width(text, start, end)
|
|
272
|
-
if inside and
|
|
290
|
+
if inside and sgr_is_open(inside):
|
|
273
291
|
inside += _RESET
|
|
274
292
|
return inside
|
|
275
293
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 54 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Regression tests for the issues.
|
|
3
3
|
|
|
4
|
-
https://github.com/Opus-Perpetuus/
|
|
4
|
+
https://github.com/Opus-Perpetuus/flexablelib/issues
|
|
5
5
|
|
|
6
6
|
Every issue ever filed against flexablelib has a reproduction here, stated
|
|
7
7
|
as the behaviour the report asked for. There are no ``xfail`` markers left:
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Merges and slices must not leave stray or doubled ANSI resets."""
|
|
2
|
+
|
|
3
|
+
from flexablelib import Table
|
|
4
|
+
from flexablelib.text_width import sgr_is_open, slice_by_width, strip_ansi
|
|
5
|
+
|
|
6
|
+
RESET = '\x1b[0m'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _merged(rows):
|
|
10
|
+
table = Table(rows=rows, headers=['h1', 'h2'])
|
|
11
|
+
table.merge_cells(0, 0, 1, 1)
|
|
12
|
+
return str(table)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_merge_over_coloured_cell_emits_no_stray_reset():
|
|
16
|
+
out = _merged([['A', 'B'], ['C', '\x1b[31mred\x1b[0m']])
|
|
17
|
+
assert '\x1b' not in out
|
|
18
|
+
assert 'A' in out
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_merge_keeps_anchor_colour_closed_once():
|
|
22
|
+
out = _merged([['\x1b[32mA\x1b[0m', 'B'], ['C', 'D']])
|
|
23
|
+
assert out.count('\x1b[32m') == 1
|
|
24
|
+
assert out.count(RESET) == 1
|
|
25
|
+
assert '\x1b[32mA' + RESET in out
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_merge_output_has_same_visible_text_as_plain():
|
|
29
|
+
coloured = _merged([['\x1b[32mA\x1b[0m', 'B'], ['C', 'D']])
|
|
30
|
+
plain = _merged([['A', 'B'], ['C', 'D']])
|
|
31
|
+
assert strip_ansi(coloured) == plain
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_slice_closes_open_colour():
|
|
35
|
+
assert slice_by_width('\x1b[31mredred', 0, 2) == '\x1b[31mre' + RESET
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_slice_does_not_double_an_existing_reset():
|
|
39
|
+
assert slice_by_width('\x1b[31mred' + RESET + ' ', 0, 5) == (
|
|
40
|
+
'\x1b[31mred' + RESET + ' ')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_sgr_is_open():
|
|
44
|
+
assert not sgr_is_open('plain')
|
|
45
|
+
assert not sgr_is_open('\x1b[31mx\x1b[0m')
|
|
46
|
+
assert not sgr_is_open('\x1b[1mx\x1b[m')
|
|
47
|
+
assert sgr_is_open('\x1b[31mx')
|
|
48
|
+
assert sgr_is_open('\x1b[0m\x1b[1;31mx')
|
|
49
|
+
assert sgr_is_open('\x1b[31mx\x1b[39m') # partial reset counts as open
|
|
50
|
+
assert not sgr_is_open('\x1b]8;;http://x\x07link\x1b]8;;\x07')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# --- reader edge cases -----------------------------------------------------
|
|
54
|
+
|
|
55
|
+
def test_from_markdown_without_pipes_gives_empty_table():
|
|
56
|
+
table = Table.from_markdown('just a paragraph\nno table here\n')
|
|
57
|
+
assert table.rows == []
|
|
58
|
+
assert table.headers == []
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_from_markdown_skips_prose_lines_around_table():
|
|
62
|
+
text = 'Intro text\n| a | b |\n|---|--:|\n| 1 | 2 |\nOutro\n'
|
|
63
|
+
table = Table.from_markdown(text)
|
|
64
|
+
assert table.headers == ['a', 'b']
|
|
65
|
+
assert table.rows == [[1, 2]]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_from_html_ignores_corrupt_embedded_payload():
|
|
69
|
+
markup = (
|
|
70
|
+
'<table><tr><th>x</th></tr></table>'
|
|
71
|
+
'<script>\nvar DATA = {not json};\n</script>'
|
|
72
|
+
)
|
|
73
|
+
table = Table.from_html(markup)
|
|
74
|
+
assert table.headers == ['x']
|
|
75
|
+
assert table.rows == []
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_from_html_payload_must_be_object_with_lists():
|
|
79
|
+
markup = (
|
|
80
|
+
'<table><tr><th>y</th></tr></table>'
|
|
81
|
+
'<script>\nvar DATA = {"headers": "y", "rows": [[3]]};\n</script>'
|
|
82
|
+
)
|
|
83
|
+
table = Table.from_html(markup)
|
|
84
|
+
assert table.headers == ['y']
|
|
85
|
+
assert table.rows == []
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_from_html_reads_valid_embedded_payload():
|
|
89
|
+
markup = (
|
|
90
|
+
'<table><tr><th>y</th></tr></table>'
|
|
91
|
+
'<script>\nvar DATA = {"headers": ["y"], "rows": [["3"]]};\n</script>'
|
|
92
|
+
)
|
|
93
|
+
assert Table.from_html(markup).rows == [[3]]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_from_html_body_rowspan_becomes_merge():
|
|
97
|
+
markup = (
|
|
98
|
+
'<table><tr><th>a</th><th>b</th></tr>'
|
|
99
|
+
'<tr><td rowspan="2">x</td><td>1</td></tr><tr><td>2</td></tr></table>'
|
|
100
|
+
)
|
|
101
|
+
table = Table.from_html(markup)
|
|
102
|
+
assert table.row_count == 2
|
|
103
|
+
assert len(table.merged_regions) == 1
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_from_html_rowspan_crossing_header_is_not_merged():
|
|
107
|
+
markup = (
|
|
108
|
+
'<table><tr><th rowspan="2">a</th><th>b</th></tr>'
|
|
109
|
+
'<tr><td>1</td></tr><tr><td>2</td><td>3</td></tr></table>'
|
|
110
|
+
)
|
|
111
|
+
table = Table.from_html(markup)
|
|
112
|
+
assert table.headers == ['a', 'b']
|
|
113
|
+
assert table.merged_regions == []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|