flexablelib 3.0.1__tar.gz → 3.0.2__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.1 → flexablelib-3.0.2}/CHANGELOG.md +22 -0
- {flexablelib-3.0.1/flexablelib.egg-info → flexablelib-3.0.2}/PKG-INFO +1 -1
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/merges.py +127 -128
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/table.py +25 -108
- {flexablelib-3.0.1 → flexablelib-3.0.2/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib.egg-info/SOURCES.txt +1 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/package.json +1 -1
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_features.py +13 -9
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_merge_edge_matrix.py +7 -8
- flexablelib-3.0.2/tests/test_merge_fill.py +244 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_merges.py +91 -100
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/stress_matrix.py +5 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/LICENSE +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/MANIFEST.in +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/README.md +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/__init__.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/_speedups.c +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/_width_tables.h +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/cells.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/colors.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/columns.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/fast.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/options.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/py.typed +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/readers.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/style_compositions.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/table_strings.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/text_width.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/utils.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib/writers.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/pytest.ini +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/setup.cfg +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/setup.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/style_examples.md +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/conftest.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/helpers.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_align_indicators.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_cells.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_columns.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_excel.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_issues.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_public_api_edges.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_readme_examples.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_stress_matrix.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_style_line_widths.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_styles.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_text_width.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_upstream_issues.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v211_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v213_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v214_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v215_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v216_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v217_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v218_features.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v219_coverage.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v219_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v220_exports.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v221_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v222_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v223_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v224_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v230_none.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v231_fixes.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v232_merge_ansi.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tests/test_v300_style_names.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/benchmark.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/generate_width_tables.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/readme_gallery.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/style_examples.py +0 -0
- {flexablelib-3.0.1 → flexablelib-3.0.2}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,28 @@
|
|
|
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.2] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- Merge and zebra backgrounds now fill a single rectangle: the interior of
|
|
9
|
+
the cell or merge, including any separators absorbed between its rows.
|
|
10
|
+
The fill no longer stairsteps at the corners, leaks onto neighbouring
|
|
11
|
+
cells, or paints the outline glyphs (`─`, `═`, tees and crossings).
|
|
12
|
+
- Horizontal rules keep `border_color` (or the default foreground) and do
|
|
13
|
+
not inherit a cell or zebra background, so a `_rows` style no longer
|
|
14
|
+
loses its border colour or leaves an uncoloured gap on a junction.
|
|
15
|
+
- A leftover `ESC[0m` after a merge that already closed its colour is
|
|
16
|
+
dropped, so `column_colors` / zebra next to a coloured merge no longer
|
|
17
|
+
emit a doubled reset.
|
|
18
|
+
- Theme `slate` (psql + zebra) and other themes paint a 2D merge as a
|
|
19
|
+
solid rectangle; `border_color` no longer cuts through the label.
|
|
20
|
+
- Column-only styles (verticals but no rule between rows) no longer
|
|
21
|
+
insert a synthetic cap around a multi-column merge. That cap blanked
|
|
22
|
+
neighbour cells on a new line and made them look merged. The span is
|
|
23
|
+
shown by dropping the internal vertical; when the merge has a colour,
|
|
24
|
+
the rectangular fill marks it. Existing header and end rules still
|
|
25
|
+
get their tees repaired.
|
|
26
|
+
|
|
5
27
|
## [3.0.1] - 2026-11-11
|
|
6
28
|
|
|
7
29
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.2
|
|
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
|
|
@@ -20,7 +20,7 @@ import operator
|
|
|
20
20
|
import re
|
|
21
21
|
from typing import List, NamedTuple, Optional
|
|
22
22
|
|
|
23
|
-
from .colors import
|
|
23
|
+
from .colors import colorize
|
|
24
24
|
from .text_width import sgr_is_open
|
|
25
25
|
from .fast import (
|
|
26
26
|
has_ansi,
|
|
@@ -47,6 +47,14 @@ def _repaint(line, start, end, replacement):
|
|
|
47
47
|
if (has_ansi(removed) and sgr_is_open(before)
|
|
48
48
|
and not replacement.startswith(_RESET)):
|
|
49
49
|
replacement = _RESET + replacement
|
|
50
|
+
# The removed span often keeps its trailing RESET, which partition leaves
|
|
51
|
+
# at the start of `after`. If the replacement already closed its colour,
|
|
52
|
+
# that leftover is a doubled reset (`ESC[0mESC[0m`).
|
|
53
|
+
if replacement.endswith(_RESET):
|
|
54
|
+
while after.startswith(_RESET):
|
|
55
|
+
after = after[len(_RESET):]
|
|
56
|
+
elif after.startswith(_RESET) and not sgr_is_open(before + replacement):
|
|
57
|
+
after = after[len(_RESET):]
|
|
50
58
|
return before + replacement + after
|
|
51
59
|
|
|
52
60
|
|
|
@@ -674,45 +682,97 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
|
|
|
674
682
|
|
|
675
683
|
def paint_rule_cell_backgrounds(line, layout, column_specs, border_color=None):
|
|
676
684
|
"""
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
as
|
|
685
|
-
|
|
686
|
-
``
|
|
687
|
-
|
|
688
|
-
|
|
685
|
+
Colour a horizontal rule with ``border_color`` only.
|
|
686
|
+
|
|
687
|
+
Cell, zebra and merge backgrounds belong on the interior rectangle of
|
|
688
|
+
the cell or merge (text lines and any rule segments absorbed inside a
|
|
689
|
+
merge). Rule glyphs on the outline stay chrome: they keep
|
|
690
|
+
``border_color`` (or the default foreground) and never inherit a cell
|
|
691
|
+
fill, so a zebra stripe cannot leak onto ``─`` and a junction cannot
|
|
692
|
+
be left as an uncoloured gap.
|
|
693
|
+
|
|
694
|
+
``layout`` and ``column_specs`` are accepted for compatibility and
|
|
695
|
+
ignored. Paint lives in ``apply`` for merge interiors and in the
|
|
696
|
+
table's rule colouring for chrome.
|
|
689
697
|
"""
|
|
690
698
|
if not line:
|
|
691
699
|
return line
|
|
692
|
-
|
|
693
|
-
spec and background_hex(spec) is not None for spec in column_specs):
|
|
694
|
-
return colorize(line, border_color) if border_color else line
|
|
700
|
+
return colorize(line, border_color) if border_color else line
|
|
695
701
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
702
|
+
|
|
703
|
+
def _join_sgr_parts(parts):
|
|
704
|
+
"""Concatenate SGR spans, collapsing a reset that is immediately doubled."""
|
|
705
|
+
out = ''
|
|
706
|
+
for part in parts:
|
|
707
|
+
if out.endswith(_RESET) and part.startswith(_RESET):
|
|
708
|
+
part = part[len(_RESET):]
|
|
709
|
+
out += part
|
|
710
|
+
return out
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def _apply_border_chrome(line, border_color, protected_ranges=()):
|
|
714
|
+
"""
|
|
715
|
+
Recolour every visible column of a rule with ``border_color``, leaving
|
|
716
|
+
merge interiors untouched.
|
|
717
|
+
|
|
718
|
+
``protected_ranges`` is a sequence of ``[start, end)`` visible-column
|
|
719
|
+
spans (the merge rectangle, including absorbed internal separators).
|
|
720
|
+
Those columns already hold the merge fill (spaces or text) and must
|
|
721
|
+
not pick up chrome. Everything else -- outline dashes, tees, outer
|
|
722
|
+
corners, and the rule on either side of a merge -- is stripped and
|
|
723
|
+
wrapped in ``border_color`` so a later ``_repaint`` cannot leave an
|
|
724
|
+
uncoloured hole where a colour was closed early.
|
|
725
|
+
"""
|
|
726
|
+
if not line or not border_color:
|
|
727
|
+
return line
|
|
728
|
+
width = visible_width(line)
|
|
729
|
+
ranges = []
|
|
730
|
+
for start, end in protected_ranges:
|
|
731
|
+
start = max(0, start)
|
|
732
|
+
end = min(width, end)
|
|
733
|
+
if end > start:
|
|
734
|
+
ranges.append((start, end))
|
|
735
|
+
ranges.sort()
|
|
736
|
+
merged = []
|
|
737
|
+
for start, end in ranges:
|
|
738
|
+
if merged and start <= merged[-1][1]:
|
|
739
|
+
merged[-1] = (merged[-1][0], max(merged[-1][1], end))
|
|
740
|
+
else:
|
|
741
|
+
merged.append((start, end))
|
|
742
|
+
|
|
743
|
+
segments = []
|
|
744
|
+
cursor = 0
|
|
745
|
+
for start, end in merged:
|
|
746
|
+
if start > cursor:
|
|
747
|
+
segments.append((cursor, start, False))
|
|
748
|
+
segments.append((start, end, True))
|
|
749
|
+
cursor = max(cursor, end)
|
|
750
|
+
if cursor < width:
|
|
751
|
+
segments.append((cursor, width, False))
|
|
752
|
+
|
|
753
|
+
if not merged:
|
|
754
|
+
return colorize(strip_ansi(line), border_color)
|
|
755
|
+
|
|
756
|
+
parts = []
|
|
757
|
+
for start, end, kept in segments:
|
|
758
|
+
_, chunk, _ = partition_by_width(line, start, end)
|
|
759
|
+
if kept:
|
|
760
|
+
parts.append(chunk)
|
|
761
|
+
else:
|
|
762
|
+
painted = colorize(strip_ansi(chunk), border_color)
|
|
763
|
+
# The reset that closed the previous (merge) span often lands at
|
|
764
|
+
# the start of this chunk and would be stripped with the rest of
|
|
765
|
+
# its ANSI, so a 'red' prefix (fg only) would inherit the merge
|
|
766
|
+
# background. Re-open chrome with a reset when this is not the
|
|
767
|
+
# start of the line; _join_sgr_parts collapses a true double.
|
|
768
|
+
if start > 0 and not painted.startswith(_RESET):
|
|
769
|
+
painted = _RESET + painted
|
|
770
|
+
parts.append(painted)
|
|
771
|
+
return _join_sgr_parts(parts)
|
|
712
772
|
|
|
713
773
|
|
|
714
774
|
def apply(lines, row_line_map, regions, column_widths, composition,
|
|
715
|
-
index_offset, hidden_columns=(), filler=' '):
|
|
775
|
+
index_offset, hidden_columns=(), filler=' ', border_color=None):
|
|
716
776
|
"""
|
|
717
777
|
Rewrite assembled lines so each region renders as one cell.
|
|
718
778
|
|
|
@@ -726,6 +786,22 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
726
786
|
coordinates ignore it. ``hidden_columns`` lists the columns the table is
|
|
727
787
|
not drawing, which take up no room in a line.
|
|
728
788
|
|
|
789
|
+
The merge interior is a single rectangle: every physical line from the
|
|
790
|
+
first content line to the last, including separators absorbed between
|
|
791
|
+
those rows, is painted from the first column's left edge to the last
|
|
792
|
+
column's right edge. Internal rule glyphs (including crossings) become
|
|
793
|
+
spaces and, when the region has a colour, carry that background.
|
|
794
|
+
Outline glyphs immediately outside the rectangle -- the rule above and
|
|
795
|
+
below, and the verticals to either side -- stay chrome: they use
|
|
796
|
+
``border_color`` (or the default foreground) and never pick up the
|
|
797
|
+
merge fill.
|
|
798
|
+
|
|
799
|
+
Column-only styles (verticals but no body rule) do not grow a synthetic
|
|
800
|
+
cap around a multi-column merge. An inserted line would blank neighbour
|
|
801
|
+
cells and make them look merged; without a real rule there is no outline
|
|
802
|
+
to repair, and the rectangular fill (when coloured) already shows the
|
|
803
|
+
span.
|
|
804
|
+
|
|
729
805
|
Returns the rewritten lines.
|
|
730
806
|
"""
|
|
731
807
|
if not regions:
|
|
@@ -742,32 +818,13 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
742
818
|
# their data lines; caps above/below need ┴/┬ repair.
|
|
743
819
|
# (above_line, below_line, inner_separator_xs, first_row, last_row)
|
|
744
820
|
horiz_caps = []
|
|
745
|
-
#
|
|
746
|
-
#
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
and synthesized is not None
|
|
753
|
-
and composition.vertical_table_body_lines is not None
|
|
754
|
-
and composition.vertical_table_body_lines.middle not in (None, '', ' ')
|
|
755
|
-
)
|
|
756
|
-
syn_h = synthesized.middle if synthesized is not None else None
|
|
757
|
-
|
|
758
|
-
def _blank_crossings(rule_line, gap_after_row):
|
|
759
|
-
"""Erase horizontal through merges that continue across this gap."""
|
|
760
|
-
for region in regions:
|
|
761
|
-
if region.first_row <= gap_after_row and region.last_row >= gap_after_row + 1:
|
|
762
|
-
bounds = _region_bounds(region, layout, index_offset)
|
|
763
|
-
if bounds is None:
|
|
764
|
-
continue
|
|
765
|
-
(start, end), _, _, _ = bounds
|
|
766
|
-
if end > start:
|
|
767
|
-
rule_line = _repaint(
|
|
768
|
-
rule_line, start, end, filler * (end - start)
|
|
769
|
-
)
|
|
770
|
-
return rule_line
|
|
821
|
+
# Visible-column ranges of every merge interior, per physical line, so
|
|
822
|
+
# the chrome pass can recolour outline glyphs without touching the fill.
|
|
823
|
+
interior_ranges = {}
|
|
824
|
+
|
|
825
|
+
def _mark_interior(line_index, start, end):
|
|
826
|
+
if end > start:
|
|
827
|
+
interior_ranges.setdefault(line_index, []).append((start, end))
|
|
771
828
|
|
|
772
829
|
for region in regions:
|
|
773
830
|
bounds = _region_bounds(region, layout, index_offset)
|
|
@@ -811,6 +868,7 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
811
868
|
continue
|
|
812
869
|
replacement = painted if line_index == text_line else blank
|
|
813
870
|
lines[line_index] = _repaint(line, start, end, replacement)
|
|
871
|
+
_mark_interior(line_index, start, end)
|
|
814
872
|
|
|
815
873
|
# Blank separator lines inside a vertical (or 2D) span. Junctions are
|
|
816
874
|
# repaired in a second pass once every region has painted, so adjacent
|
|
@@ -823,6 +881,7 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
823
881
|
if visible_width(line) < end:
|
|
824
882
|
continue
|
|
825
883
|
lines[line_index] = _repaint(line, start, end, blank)
|
|
884
|
+
_mark_interior(line_index, start, end)
|
|
826
885
|
touched_seps.add(line_index)
|
|
827
886
|
|
|
828
887
|
inner_seps = [
|
|
@@ -838,31 +897,6 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
838
897
|
(above, below, set(inner_seps), region.first_row, region.last_row)
|
|
839
898
|
)
|
|
840
899
|
|
|
841
|
-
if col_only and synthesized is not None:
|
|
842
|
-
# Cap above: gap after first_row-1 (if any).
|
|
843
|
-
if region.first_row > 0:
|
|
844
|
-
g = region.first_row - 1
|
|
845
|
-
plan = gap_plans.setdefault(
|
|
846
|
-
g, {'s': set(), 'n': set(), 'at': min(target_lines),
|
|
847
|
-
'h': []}
|
|
848
|
-
)
|
|
849
|
-
plan['s'] |= set(inner_seps)
|
|
850
|
-
plan['at'] = min(plan['at'], min(target_lines))
|
|
851
|
-
plan.setdefault('h', []).append((start, end))
|
|
852
|
-
# Cap below: gap after last_row (unless last table row — end
|
|
853
|
-
# line is repaired in pass 3).
|
|
854
|
-
max_row = max(row_line_map) if row_line_map else region.last_row
|
|
855
|
-
if region.last_row < max_row:
|
|
856
|
-
g = region.last_row
|
|
857
|
-
plan = gap_plans.setdefault(
|
|
858
|
-
g, {'s': set(), 'n': set(), 'at': max(target_lines) + 1,
|
|
859
|
-
'h': []}
|
|
860
|
-
)
|
|
861
|
-
plan['n'] |= set(inner_seps)
|
|
862
|
-
plan['at'] = min(plan.get('at', max(target_lines) + 1),
|
|
863
|
-
max(target_lines) + 1)
|
|
864
|
-
plan.setdefault('h', []).append((start, end))
|
|
865
|
-
|
|
866
900
|
# --- Pass 2: repair junctions on body rules touched by vertical blanks ---
|
|
867
901
|
if h_glyph:
|
|
868
902
|
for sep_index in sorted(touched_seps):
|
|
@@ -898,52 +932,17 @@ def apply(lines, row_line_map, regions, column_widths, composition,
|
|
|
898
932
|
| missing_north_by_line.get(line_index, set())),
|
|
899
933
|
)
|
|
900
934
|
|
|
901
|
-
#
|
|
902
|
-
#
|
|
903
|
-
#
|
|
904
|
-
# vertical/2D merges are not crossed by ghost edges.
|
|
905
|
-
if col_only and gap_plans and synthesized is not None:
|
|
906
|
-
for g in sorted(gap_plans.keys(), reverse=True):
|
|
907
|
-
plan = gap_plans[g]
|
|
908
|
-
at = plan['at']
|
|
909
|
-
# If the line already at `at` (or just above the lower row) is a
|
|
910
|
-
# real rule, repair it in place instead of inserting.
|
|
911
|
-
existing = None
|
|
912
|
-
if 0 <= at < len(lines) and _looks_like_rule(lines[at], syn_h):
|
|
913
|
-
existing = at
|
|
914
|
-
elif 0 <= at - 1 < len(lines) and _looks_like_rule(lines[at - 1], syn_h):
|
|
915
|
-
# Header/end sitting where we wanted a gap.
|
|
916
|
-
existing = at - 1
|
|
917
|
-
|
|
918
|
-
if existing is not None:
|
|
919
|
-
line = lines[existing]
|
|
920
|
-
line = _blank_crossings(line, g)
|
|
921
|
-
line_h = next((ch for ch in line if _is_h(ch)), syn_h or '─')
|
|
922
|
-
lines[existing] = _repair_rule_junctions(
|
|
923
|
-
line, layout, composition, line_h,
|
|
924
|
-
missing_south=plan['s'] or None,
|
|
925
|
-
missing_north=plan['n'] or None,
|
|
926
|
-
above=lines[existing - 1] if existing > 0 else None,
|
|
927
|
-
below=lines[existing + 1] if existing + 1 < len(lines) else None,
|
|
928
|
-
)
|
|
929
|
-
continue
|
|
935
|
+
# No synthetic caps. Inserting a rule in a column-only style blanks the
|
|
936
|
+
# neighbour columns on that new line and makes them look merged. Outline
|
|
937
|
+
# tees are only repaired on rules that already exist (pass 3).
|
|
930
938
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
if
|
|
939
|
+
# --- Pass 4: restore border chrome on remaining rule glyphs --------------
|
|
940
|
+
if border_color:
|
|
941
|
+
for line_index, line in enumerate(lines):
|
|
942
|
+
if not _looks_like_rule(line, h_glyph):
|
|
935
943
|
continue
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
rule = _clamp_rule_to_h_ranges(
|
|
939
|
-
rule, layout, composition, plan.get('h') or []
|
|
940
|
-
)
|
|
941
|
-
rule = _blank_crossings(rule, g)
|
|
942
|
-
rule = _repair_rule_junctions(
|
|
943
|
-
rule, layout, composition, syn_h,
|
|
944
|
-
missing_south=plan['s'] or None,
|
|
945
|
-
missing_north=plan['n'] or None,
|
|
944
|
+
lines[line_index] = _apply_border_chrome(
|
|
945
|
+
line, border_color, interior_ranges.get(line_index, ()),
|
|
946
946
|
)
|
|
947
|
-
lines.insert(max(0, min(at, len(lines))), rule)
|
|
948
947
|
|
|
949
948
|
return lines
|
|
@@ -4747,6 +4747,9 @@ class Table(object):
|
|
|
4747
4747
|
hidden_columns = self.__effective_hidden_columns(table_with_i)
|
|
4748
4748
|
|
|
4749
4749
|
regions = self.__regions_with_colors()
|
|
4750
|
+
border_color = (
|
|
4751
|
+
self.__border_color if self.__colors_active else None
|
|
4752
|
+
)
|
|
4750
4753
|
merged = apply_merges(
|
|
4751
4754
|
table_string.split('\n'),
|
|
4752
4755
|
row_line_map,
|
|
@@ -4755,44 +4758,11 @@ class Table(object):
|
|
|
4755
4758
|
self.__style_composition,
|
|
4756
4759
|
1 if table_with_i else 0,
|
|
4757
4760
|
hidden_columns,
|
|
4761
|
+
border_color=border_color,
|
|
4758
4762
|
)
|
|
4759
4763
|
return '\n'.join(merged)
|
|
4760
4764
|
|
|
4761
4765
|
|
|
4762
|
-
def __rule_spec_for_cell(self, row_index, column_index, column_titles):
|
|
4763
|
-
"""
|
|
4764
|
-
Colour that should back the H-rule segment under a cell.
|
|
4765
|
-
|
|
4766
|
-
Explicit merge colours win (so a wide merge paints one continuous
|
|
4767
|
-
band under its span). Otherwise the cell's resolved colour is used.
|
|
4768
|
-
"""
|
|
4769
|
-
for region in self.__regions_with_colors():
|
|
4770
|
-
if (region.first_row <= row_index <= region.last_row
|
|
4771
|
-
and region.first_column <= column_index <= region.last_column
|
|
4772
|
-
and region.color):
|
|
4773
|
-
return region.color
|
|
4774
|
-
name = (
|
|
4775
|
-
column_titles[column_index]
|
|
4776
|
-
if column_index < len(column_titles) else ''
|
|
4777
|
-
)
|
|
4778
|
-
try:
|
|
4779
|
-
raw = self.__raw_value_at(column_titles, column_index, row_index)
|
|
4780
|
-
except Exception:
|
|
4781
|
-
raw = None
|
|
4782
|
-
return self.__color_for_cell(raw, row_index, name)
|
|
4783
|
-
|
|
4784
|
-
def __rule_specs_for_row(self, row_index, column_titles, column_widths):
|
|
4785
|
-
"""One colour spec per *drawn* column for the rule under ``row_index``."""
|
|
4786
|
-
hidden = set(self.__effective_hidden_columns(self.__show_index))
|
|
4787
|
-
specs = []
|
|
4788
|
-
for col_i, _width in enumerate(column_widths):
|
|
4789
|
-
if col_i in hidden:
|
|
4790
|
-
continue
|
|
4791
|
-
specs.append(
|
|
4792
|
-
self.__rule_spec_for_cell(row_index, col_i, column_titles)
|
|
4793
|
-
)
|
|
4794
|
-
return specs
|
|
4795
|
-
|
|
4796
4766
|
@staticmethod
|
|
4797
4767
|
def _border_text_span(length, text_len, offset, align, lo, hi):
|
|
4798
4768
|
"""
|
|
@@ -5056,92 +5026,39 @@ class Table(object):
|
|
|
5056
5026
|
def __colour_horizontal_rules(self, separators, column_widths,
|
|
5057
5027
|
column_titles, body_row_count):
|
|
5058
5028
|
"""
|
|
5059
|
-
|
|
5029
|
+
Colour horizontal rules with ``border_color`` only (no cell fill).
|
|
5060
5030
|
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
(or None when the style has no body rule).
|
|
5067
|
-
"""
|
|
5068
|
-
from .merges import compute_layout, paint_rule_cell_backgrounds
|
|
5031
|
+
Cell, zebra and merge backgrounds live on the interior rectangle
|
|
5032
|
+
of the cell or merge. Rule glyphs stay chrome so a fill cannot
|
|
5033
|
+
leak onto ``─`` / ``═`` / junctions, and a missing ``border_color``
|
|
5034
|
+
on a junction cannot open an uncoloured gap in the middle of a
|
|
5035
|
+
rule.
|
|
5069
5036
|
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
)
|
|
5037
|
+
Returns the updated HorizontalComposition and a gap painter
|
|
5038
|
+
callable (or None when the style has no body rule).
|
|
5039
|
+
"""
|
|
5074
5040
|
border = self.__border_color
|
|
5075
5041
|
|
|
5076
|
-
def paint(line
|
|
5042
|
+
def paint(line):
|
|
5077
5043
|
if line is None:
|
|
5078
5044
|
return None
|
|
5079
|
-
return
|
|
5080
|
-
|
|
5081
|
-
first_specs = (
|
|
5082
|
-
self.__rule_specs_for_row(0, column_titles, column_widths)
|
|
5083
|
-
if body_row_count else []
|
|
5084
|
-
)
|
|
5085
|
-
last_specs = (
|
|
5086
|
-
self.__rule_specs_for_row(
|
|
5087
|
-
body_row_count - 1, column_titles, column_widths
|
|
5088
|
-
)
|
|
5089
|
-
if body_row_count else []
|
|
5090
|
-
)
|
|
5091
|
-
header_specs = []
|
|
5092
|
-
if self.__header_color and background_hex(self.__header_color):
|
|
5093
|
-
drawn = sum(
|
|
5094
|
-
1 for i, _ in enumerate(column_widths)
|
|
5095
|
-
if i not in set(hidden)
|
|
5096
|
-
)
|
|
5097
|
-
header_specs = [self.__header_color] * drawn
|
|
5098
|
-
|
|
5099
|
-
superior = separators.superior_header_line
|
|
5100
|
-
if header_specs:
|
|
5101
|
-
superior = paint(superior, header_specs)
|
|
5102
|
-
elif border and superior is not None:
|
|
5103
|
-
superior = colorize(superior, border)
|
|
5104
|
-
|
|
5105
|
-
inferior = separators.inferior_header_line
|
|
5106
|
-
if first_specs:
|
|
5107
|
-
inferior = paint(inferior, first_specs)
|
|
5108
|
-
elif border and inferior is not None:
|
|
5109
|
-
inferior = colorize(inferior, border)
|
|
5110
|
-
|
|
5111
|
-
superior_nh = separators.superior_header_line_no_header
|
|
5112
|
-
if first_specs:
|
|
5113
|
-
superior_nh = paint(superior_nh, first_specs)
|
|
5114
|
-
elif border and superior_nh is not None:
|
|
5115
|
-
superior_nh = colorize(superior_nh, border)
|
|
5116
|
-
|
|
5117
|
-
end_line = separators.table_end_line
|
|
5118
|
-
if last_specs:
|
|
5119
|
-
end_line = paint(end_line, last_specs)
|
|
5120
|
-
elif border and end_line is not None:
|
|
5121
|
-
end_line = colorize(end_line, border)
|
|
5122
|
-
|
|
5123
|
-
plain_body = separators.table_body_line
|
|
5124
|
-
body_template = plain_body
|
|
5125
|
-
if border and body_template is not None and not first_specs:
|
|
5126
|
-
body_template = colorize(body_template, border)
|
|
5045
|
+
return colorize(line, border) if border else line
|
|
5127
5046
|
|
|
5128
5047
|
painted = HorizontalComposition(
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5048
|
+
paint(separators.superior_header_line),
|
|
5049
|
+
paint(separators.inferior_header_line),
|
|
5050
|
+
paint(separators.superior_header_line_no_header),
|
|
5051
|
+
paint(separators.table_body_line),
|
|
5052
|
+
paint(separators.table_end_line),
|
|
5134
5053
|
)
|
|
5135
5054
|
|
|
5055
|
+
plain_body = separators.table_body_line
|
|
5136
5056
|
gap_separator = None
|
|
5137
5057
|
if plain_body is not None and body_row_count:
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
return paint_rule_cell_backgrounds(
|
|
5143
|
-
_plain, layout, specs, border
|
|
5144
|
-
)
|
|
5058
|
+
chrome = paint(plain_body)
|
|
5059
|
+
|
|
5060
|
+
def gap_separator(after_row, _line=chrome):
|
|
5061
|
+
return _line
|
|
5145
5062
|
|
|
5146
5063
|
return painted, gap_separator
|
|
5147
5064
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.2
|
|
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
|
|
@@ -317,26 +317,30 @@ def test_html_and_excel_carry_merge_fill(tmp_path):
|
|
|
317
317
|
ws = openpyxl.load_workbook(path).active
|
|
318
318
|
assert ws['A2'].fill.fgColor.rgb.endswith('0891B2') or '0891B2' in str(ws['A2'].fill.fgColor.rgb)
|
|
319
319
|
|
|
320
|
-
def
|
|
321
|
-
"""H-rule
|
|
320
|
+
def test_horizontal_rules_stay_chrome_without_cell_bg():
|
|
321
|
+
"""H-rule glyphs stay chrome: cell fill must not leak onto ─ / junctions."""
|
|
322
|
+
import os
|
|
322
323
|
import re
|
|
324
|
+
os.environ['FORCE_COLOR'] = '1'
|
|
323
325
|
table = Table(style_name='double_horizontal_rows')
|
|
324
326
|
table.use_colors = True
|
|
325
327
|
table.add_column('A', ['a0', 'a1'])
|
|
326
328
|
table.add_column('B', ['b0', 'b1'])
|
|
327
329
|
table.column_colors = {'A': 'black on cyan', 'B': 'black on yellow'}
|
|
330
|
+
table.border_color = 'red'
|
|
328
331
|
rendered = str(table)
|
|
329
|
-
|
|
330
|
-
found_yellow_on_rule = False
|
|
332
|
+
rule_seen = False
|
|
331
333
|
for line in rendered.splitlines():
|
|
332
334
|
plain = re.sub('\x1b' r'\[[0-9;]*m', '', line)
|
|
333
335
|
if '─' not in plain and '═' not in plain:
|
|
334
336
|
continue
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
rule_seen = True
|
|
338
|
+
# Cell backgrounds (cyan 46 / yellow 43) must not appear on the rule.
|
|
339
|
+
assert '46m' not in line, line
|
|
340
|
+
assert '43m' not in line, line
|
|
341
|
+
# border_color (red) should wrap the rule.
|
|
342
|
+
assert '31m' in line, line
|
|
343
|
+
assert rule_seen
|
|
340
344
|
|
|
341
345
|
|
|
342
346
|
def test_border_color_foreground_on_modern_and_ascii():
|
|
@@ -86,16 +86,15 @@ def test_last_row_horizontal_merge_bottom_is_not_header_tee(style):
|
|
|
86
86
|
|
|
87
87
|
|
|
88
88
|
@pytest.mark.parametrize('style', ['double_horizontal', 'rounded_double_underline', 'dashed'])
|
|
89
|
-
def
|
|
89
|
+
def test_column_only_multi_col_merge_stays_square_without_cap(style):
|
|
90
90
|
table = _build_base(style)
|
|
91
|
+
before = str(table)
|
|
91
92
|
table.merge_cells(1, 0, last_column=1, value='AB')
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
assert len(bodyish) >= 2, lines # header + at least one cap or end
|
|
98
|
-
_square(str(table))
|
|
93
|
+
rendered = str(table)
|
|
94
|
+
lines = rendered.splitlines()
|
|
95
|
+
assert any('AB' in line for line in lines)
|
|
96
|
+
assert len(lines) == len(before.splitlines())
|
|
97
|
+
_square(rendered)
|
|
99
98
|
|
|
100
99
|
|
|
101
100
|
@pytest.mark.parametrize('style', ['double_horizontal', 'rounded_double_underline', 'dashed'])
|