flexablelib 2.0.10__tar.gz → 2.0.11__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.
Files changed (43) hide show
  1. {flexablelib-2.0.10 → flexablelib-2.0.11}/CHANGELOG.md +6 -0
  2. {flexablelib-2.0.10/flexablelib.egg-info → flexablelib-2.0.11}/PKG-INFO +1 -1
  3. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/merges.py +53 -4
  4. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/style_compositions.py +3 -2
  5. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/table.py +167 -13
  6. {flexablelib-2.0.10 → flexablelib-2.0.11/flexablelib.egg-info}/PKG-INFO +1 -1
  7. {flexablelib-2.0.10 → flexablelib-2.0.11}/package.json +1 -1
  8. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_features.py +25 -2
  9. {flexablelib-2.0.10 → flexablelib-2.0.11}/LICENSE +0 -0
  10. {flexablelib-2.0.10 → flexablelib-2.0.11}/MANIFEST.in +0 -0
  11. {flexablelib-2.0.10 → flexablelib-2.0.11}/README.md +0 -0
  12. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/__init__.py +0 -0
  13. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/_speedups.c +0 -0
  14. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/_width_tables.h +0 -0
  15. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/cells.py +0 -0
  16. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/colors.py +0 -0
  17. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/columns.py +0 -0
  18. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/fast.py +0 -0
  19. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/options.py +0 -0
  20. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/readers.py +0 -0
  21. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/table_strings.py +0 -0
  22. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/text_width.py +0 -0
  23. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/utils.py +0 -0
  24. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib/writers.py +0 -0
  25. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib.egg-info/SOURCES.txt +0 -0
  26. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib.egg-info/dependency_links.txt +0 -0
  27. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib.egg-info/requires.txt +0 -0
  28. {flexablelib-2.0.10 → flexablelib-2.0.11}/flexablelib.egg-info/top_level.txt +0 -0
  29. {flexablelib-2.0.10 → flexablelib-2.0.11}/setup.cfg +0 -0
  30. {flexablelib-2.0.10 → flexablelib-2.0.11}/setup.py +0 -0
  31. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_cells.py +0 -0
  32. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_columns.py +0 -0
  33. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_excel.py +0 -0
  34. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_issues.py +0 -0
  35. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_merge_edge_matrix.py +0 -0
  36. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_merges.py +0 -0
  37. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_readme_examples.py +0 -0
  38. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_styles.py +0 -0
  39. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_text_width.py +0 -0
  40. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_two_pass_measurement.py +0 -0
  41. {flexablelib-2.0.10 → flexablelib-2.0.11}/tests/test_upstream_issues.py +0 -0
  42. {flexablelib-2.0.10 → flexablelib-2.0.11}/tools/benchmark.py +0 -0
  43. {flexablelib-2.0.10 → flexablelib-2.0.11}/tools/generate_width_tables.py +0 -0
@@ -2,6 +2,12 @@
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
+ ## [2.0.11] - 2026-10-28
6
+
7
+ ### Added
8
+ - Horizontal rule cell backgrounds: dash runs on H-separators inherit the cell-above fill so coloured cells meet ─/═ without a dark band (generic; recommended with `flush`).
9
+ - `paint_rule_cell_backgrounds` helper; ANSI-aware junction glyph detection for painted rules.
10
+
5
11
  ## [2.0.10] - 2026-10-28
6
12
 
7
13
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.10
3
+ Version: 2.0.11
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -19,12 +19,13 @@ than the span it was given is truncated, not accommodated.
19
19
  import re
20
20
  from typing import List, NamedTuple, Optional
21
21
 
22
- from .colors import colorize
22
+ from .colors import background_hex, colorize
23
23
  from .fast import (
24
24
  has_ansi,
25
25
  pad_to_width,
26
26
  partition_by_width,
27
27
  slice_by_width,
28
+ strip_ansi,
28
29
  strip_by_width,
29
30
  truncate_to_width,
30
31
  visible_width,
@@ -274,13 +275,22 @@ _ASCII = {
274
275
  }
275
276
 
276
277
 
278
+ def _glyph(ch: str) -> str:
279
+ """Visible character from a slice that may still carry SGR wraps."""
280
+ if not ch:
281
+ return ''
282
+ plain = strip_ansi(ch)
283
+ return plain[:1] if plain else ''
284
+
285
+
277
286
  def _is_h(ch: str) -> bool:
278
- return ch in _H_CHARS
287
+ return _glyph(ch) in _H_CHARS
279
288
 
280
289
 
281
290
  def _visible_vertical(ch: str) -> bool:
282
291
  """True when a style's vertical glyph is a real column rule, not a spacer."""
283
- return bool(ch) and not ch.isspace()
292
+ g = _glyph(ch)
293
+ return bool(g) and not g.isspace()
284
294
 
285
295
 
286
296
  def _char_at(line: str, index: int) -> str:
@@ -487,7 +497,7 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
487
497
  continue
488
498
  here = _char_at(rewritten, x)
489
499
  # Interior of a multi-column vertical blank: junction was wiped to space.
490
- if here == ' ' or here == '':
500
+ if _glyph(here) in ('', ' '):
491
501
  continue
492
502
  left = _char_at(rewritten, x - 1)
493
503
  right = _char_at(rewritten, x + 1)
@@ -503,6 +513,45 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
503
513
  return rewritten
504
514
 
505
515
 
516
+
517
+ def paint_rule_cell_backgrounds(line, layout, column_specs, border_color=None):
518
+ """
519
+ Paint each column's dash run on a horizontal rule with that column's cell
520
+ background.
521
+
522
+ Terminal grid tables put H-rules on their own row. Without a background,
523
+ that row is a dark band between coloured cells (the ─ glyph is only a thin
524
+ stroke). Colouring the dash run with the cell above makes the fill meet the
525
+ rule. Junctions and outer corners stay outside the cell fill (same contract
526
+ as vertical borders in ``flush``).
527
+
528
+ ``column_specs`` is aligned with ``layout.spans`` (drawn columns). Specs
529
+ without a background are skipped. Paint right-to-left so ANSI insertion
530
+ does not shift later visible offsets.
531
+ """
532
+ if not line:
533
+ return line
534
+ if not column_specs or not any(
535
+ spec and background_hex(spec) is not None for spec in column_specs):
536
+ return colorize(line, border_color) if border_color else line
537
+
538
+ rewritten = line
539
+ for (start, end), spec in reversed(list(zip(layout.spans, column_specs))):
540
+ if end <= start:
541
+ continue
542
+ if not spec or background_hex(spec) is None:
543
+ continue
544
+ before, chunk, after = partition_by_width(rewritten, start, end)
545
+ plain = strip_ansi(chunk) if has_ansi(chunk) else chunk
546
+ if not plain:
547
+ continue
548
+ painted = colorize(plain, spec)
549
+ if has_ansi(chunk) and not painted.startswith(_RESET):
550
+ painted = _RESET + painted
551
+ rewritten = before + painted + after
552
+ return rewritten
553
+
554
+
506
555
  def apply(lines, row_line_map, regions, column_widths, composition,
507
556
  index_offset, hidden_columns=(), filler=' '):
508
557
  """
@@ -894,8 +894,9 @@ __style_compositions = Compositions(
894
894
  ),
895
895
  # Flush cell fills: full unicode grid whose cell backgrounds (pad-then-paint)
896
896
  # meet the border glyphs with no interior gap and never paint over them.
897
- # Recommended style for coloured cells and coloured merges. Same box as
898
- # pretty_grid; the name encodes the fill contract used by demos/docs.
897
+ # Horizontal rules also inherit the cell-above background on their dash
898
+ # runs so fills meet ─/═ without a dark band. Recommended for coloured
899
+ # cells and coloured merges. Same box as pretty_grid.
899
900
  flush=TableComposition(
900
901
  superior_header_line=SeparatorLine('╒', '═', '╤', '╕'),
901
902
  inferior_header_line=SeparatorLine('╞', '═', '╪', '╡'),
@@ -55,7 +55,7 @@ from .cells import (
55
55
  _wrap_rows,
56
56
  _zip_wrapped_rows
57
57
  )
58
- from .colors import colorize, supports_color
58
+ from .colors import background_hex, colorize, supports_color
59
59
 
60
60
  from copy import deepcopy
61
61
  from typing import (
@@ -2167,6 +2167,7 @@ class Table(object):
2167
2167
  or self.__column_colors
2168
2168
  or self.__row_colors
2169
2169
  or self.__color_rule
2170
+ or any(getattr(r, 'color', None) for r in self.__merged_regions)
2170
2171
  )
2171
2172
 
2172
2173
  @staticmethod
@@ -3837,7 +3838,10 @@ class Table(object):
3837
3838
  ),
3838
3839
  )
3839
3840
  aligned_columns = self.__zip_columns(aligned_columns)
3840
- # String separators and data rows are joined
3841
+ # String separators and data rows are joined. Horizontal rules stay
3842
+ # plain here; cell-background fills (and optional border_color) are
3843
+ # applied per segment below so coloured cells do not sit above a dark
3844
+ # H-rule band.
3841
3845
  separators: HorizontalComposition = _get_separators(
3842
3846
  self.__style_composition,
3843
3847
  column_widths_list,
@@ -3845,11 +3849,6 @@ class Table(object):
3845
3849
  self.__show_empty_columns,
3846
3850
  column_alignments_list,
3847
3851
  )
3848
- if colors_on and self.__border_color:
3849
- separators = HorizontalComposition(*[
3850
- colorize(line, self.__border_color) if line is not None else None
3851
- for line in separators
3852
- ])
3853
3852
  empty_rows_for_render = (
3854
3853
  self.__compose_empty_row_indexes
3855
3854
  if self.__compose_empty_row_indexes is not None
@@ -3865,6 +3864,22 @@ class Table(object):
3865
3864
  self.__border_color if colors_on else None,
3866
3865
  )
3867
3866
 
3867
+ header_row = data_rows.header_row
3868
+ body_rows = data_rows.body_rows
3869
+ gap_separator = None
3870
+ if colors_on:
3871
+ separators, gap_separator = self.__colour_horizontal_rules(
3872
+ separators,
3873
+ column_widths_list,
3874
+ column_titles,
3875
+ len(body_rows),
3876
+ )
3877
+ elif self.__border_color:
3878
+ separators = HorizontalComposition(*[
3879
+ colorize(line, self.__border_color) if line is not None else None
3880
+ for line in separators
3881
+ ])
3882
+
3868
3883
  # Table string is formed
3869
3884
  no_header_superior = separators.superior_header_line_no_header
3870
3885
  body_line = ''.join(['\n', separators.table_body_line]) if (
@@ -3872,8 +3887,6 @@ class Table(object):
3872
3887
  ) else NONE_VALUE_REPLACEMENT
3873
3888
 
3874
3889
  end_line = separators.table_end_line
3875
- header_row = data_rows.header_row
3876
- body_rows = data_rows.body_rows
3877
3890
 
3878
3891
  if self.__show_headers:
3879
3892
  superior_row = '\n'.join([
@@ -3892,7 +3905,8 @@ class Table(object):
3892
3905
  # joined in as an empty string, which is what used to put a blank
3893
3906
  # line through the middle of a table with no rows.
3894
3907
  body, body_line_map = self.__join_body_rows(
3895
- body_rows, body_line, separators.table_body_line
3908
+ body_rows, body_line, separators.table_body_line,
3909
+ gap_separator=gap_separator,
3896
3910
  )
3897
3911
  title_line = self.__title_line(column_widths_list, table_with_i)
3898
3912
 
@@ -3919,7 +3933,8 @@ class Table(object):
3919
3933
 
3920
3934
  return self.__apply_table_align(table_string)
3921
3935
 
3922
- def __join_body_rows(self, body_rows, body_line, separator_line):
3936
+ def __join_body_rows(self, body_rows, body_line, separator_line,
3937
+ gap_separator=None):
3923
3938
  """
3924
3939
  Join body rows, inserting extra divider rules where requested.
3925
3940
 
@@ -3928,6 +3943,10 @@ class Table(object):
3928
3943
  ``add_divider`` inserts a dashed line after the chosen row index
3929
3944
  (display order after filter/sort).
3930
3945
 
3946
+ ``gap_separator``, when set, is called as ``gap_separator(after_row)``
3947
+ to build the rule between that display row and the next (used to paint
3948
+ cell backgrounds onto H-rules).
3949
+
3931
3950
  Returns the joined body and a map from display row index to the
3932
3951
  physical lines that row occupies, numbered from the start of the body.
3933
3952
  Building the map here rather than reconstructing it afterwards is what
@@ -3958,8 +3977,11 @@ class Table(object):
3958
3977
  for display_i, row in enumerate(body_rows):
3959
3978
  if display_i:
3960
3979
  if separator_line is not None:
3961
- pieces.append(body_line[1:] if body_line.startswith('\n')
3962
- else body_line)
3980
+ if gap_separator is not None:
3981
+ pieces.append(gap_separator(display_i - 1))
3982
+ else:
3983
+ pieces.append(body_line[1:] if body_line.startswith('\n')
3984
+ else body_line)
3963
3985
  cursor += separator_lines
3964
3986
  elif (display_i - 1) in explicit_dividers:
3965
3987
  pieces.append(rule)
@@ -4045,6 +4067,138 @@ class Table(object):
4045
4067
  )
4046
4068
  return '\n'.join(merged)
4047
4069
 
4070
+
4071
+ def __rule_spec_for_cell(self, row_index, column_index, column_titles):
4072
+ """
4073
+ Colour that should back the H-rule segment under a cell.
4074
+
4075
+ Explicit merge colours win (so a wide merge paints one continuous
4076
+ band under its span). Otherwise the cell's resolved colour is used.
4077
+ """
4078
+ for region in self.__regions_with_colors():
4079
+ if (region.first_row <= row_index <= region.last_row
4080
+ and region.first_column <= column_index <= region.last_column
4081
+ and region.color):
4082
+ return region.color
4083
+ name = (
4084
+ column_titles[column_index]
4085
+ if column_index < len(column_titles) else ''
4086
+ )
4087
+ try:
4088
+ raw = self.__raw_value_at(column_titles, column_index, row_index)
4089
+ except Exception:
4090
+ raw = None
4091
+ return self.__color_for_cell(raw, row_index, name)
4092
+
4093
+ def __rule_specs_for_row(self, row_index, column_titles, column_widths):
4094
+ """One colour spec per *drawn* column for the rule under ``row_index``."""
4095
+ hidden = (
4096
+ () if self.__show_empty_columns else self.__empty_column_indexes
4097
+ )
4098
+ hidden = set(hidden)
4099
+ specs = []
4100
+ for col_i, _width in enumerate(column_widths):
4101
+ if col_i in hidden:
4102
+ continue
4103
+ specs.append(
4104
+ self.__rule_spec_for_cell(row_index, col_i, column_titles)
4105
+ )
4106
+ return specs
4107
+
4108
+ def __colour_horizontal_rules(self, separators, column_widths,
4109
+ column_titles, body_row_count):
4110
+ """
4111
+ Paint cell backgrounds onto horizontal rules.
4112
+
4113
+ Body gaps use the row above. The header/body rule uses the first body
4114
+ row (fill meets the header separator from below). The end rule uses
4115
+ the last body row. Superior header keeps ``border_color`` only unless
4116
+ ``header_color`` carries a background.
4117
+ Returns the updated HorizontalComposition and a gap painter callable
4118
+ (or None when the style has no body rule).
4119
+ """
4120
+ from .merges import compute_layout, paint_rule_cell_backgrounds
4121
+
4122
+ hidden = (
4123
+ () if self.__show_empty_columns else self.__empty_column_indexes
4124
+ )
4125
+ layout = compute_layout(
4126
+ column_widths, self.__style_composition, hidden
4127
+ )
4128
+ border = self.__border_color
4129
+
4130
+ def paint(line, specs):
4131
+ if line is None:
4132
+ return None
4133
+ return paint_rule_cell_backgrounds(line, layout, specs, border)
4134
+
4135
+ first_specs = (
4136
+ self.__rule_specs_for_row(0, column_titles, column_widths)
4137
+ if body_row_count else []
4138
+ )
4139
+ last_specs = (
4140
+ self.__rule_specs_for_row(
4141
+ body_row_count - 1, column_titles, column_widths
4142
+ )
4143
+ if body_row_count else []
4144
+ )
4145
+ header_specs = []
4146
+ if self.__header_color and background_hex(self.__header_color):
4147
+ drawn = sum(
4148
+ 1 for i, _ in enumerate(column_widths)
4149
+ if i not in set(hidden)
4150
+ )
4151
+ header_specs = [self.__header_color] * drawn
4152
+
4153
+ superior = separators.superior_header_line
4154
+ if header_specs:
4155
+ superior = paint(superior, header_specs)
4156
+ elif border and superior is not None:
4157
+ superior = colorize(superior, border)
4158
+
4159
+ inferior = separators.inferior_header_line
4160
+ if first_specs:
4161
+ inferior = paint(inferior, first_specs)
4162
+ elif border and inferior is not None:
4163
+ inferior = colorize(inferior, border)
4164
+
4165
+ superior_nh = separators.superior_header_line_no_header
4166
+ if first_specs:
4167
+ superior_nh = paint(superior_nh, first_specs)
4168
+ elif border and superior_nh is not None:
4169
+ superior_nh = colorize(superior_nh, border)
4170
+
4171
+ end_line = separators.table_end_line
4172
+ if last_specs:
4173
+ end_line = paint(end_line, last_specs)
4174
+ elif border and end_line is not None:
4175
+ end_line = colorize(end_line, border)
4176
+
4177
+ plain_body = separators.table_body_line
4178
+ body_template = plain_body
4179
+ if border and body_template is not None and not first_specs:
4180
+ body_template = colorize(body_template, border)
4181
+
4182
+ painted = HorizontalComposition(
4183
+ superior,
4184
+ inferior,
4185
+ superior_nh,
4186
+ body_template if not first_specs else plain_body,
4187
+ end_line,
4188
+ )
4189
+
4190
+ gap_separator = None
4191
+ if plain_body is not None and body_row_count:
4192
+ def gap_separator(after_row, _plain=plain_body):
4193
+ specs = self.__rule_specs_for_row(
4194
+ after_row, column_titles, column_widths
4195
+ )
4196
+ return paint_rule_cell_backgrounds(
4197
+ _plain, layout, specs, border
4198
+ )
4199
+
4200
+ return painted, gap_separator
4201
+
4048
4202
  def __regions_with_colors(self):
4049
4203
  """
4050
4204
  Merged regions with an effective colour for this render.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.10
3
+ Version: 2.0.11
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
5
5
  "main": "__init__.py",
6
6
  "scripts": {
@@ -4,6 +4,8 @@ Public API coverage for the high-demand features.
4
4
  Each test drives the shipped Table entry point and asserts concrete output.
5
5
  """
6
6
 
7
+ import pytest
8
+
7
9
  from helpers import table_width
8
10
  from flexablelib import Table
9
11
 
@@ -311,8 +313,29 @@ def test_html_and_excel_carry_merge_fill(tmp_path):
311
313
  table.merge_cells(0, 0, last_column=1, value='BOX', color='black on cyan')
312
314
  html = table.to_html(title='m')
313
315
  assert 'background-color' in html
316
+ openpyxl = pytest.importorskip('openpyxl')
314
317
  path = tmp_path / 'm.xlsx'
315
318
  table.to_excel(path)
316
- from openpyxl import load_workbook
317
- ws = load_workbook(path).active
319
+ ws = openpyxl.load_workbook(path).active
318
320
  assert ws['A2'].fill.fgColor.rgb.endswith('0891B2') or '0891B2' in str(ws['A2'].fill.fgColor.rgb)
321
+
322
+ def test_flush_horizontal_rules_carry_cell_bg():
323
+ """H-rule dash runs inherit the cell-above background (no dark band)."""
324
+ import re
325
+ table = Table(style_name='flush')
326
+ table.use_colors = True
327
+ table.add_column('A', ['a0', 'a1'])
328
+ table.add_column('B', ['b0', 'b1'])
329
+ table.column_colors = {'A': 'black on cyan', 'B': 'black on yellow'}
330
+ rendered = str(table)
331
+ found_cyan_on_rule = False
332
+ found_yellow_on_rule = False
333
+ for line in rendered.splitlines():
334
+ plain = re.sub('\x1b' r'\[[0-9;]*m', '', line)
335
+ if '─' not in plain and '═' not in plain:
336
+ continue
337
+ if '46m' in line:
338
+ found_cyan_on_rule = True
339
+ if '43m' in line:
340
+ found_yellow_on_rule = True
341
+ assert found_cyan_on_rule and found_yellow_on_rule
File without changes
File without changes
File without changes
File without changes
File without changes