flexablelib 2.0.10__tar.gz → 2.0.12__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.12}/CHANGELOG.md +23 -0
  2. {flexablelib-2.0.10/flexablelib.egg-info → flexablelib-2.0.12}/PKG-INFO +2 -2
  3. {flexablelib-2.0.10 → flexablelib-2.0.12}/README.md +1 -1
  4. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/merges.py +53 -4
  5. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/style_compositions.py +242 -10
  6. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/table.py +442 -13
  7. {flexablelib-2.0.10 → flexablelib-2.0.12/flexablelib.egg-info}/PKG-INFO +2 -2
  8. {flexablelib-2.0.10 → flexablelib-2.0.12}/package.json +1 -1
  9. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_features.py +88 -7
  10. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_styles.py +23 -1
  11. {flexablelib-2.0.10 → flexablelib-2.0.12}/LICENSE +0 -0
  12. {flexablelib-2.0.10 → flexablelib-2.0.12}/MANIFEST.in +0 -0
  13. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/__init__.py +0 -0
  14. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/_speedups.c +0 -0
  15. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/_width_tables.h +0 -0
  16. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/cells.py +0 -0
  17. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/colors.py +0 -0
  18. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/columns.py +0 -0
  19. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/fast.py +0 -0
  20. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/options.py +0 -0
  21. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/readers.py +0 -0
  22. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/table_strings.py +0 -0
  23. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/text_width.py +0 -0
  24. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/utils.py +0 -0
  25. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib/writers.py +0 -0
  26. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib.egg-info/SOURCES.txt +0 -0
  27. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib.egg-info/dependency_links.txt +0 -0
  28. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib.egg-info/requires.txt +0 -0
  29. {flexablelib-2.0.10 → flexablelib-2.0.12}/flexablelib.egg-info/top_level.txt +0 -0
  30. {flexablelib-2.0.10 → flexablelib-2.0.12}/setup.cfg +0 -0
  31. {flexablelib-2.0.10 → flexablelib-2.0.12}/setup.py +0 -0
  32. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_cells.py +0 -0
  33. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_columns.py +0 -0
  34. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_excel.py +0 -0
  35. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_issues.py +0 -0
  36. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_merge_edge_matrix.py +0 -0
  37. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_merges.py +0 -0
  38. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_readme_examples.py +0 -0
  39. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_text_width.py +0 -0
  40. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_two_pass_measurement.py +0 -0
  41. {flexablelib-2.0.10 → flexablelib-2.0.12}/tests/test_upstream_issues.py +0 -0
  42. {flexablelib-2.0.10 → flexablelib-2.0.12}/tools/benchmark.py +0 -0
  43. {flexablelib-2.0.10 → flexablelib-2.0.12}/tools/generate_width_tables.py +0 -0
@@ -2,6 +2,29 @@
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.12] - 2026-10-28
6
+
7
+ ### Removed
8
+ - ``flush`` style (colour-fill experiments). Use ``blocks`` for borderless
9
+ fills, or any bordered style with ``border_color`` / cell colours.
10
+
11
+ ### Added
12
+ - tabled-compatible style names: ``ascii``, ``modern``, ``sharp``, ``rounded``,
13
+ ``modern_rounded``, ``extended``, ``psql``, ``markdown``, ``re_structured_text``,
14
+ ``dots``, ``ascii_rounded``, ``blank``, ``empty`` (glyphs aligned with
15
+ [tabled](https://github.com/zhiburt/tabled) Style presets).
16
+ - ``Table.border_text(text, where=..., color=..., offset=..., align=...)`` —
17
+ overlay coloured text on horizontal or vertical borders (tabled LineText).
18
+ ``clear_border_texts()`` resets overlays.
19
+ - ``border_color`` documents FG paint of border/rule/junction glyphs on any
20
+ style (including the new tabled names).
21
+
22
+ ## [2.0.11] - 2026-10-28
23
+
24
+ ### Added
25
+ - 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`).
26
+ - `paint_rule_cell_backgrounds` helper; ANSI-aware junction glyph detection for painted rules.
27
+
5
28
  ## [2.0.10] - 2026-10-28
6
29
 
7
30
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.10
3
+ Version: 2.0.12
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -355,7 +355,7 @@ flexablelib/ # GitHub repository
355
355
  ├── docs/ issue history and design notes
356
356
  ├── logos/ brand assets — see logos/README.md
357
357
  ├── ARCHITECTURE.md how it all fits together
358
- ├── style_examples.md all 44 styles rendered
358
+ ├── style_examples.md all 56 styles rendered
359
359
  ├── package.json canonical version number; drives the release
360
360
  └── setup.py reads the version from package.json
361
361
  ```
@@ -306,7 +306,7 @@ flexablelib/ # GitHub repository
306
306
  ├── docs/ issue history and design notes
307
307
  ├── logos/ brand assets — see logos/README.md
308
308
  ├── ARCHITECTURE.md how it all fits together
309
- ├── style_examples.md all 44 styles rendered
309
+ ├── style_examples.md all 56 styles rendered
310
310
  ├── package.json canonical version number; drives the release
311
311
  └── setup.py reads the version from package.json
312
312
  ```
@@ -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
  """
@@ -133,7 +133,21 @@ Compositions = namedtuple(
133
133
 
134
134
  # Fill-only (background colours, no border glyphs)
135
135
  'blocks',
136
- 'flush',
136
+
137
+ # tabled-compatible names (https://github.com/zhiburt/tabled)
138
+ 'ascii',
139
+ 'modern',
140
+ 'sharp',
141
+ 'rounded',
142
+ 'modern_rounded',
143
+ 'extended',
144
+ 'psql',
145
+ 'markdown',
146
+ 're_structured_text',
147
+ 'dots',
148
+ 'ascii_rounded',
149
+ 'blank',
150
+ 'empty',
137
151
  ]
138
152
  )
139
153
 
@@ -892,16 +906,54 @@ __style_compositions = Compositions(
892
906
  align_indicator_margin=0,
893
907
  always_center_indicator=False
894
908
  ),
895
- # Flush cell fills: full unicode grid whose cell backgrounds (pad-then-paint)
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.
899
- flush=TableComposition(
900
- superior_header_line=SeparatorLine('╒', '═', '╤', '╕'),
901
- inferior_header_line=SeparatorLine('╞', '═', '╪', '╡'),
902
- superior_header_line_no_header=SeparatorLine('╒', '═', '╤', '╕'),
909
+
910
+ ############################################
911
+ #### tabled-compatible style names ####
912
+ #### https://github.com/zhiburt/tabled ####
913
+ ############################################
914
+ # ascii: full ASCII grid; all rules use '-' (unlike grid which uses '=' under the header).
915
+ ascii=TableComposition(
916
+ superior_header_line=SeparatorLine('+', '-', '+', '+'),
917
+ inferior_header_line=SeparatorLine('+', '-', '+', '+'),
918
+ superior_header_line_no_header=SeparatorLine('+', '-', '+', '+'),
919
+ table_body_line=SeparatorLine('+', '-', '+', '+'),
920
+ table_end_line=SeparatorLine('+', '-', '+', '+'),
921
+ vertical_header_lines=SeparatorLine('|', '|', None, '|'),
922
+ vertical_table_body_lines=SeparatorLine('|', '|', None, '|'),
923
+ margin=CELL_MARGIN,
924
+ align_sensitive=False,
925
+ align_indicator=None,
926
+ centered_indicator_on_sides=False,
927
+ left_and_right_when_centered=False,
928
+ lines_with_indicator=[],
929
+ align_indicator_margin=0,
930
+ always_center_indicator=False
931
+ ),
932
+ # modern: UTF-8 thin box with body horizontals; header rule is also ─ (not ═).
933
+ modern=TableComposition(
934
+ superior_header_line=SeparatorLine('┌', '─', '┬', '┐'),
935
+ inferior_header_line=SeparatorLine('├', '─', '┼', '┤'),
936
+ superior_header_line_no_header=SeparatorLine('┌', '─', '┬', '┐'),
903
937
  table_body_line=SeparatorLine('├', '─', '┼', '┤'),
904
- table_end_line=SeparatorLine('╘', '═', '╧', '╛'),
938
+ table_end_line=SeparatorLine('└', '─', '┴', '┘'),
939
+ vertical_header_lines=SeparatorLine('│', '│', None, '│'),
940
+ vertical_table_body_lines=SeparatorLine('│', '│', None, '│'),
941
+ margin=CELL_MARGIN,
942
+ align_sensitive=False,
943
+ align_indicator=None,
944
+ centered_indicator_on_sides=False,
945
+ left_and_right_when_centered=False,
946
+ lines_with_indicator=[],
947
+ align_indicator_margin=0,
948
+ always_center_indicator=False
949
+ ),
950
+ # sharp: modern frame without body horizontals.
951
+ sharp=TableComposition(
952
+ superior_header_line=SeparatorLine('┌', '─', '┬', '┐'),
953
+ inferior_header_line=SeparatorLine('├', '─', '┼', '┤'),
954
+ superior_header_line_no_header=SeparatorLine('┌', '─', '┬', '┐'),
955
+ table_body_line=None,
956
+ table_end_line=SeparatorLine('└', '─', '┴', '┘'),
905
957
  vertical_header_lines=SeparatorLine('│', '│', None, '│'),
906
958
  vertical_table_body_lines=SeparatorLine('│', '│', None, '│'),
907
959
  margin=CELL_MARGIN,
@@ -912,5 +964,185 @@ __style_compositions = Compositions(
912
964
  lines_with_indicator=[],
913
965
  align_indicator_margin=0,
914
966
  always_center_indicator=False
967
+ ),
968
+ # rounded: sharp with rounded corners.
969
+ rounded=TableComposition(
970
+ superior_header_line=SeparatorLine('╭', '─', '┬', '╮'),
971
+ inferior_header_line=SeparatorLine('├', '─', '┼', '┤'),
972
+ superior_header_line_no_header=SeparatorLine('╭', '─', '┬', '╮'),
973
+ table_body_line=None,
974
+ table_end_line=SeparatorLine('╰', '─', '┴', '╯'),
975
+ vertical_header_lines=SeparatorLine('│', '│', None, '│'),
976
+ vertical_table_body_lines=SeparatorLine('│', '│', None, '│'),
977
+ margin=CELL_MARGIN,
978
+ align_sensitive=False,
979
+ align_indicator=None,
980
+ centered_indicator_on_sides=False,
981
+ left_and_right_when_centered=False,
982
+ lines_with_indicator=[],
983
+ align_indicator_margin=0,
984
+ always_center_indicator=False
985
+ ),
986
+ # modern_rounded: rounded corners with body horizontals.
987
+ modern_rounded=TableComposition(
988
+ superior_header_line=SeparatorLine('╭', '─', '┬', '╮'),
989
+ inferior_header_line=SeparatorLine('├', '─', '┼', '┤'),
990
+ superior_header_line_no_header=SeparatorLine('╭', '─', '┬', '╮'),
991
+ table_body_line=SeparatorLine('├', '─', '┼', '┤'),
992
+ table_end_line=SeparatorLine('╰', '─', '┴', '╯'),
993
+ vertical_header_lines=SeparatorLine('│', '│', None, '│'),
994
+ vertical_table_body_lines=SeparatorLine('│', '│', None, '│'),
995
+ margin=CELL_MARGIN,
996
+ align_sensitive=False,
997
+ align_indicator=None,
998
+ centered_indicator_on_sides=False,
999
+ left_and_right_when_centered=False,
1000
+ lines_with_indicator=[],
1001
+ align_indicator_margin=0,
1002
+ always_center_indicator=False
1003
+ ),
1004
+ # extended: double-line box (all ═/║ junctions).
1005
+ extended=TableComposition(
1006
+ superior_header_line=SeparatorLine('╔', '═', '╦', '╗'),
1007
+ inferior_header_line=SeparatorLine('╠', '═', '╬', '╣'),
1008
+ superior_header_line_no_header=SeparatorLine('╔', '═', '╦', '╗'),
1009
+ table_body_line=SeparatorLine('╠', '═', '╬', '╣'),
1010
+ table_end_line=SeparatorLine('╚', '═', '╩', '╝'),
1011
+ vertical_header_lines=SeparatorLine('║', '║', None, '║'),
1012
+ vertical_table_body_lines=SeparatorLine('║', '║', None, '║'),
1013
+ margin=CELL_MARGIN,
1014
+ align_sensitive=False,
1015
+ align_indicator=None,
1016
+ centered_indicator_on_sides=False,
1017
+ left_and_right_when_centered=False,
1018
+ lines_with_indicator=[],
1019
+ align_indicator_margin=0,
1020
+ always_center_indicator=False
1021
+ ),
1022
+ # psql: PostgreSQL-like; header rule only, no outer frame.
1023
+ psql=TableComposition(
1024
+ superior_header_line=None,
1025
+ inferior_header_line=SeparatorLine(None, '-', '+', None),
1026
+ superior_header_line_no_header=None,
1027
+ table_body_line=None,
1028
+ table_end_line=None,
1029
+ vertical_header_lines=SeparatorLine(None, '|', None, None),
1030
+ vertical_table_body_lines=SeparatorLine(None, '|', None, None),
1031
+ margin=CELL_MARGIN,
1032
+ align_sensitive=False,
1033
+ align_indicator=None,
1034
+ centered_indicator_on_sides=False,
1035
+ left_and_right_when_centered=False,
1036
+ lines_with_indicator=[],
1037
+ align_indicator_margin=0,
1038
+ always_center_indicator=False
1039
+ ),
1040
+ # markdown: GitHub-flavoured markdown pipe table.
1041
+ markdown=TableComposition(
1042
+ superior_header_line=None,
1043
+ inferior_header_line=SeparatorLine('|', '-', '|', '|'),
1044
+ superior_header_line_no_header=SeparatorLine('|', '-', '|', '|'),
1045
+ table_body_line=None,
1046
+ table_end_line=None,
1047
+ vertical_header_lines=SeparatorLine('|', '|', None, '|'),
1048
+ vertical_table_body_lines=SeparatorLine('|', '|', None, '|'),
1049
+ margin=CELL_MARGIN,
1050
+ align_sensitive=False,
1051
+ align_indicator=None,
1052
+ centered_indicator_on_sides=False,
1053
+ left_and_right_when_centered=False,
1054
+ lines_with_indicator=[],
1055
+ align_indicator_margin=0,
1056
+ always_center_indicator=False
1057
+ ),
1058
+ # re_structured_text: RST simple table (== rules, space gutters).
1059
+ re_structured_text=TableComposition(
1060
+ superior_header_line=SeparatorLine(None, '=', ' ', None),
1061
+ inferior_header_line=SeparatorLine(None, '=', ' ', None),
1062
+ superior_header_line_no_header=SeparatorLine(None, '=', ' ', None),
1063
+ table_body_line=None,
1064
+ table_end_line=SeparatorLine(None, '=', ' ', None),
1065
+ vertical_header_lines=SeparatorLine(None, INVISIBLE_SEPARATOR, None, None),
1066
+ vertical_table_body_lines=SeparatorLine(None, INVISIBLE_SEPARATOR, None, None),
1067
+ margin=CELL_MARGIN,
1068
+ align_sensitive=False,
1069
+ align_indicator=None,
1070
+ centered_indicator_on_sides=False,
1071
+ left_and_right_when_centered=False,
1072
+ lines_with_indicator=[],
1073
+ align_indicator_margin=0,
1074
+ always_center_indicator=False
1075
+ ),
1076
+ # dots: '.' frame / horizontals and ':' verticals (tabled Style::dots).
1077
+ dots=TableComposition(
1078
+ superior_header_line=SeparatorLine('.', '.', '.', '.'),
1079
+ inferior_header_line=SeparatorLine(':', '.', ':', ':'),
1080
+ superior_header_line_no_header=SeparatorLine('.', '.', '.', '.'),
1081
+ table_body_line=SeparatorLine(':', '.', ':', ':'),
1082
+ table_end_line=SeparatorLine(':', '.', ':', ':'),
1083
+ vertical_header_lines=SeparatorLine(':', ':', None, ':'),
1084
+ vertical_table_body_lines=SeparatorLine(':', ':', None, ':'),
1085
+ margin=CELL_MARGIN,
1086
+ align_sensitive=False,
1087
+ align_indicator=None,
1088
+ centered_indicator_on_sides=False,
1089
+ left_and_right_when_centered=False,
1090
+ lines_with_indicator=[],
1091
+ align_indicator_margin=0,
1092
+ always_center_indicator=False
1093
+ ),
1094
+ # ascii_rounded: '.' / "'" corners, no header or body horizontals.
1095
+ ascii_rounded=TableComposition(
1096
+ superior_header_line=SeparatorLine('.', '-', '-', '.'),
1097
+ inferior_header_line=None,
1098
+ superior_header_line_no_header=SeparatorLine('.', '-', '-', '.'),
1099
+ table_body_line=None,
1100
+ table_end_line=SeparatorLine("'", '-', '-', "'"),
1101
+ vertical_header_lines=SeparatorLine('|', '|', None, '|'),
1102
+ vertical_table_body_lines=SeparatorLine('|', '|', None, '|'),
1103
+ margin=CELL_MARGIN,
1104
+ align_sensitive=False,
1105
+ align_indicator=None,
1106
+ centered_indicator_on_sides=False,
1107
+ left_and_right_when_centered=False,
1108
+ lines_with_indicator=[],
1109
+ align_indicator_margin=0,
1110
+ always_center_indicator=False
1111
+ ),
1112
+ # blank: no rules; columns separated by a space (with cell margin).
1113
+ blank=TableComposition(
1114
+ superior_header_line=None,
1115
+ inferior_header_line=None,
1116
+ superior_header_line_no_header=None,
1117
+ table_body_line=None,
1118
+ table_end_line=None,
1119
+ vertical_header_lines=SeparatorLine(None, ' ', None, None),
1120
+ vertical_table_body_lines=SeparatorLine(None, ' ', None, None),
1121
+ margin=CELL_MARGIN,
1122
+ align_sensitive=False,
1123
+ align_indicator=None,
1124
+ centered_indicator_on_sides=False,
1125
+ left_and_right_when_centered=False,
1126
+ lines_with_indicator=[],
1127
+ align_indicator_margin=0,
1128
+ always_center_indicator=False
1129
+ ),
1130
+ # empty: no chrome and no margin (tabled Style::empty base).
1131
+ empty=TableComposition(
1132
+ superior_header_line=None,
1133
+ inferior_header_line=None,
1134
+ superior_header_line_no_header=None,
1135
+ table_body_line=None,
1136
+ table_end_line=None,
1137
+ vertical_header_lines=SeparatorLine(None, INVISIBLE_SEPARATOR, None, None),
1138
+ vertical_table_body_lines=SeparatorLine(None, INVISIBLE_SEPARATOR, None, None),
1139
+ margin=0,
1140
+ align_sensitive=False,
1141
+ align_indicator=None,
1142
+ centered_indicator_on_sides=False,
1143
+ left_and_right_when_centered=False,
1144
+ lines_with_indicator=[],
1145
+ align_indicator_margin=0,
1146
+ always_center_indicator=False
915
1147
  )
916
1148
  )
@@ -26,6 +26,7 @@ from .columns import (
26
26
  ALIGNMENTS_PER_TYPE as type_alignments
27
27
  )
28
28
  from .fast import truncate_to_width, visible_width, wrap_to_width
29
+ from .text_width import strip_ansi
29
30
  from .table_strings import (
30
31
  _get_separators,
31
32
  _get_data_rows,
@@ -55,7 +56,7 @@ from .cells import (
55
56
  _wrap_rows,
56
57
  _zip_wrapped_rows
57
58
  )
58
- from .colors import colorize, supports_color
59
+ from .colors import background_hex, colorize, supports_color
59
60
 
60
61
  from copy import deepcopy
61
62
  from typing import (
@@ -827,6 +828,8 @@ class Table(object):
827
828
  # cell. None everywhere means no colour and no cost.
828
829
  self.__header_color = None
829
830
  self.__border_color = None
831
+ # LineText-style overlays (tabled): text drawn onto border runs.
832
+ self.__border_texts = []
830
833
  self.__column_colors = {}
831
834
  self.__row_colors = {}
832
835
  self.__color_rule = None
@@ -2068,6 +2071,69 @@ class Table(object):
2068
2071
  def border_color(self, value):
2069
2072
  self.__border_color = value
2070
2073
 
2074
+ def border_text(self, text, where='top', color=None, offset=1, align='left'):
2075
+ """
2076
+ Overlay ``text`` on a border line (inspired by tabled ``LineText``).
2077
+
2078
+ ``where`` selects the target rule or vertical::
2079
+
2080
+ 'top' / 'superior_header' – top frame
2081
+ 'header' / 'header_rule' – rule under the header
2082
+ 'body' / 'body_rule' – inter-row body rules
2083
+ 'bottom' / 'end' – bottom frame
2084
+ 'left' / 'right' – vertical outer borders
2085
+
2086
+ ``offset`` is the visible column (horizontal) or row (vertical) where
2087
+ the text starts; junctions outside the span are preserved when the
2088
+ text does not overwrite them. ``color`` paints the text foreground
2089
+ (``border_color`` still paints the remaining chrome). ``align`` is
2090
+ ``left``, ``center``, or ``right`` within the writable span when
2091
+ ``offset`` is None.
2092
+
2093
+ Multiple calls accumulate; use ``clear_border_texts()`` to reset.
2094
+ """
2095
+ where_key = str(where).strip().lower()
2096
+ aliases = {
2097
+ 'top': 'top',
2098
+ 'superior': 'top',
2099
+ 'superior_header': 'top',
2100
+ 'header': 'header',
2101
+ 'header_rule': 'header',
2102
+ 'inferior_header': 'header',
2103
+ 'body': 'body',
2104
+ 'body_rule': 'body',
2105
+ 'table_body': 'body',
2106
+ 'bottom': 'bottom',
2107
+ 'end': 'bottom',
2108
+ 'table_end': 'bottom',
2109
+ 'left': 'left',
2110
+ 'right': 'right',
2111
+ }
2112
+ if where_key not in aliases:
2113
+ raise ValueError(
2114
+ f"Unknown border_text where={where!r}; "
2115
+ f"expected one of {sorted(set(aliases.values()))}"
2116
+ )
2117
+ align_key = (align or 'left').lower()
2118
+ if align_key not in ('left', 'center', 'right', 'l', 'c', 'r'):
2119
+ raise ValueError(f"Unknown border_text align={align!r}")
2120
+ align_key = {'l': 'left', 'c': 'center', 'r': 'right'}.get(
2121
+ align_key, align_key
2122
+ )
2123
+ self.__border_texts.append({
2124
+ 'text': '' if text is None else str(text),
2125
+ 'where': aliases[where_key],
2126
+ 'color': color,
2127
+ 'offset': offset,
2128
+ 'align': align_key,
2129
+ })
2130
+ return self
2131
+
2132
+ def clear_border_texts(self):
2133
+ """Remove every overlay registered with ``border_text``."""
2134
+ self.__border_texts = []
2135
+ return self
2136
+
2071
2137
  @property
2072
2138
  def column_colors(self) -> dict:
2073
2139
  """
@@ -2167,6 +2233,7 @@ class Table(object):
2167
2233
  or self.__column_colors
2168
2234
  or self.__row_colors
2169
2235
  or self.__color_rule
2236
+ or any(getattr(r, 'color', None) for r in self.__merged_regions)
2170
2237
  )
2171
2238
 
2172
2239
  @staticmethod
@@ -3837,7 +3904,10 @@ class Table(object):
3837
3904
  ),
3838
3905
  )
3839
3906
  aligned_columns = self.__zip_columns(aligned_columns)
3840
- # String separators and data rows are joined
3907
+ # String separators and data rows are joined. Horizontal rules stay
3908
+ # plain here; cell-background fills (and optional border_color) are
3909
+ # applied per segment below so coloured cells do not sit above a dark
3910
+ # H-rule band.
3841
3911
  separators: HorizontalComposition = _get_separators(
3842
3912
  self.__style_composition,
3843
3913
  column_widths_list,
@@ -3845,11 +3915,6 @@ class Table(object):
3845
3915
  self.__show_empty_columns,
3846
3916
  column_alignments_list,
3847
3917
  )
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
3918
  empty_rows_for_render = (
3854
3919
  self.__compose_empty_row_indexes
3855
3920
  if self.__compose_empty_row_indexes is not None
@@ -3865,6 +3930,27 @@ class Table(object):
3865
3930
  self.__border_color if colors_on else None,
3866
3931
  )
3867
3932
 
3933
+ header_row = data_rows.header_row
3934
+ body_rows = data_rows.body_rows
3935
+ gap_separator = None
3936
+ if colors_on:
3937
+ separators, gap_separator = self.__colour_horizontal_rules(
3938
+ separators,
3939
+ column_widths_list,
3940
+ column_titles,
3941
+ len(body_rows),
3942
+ )
3943
+ elif self.__border_color:
3944
+ separators = HorizontalComposition(*[
3945
+ colorize(line, self.__border_color) if line is not None else None
3946
+ for line in separators
3947
+ ])
3948
+
3949
+ if self.__border_texts:
3950
+ separators, gap_separator = self.__apply_horizontal_border_texts(
3951
+ separators, gap_separator
3952
+ )
3953
+
3868
3954
  # Table string is formed
3869
3955
  no_header_superior = separators.superior_header_line_no_header
3870
3956
  body_line = ''.join(['\n', separators.table_body_line]) if (
@@ -3872,8 +3958,6 @@ class Table(object):
3872
3958
  ) else NONE_VALUE_REPLACEMENT
3873
3959
 
3874
3960
  end_line = separators.table_end_line
3875
- header_row = data_rows.header_row
3876
- body_rows = data_rows.body_rows
3877
3961
 
3878
3962
  if self.__show_headers:
3879
3963
  superior_row = '\n'.join([
@@ -3892,7 +3976,8 @@ class Table(object):
3892
3976
  # joined in as an empty string, which is what used to put a blank
3893
3977
  # line through the middle of a table with no rows.
3894
3978
  body, body_line_map = self.__join_body_rows(
3895
- body_rows, body_line, separators.table_body_line
3979
+ body_rows, body_line, separators.table_body_line,
3980
+ gap_separator=gap_separator,
3896
3981
  )
3897
3982
  title_line = self.__title_line(column_widths_list, table_with_i)
3898
3983
 
@@ -3917,9 +4002,13 @@ class Table(object):
3917
4002
  column_widths_list, table_with_i
3918
4003
  )
3919
4004
 
4005
+ if self.__border_texts:
4006
+ table_string = self.__apply_vertical_border_texts(table_string)
4007
+
3920
4008
  return self.__apply_table_align(table_string)
3921
4009
 
3922
- def __join_body_rows(self, body_rows, body_line, separator_line):
4010
+ def __join_body_rows(self, body_rows, body_line, separator_line,
4011
+ gap_separator=None):
3923
4012
  """
3924
4013
  Join body rows, inserting extra divider rules where requested.
3925
4014
 
@@ -3928,6 +4017,10 @@ class Table(object):
3928
4017
  ``add_divider`` inserts a dashed line after the chosen row index
3929
4018
  (display order after filter/sort).
3930
4019
 
4020
+ ``gap_separator``, when set, is called as ``gap_separator(after_row)``
4021
+ to build the rule between that display row and the next (used to paint
4022
+ cell backgrounds onto H-rules).
4023
+
3931
4024
  Returns the joined body and a map from display row index to the
3932
4025
  physical lines that row occupies, numbered from the start of the body.
3933
4026
  Building the map here rather than reconstructing it afterwards is what
@@ -3958,8 +4051,11 @@ class Table(object):
3958
4051
  for display_i, row in enumerate(body_rows):
3959
4052
  if display_i:
3960
4053
  if separator_line is not None:
3961
- pieces.append(body_line[1:] if body_line.startswith('\n')
3962
- else body_line)
4054
+ if gap_separator is not None:
4055
+ pieces.append(gap_separator(display_i - 1))
4056
+ else:
4057
+ pieces.append(body_line[1:] if body_line.startswith('\n')
4058
+ else body_line)
3963
4059
  cursor += separator_lines
3964
4060
  elif (display_i - 1) in explicit_dividers:
3965
4061
  pieces.append(rule)
@@ -4045,6 +4141,339 @@ class Table(object):
4045
4141
  )
4046
4142
  return '\n'.join(merged)
4047
4143
 
4144
+
4145
+ def __rule_spec_for_cell(self, row_index, column_index, column_titles):
4146
+ """
4147
+ Colour that should back the H-rule segment under a cell.
4148
+
4149
+ Explicit merge colours win (so a wide merge paints one continuous
4150
+ band under its span). Otherwise the cell's resolved colour is used.
4151
+ """
4152
+ for region in self.__regions_with_colors():
4153
+ if (region.first_row <= row_index <= region.last_row
4154
+ and region.first_column <= column_index <= region.last_column
4155
+ and region.color):
4156
+ return region.color
4157
+ name = (
4158
+ column_titles[column_index]
4159
+ if column_index < len(column_titles) else ''
4160
+ )
4161
+ try:
4162
+ raw = self.__raw_value_at(column_titles, column_index, row_index)
4163
+ except Exception:
4164
+ raw = None
4165
+ return self.__color_for_cell(raw, row_index, name)
4166
+
4167
+ def __rule_specs_for_row(self, row_index, column_titles, column_widths):
4168
+ """One colour spec per *drawn* column for the rule under ``row_index``."""
4169
+ hidden = (
4170
+ () if self.__show_empty_columns else self.__empty_column_indexes
4171
+ )
4172
+ hidden = set(hidden)
4173
+ specs = []
4174
+ for col_i, _width in enumerate(column_widths):
4175
+ if col_i in hidden:
4176
+ continue
4177
+ specs.append(
4178
+ self.__rule_spec_for_cell(row_index, col_i, column_titles)
4179
+ )
4180
+ return specs
4181
+
4182
+ def __overlay_line_text(self, line, text, offset=1, color=None,
4183
+ align='left', chrome_color=None):
4184
+ """
4185
+ Replace a span of ``line`` with ``text`` (tabled LineText spirit).
4186
+
4187
+ Works on ANSI-coloured lines by stripping for geometry, then rebuilding
4188
+ ``prefix + colored_text + suffix``. Truncates text that does not fit.
4189
+ ``offset`` None means place by ``align`` inside the full line width.
4190
+ ``chrome_color`` (defaults to ``border_color``) repaints the non-text
4191
+ segments so overlays do not strip an existing border foreground.
4192
+ """
4193
+ if line is None:
4194
+ return None
4195
+ plain = strip_ansi(line)
4196
+ if not plain:
4197
+ return line
4198
+ raw = '' if text is None else str(text)
4199
+ # Drop ANSI from the overlay itself; we recolour via ``color``.
4200
+ raw = strip_ansi(raw)
4201
+ chars = list(plain)
4202
+ width = len(chars)
4203
+ text_chars = list(raw)
4204
+ tw = len(text_chars)
4205
+ if offset is None:
4206
+ if align == 'center':
4207
+ start = max(0, (width - tw) // 2)
4208
+ elif align == 'right':
4209
+ start = max(0, width - tw)
4210
+ else:
4211
+ start = 0
4212
+ else:
4213
+ start = max(0, int(offset))
4214
+ if start >= width:
4215
+ return line
4216
+ available = width - start
4217
+ if tw > available:
4218
+ text_chars = text_chars[:available]
4219
+ tw = len(text_chars)
4220
+ for i, ch in enumerate(text_chars):
4221
+ chars[start + i] = ch
4222
+ new_plain = ''.join(chars)
4223
+ chrome = chrome_color if chrome_color is not None else self.__border_color
4224
+ prefix = new_plain[:start]
4225
+ mid = new_plain[start:start + tw]
4226
+ suffix = new_plain[start + tw:]
4227
+ if color or chrome:
4228
+ left = colorize(prefix, chrome) if chrome and prefix else prefix
4229
+ centre = colorize(mid, color or chrome) if (color or chrome) and mid else mid
4230
+ right = colorize(suffix, chrome) if chrome and suffix else suffix
4231
+ return left + centre + right
4232
+ return new_plain
4233
+
4234
+ def __horizontal_border_specs(self, where):
4235
+ return [spec for spec in self.__border_texts if spec['where'] == where]
4236
+
4237
+ def __apply_horizontal_border_texts(self, separators, gap_separator):
4238
+ """Overlay registered horizontal ``border_text`` entries onto rules."""
4239
+ def paint_field(line, where):
4240
+ if line is None:
4241
+ return None
4242
+ out = line
4243
+ for spec in self.__horizontal_border_specs(where):
4244
+ out = self.__overlay_line_text(
4245
+ out, spec['text'], spec['offset'],
4246
+ spec['color'], spec['align'],
4247
+ )
4248
+ return out
4249
+
4250
+ painted = HorizontalComposition(
4251
+ paint_field(separators.superior_header_line, 'top'),
4252
+ paint_field(separators.inferior_header_line, 'header'),
4253
+ paint_field(separators.superior_header_line_no_header, 'top'),
4254
+ paint_field(separators.table_body_line, 'body'),
4255
+ paint_field(separators.table_end_line, 'bottom'),
4256
+ )
4257
+
4258
+ body_specs = self.__horizontal_border_specs('body')
4259
+ if gap_separator is None or not body_specs:
4260
+ return painted, gap_separator
4261
+
4262
+ def wrapped(after_row, _inner=gap_separator, _specs=body_specs):
4263
+ line = _inner(after_row)
4264
+ for spec in _specs:
4265
+ line = self.__overlay_line_text(
4266
+ line, spec['text'], spec['offset'],
4267
+ spec['color'], spec['align'],
4268
+ )
4269
+ return line
4270
+
4271
+ return painted, wrapped
4272
+
4273
+ def __apply_vertical_border_texts(self, table_string):
4274
+ """
4275
+ Overlay left/right ``border_text`` onto outer vertical glyphs.
4276
+
4277
+ Writes one character of the text per successive physical line,
4278
+ starting at ``offset`` (0 = first line of the rendered table).
4279
+ """
4280
+ if not table_string:
4281
+ return table_string
4282
+ left_specs = [s for s in self.__border_texts if s['where'] == 'left']
4283
+ right_specs = [s for s in self.__border_texts if s['where'] == 'right']
4284
+ if not left_specs and not right_specs:
4285
+ return table_string
4286
+
4287
+ lines = table_string.split('\n')
4288
+ n = len(lines)
4289
+
4290
+ for spec in left_specs:
4291
+ text = strip_ansi(spec['text'])
4292
+ if not text:
4293
+ continue
4294
+ offset = 0 if spec['offset'] is None else int(spec['offset'])
4295
+ for i, ch in enumerate(text):
4296
+ row = offset + i
4297
+ if row < 0 or row >= n:
4298
+ break
4299
+ lines[row] = self.__replace_first_visible(
4300
+ lines[row], ch, spec['color']
4301
+ )
4302
+
4303
+ for spec in right_specs:
4304
+ text = strip_ansi(spec['text'])
4305
+ if not text:
4306
+ continue
4307
+ offset = 0 if spec['offset'] is None else int(spec['offset'])
4308
+ for i, ch in enumerate(text):
4309
+ row = offset + i
4310
+ if row < 0 or row >= n:
4311
+ break
4312
+ lines[row] = self.__replace_last_visible(
4313
+ lines[row], ch, spec['color']
4314
+ )
4315
+
4316
+ return '\n'.join(lines)
4317
+
4318
+ @staticmethod
4319
+ def __replace_first_visible(line, ch, color):
4320
+ """Replace the first visible character of ``line`` with ``ch``."""
4321
+ plain = strip_ansi(line)
4322
+ if not plain:
4323
+ return line
4324
+ # Rebuild: find first non-ANSI char span by walking with strip.
4325
+ # Simpler path: compose new_plain then, if colouring, colourize ch.
4326
+ new_plain = ch + plain[1:]
4327
+ if color is None and line == plain:
4328
+ return new_plain
4329
+ # When the line carries ANSI, keep suffix after first visible char.
4330
+ # Locate end of first visible character in the ANSI string.
4331
+ from .text_width import has_ansi
4332
+ if not has_ansi(line):
4333
+ return colorize(ch, color) + plain[1:] if color else new_plain
4334
+ # Walk CSI sequences; first real char is the border glyph.
4335
+ import re
4336
+ sgr = re.compile(r'\x1b\[[0-9;]*m')
4337
+ pos = 0
4338
+ while pos < len(line):
4339
+ m = sgr.match(line, pos)
4340
+ if m:
4341
+ pos = m.end()
4342
+ continue
4343
+ # replace this one character
4344
+ head = line[:pos]
4345
+ # skip one unicode char
4346
+ tail_start = pos + 1
4347
+ # If original char was the start of a combining sequence, still +1
4348
+ # is fine for box-drawing / ascii borders.
4349
+ tail = line[tail_start:]
4350
+ painted = colorize(ch, color) if color else ch
4351
+ return head + painted + tail
4352
+ return line
4353
+
4354
+ @staticmethod
4355
+ def __replace_last_visible(line, ch, color):
4356
+ """Replace the last visible character of ``line`` with ``ch``."""
4357
+ plain = strip_ansi(line)
4358
+ if not plain:
4359
+ return line
4360
+ from .text_width import has_ansi
4361
+ if not has_ansi(line):
4362
+ body = plain[:-1] + ch
4363
+ if color:
4364
+ return plain[:-1] + colorize(ch, color)
4365
+ return body
4366
+ import re
4367
+ sgr = re.compile(r'\x1b\[[0-9;]*m')
4368
+ # Find index of last visible character.
4369
+ last = None
4370
+ pos = 0
4371
+ while pos < len(line):
4372
+ m = sgr.match(line, pos)
4373
+ if m:
4374
+ pos = m.end()
4375
+ continue
4376
+ last = pos
4377
+ pos += 1
4378
+ if last is None:
4379
+ return line
4380
+ painted = colorize(ch, color) if color else ch
4381
+ return line[:last] + painted + line[last + 1:]
4382
+
4383
+ def __colour_horizontal_rules(self, separators, column_widths,
4384
+ column_titles, body_row_count):
4385
+ """
4386
+ Paint cell backgrounds onto horizontal rules.
4387
+
4388
+ Body gaps use the row above. The header/body rule uses the first body
4389
+ row (fill meets the header separator from below). The end rule uses
4390
+ the last body row. Superior header keeps ``border_color`` only unless
4391
+ ``header_color`` carries a background.
4392
+ Returns the updated HorizontalComposition and a gap painter callable
4393
+ (or None when the style has no body rule).
4394
+ """
4395
+ from .merges import compute_layout, paint_rule_cell_backgrounds
4396
+
4397
+ hidden = (
4398
+ () if self.__show_empty_columns else self.__empty_column_indexes
4399
+ )
4400
+ layout = compute_layout(
4401
+ column_widths, self.__style_composition, hidden
4402
+ )
4403
+ border = self.__border_color
4404
+
4405
+ def paint(line, specs):
4406
+ if line is None:
4407
+ return None
4408
+ return paint_rule_cell_backgrounds(line, layout, specs, border)
4409
+
4410
+ first_specs = (
4411
+ self.__rule_specs_for_row(0, column_titles, column_widths)
4412
+ if body_row_count else []
4413
+ )
4414
+ last_specs = (
4415
+ self.__rule_specs_for_row(
4416
+ body_row_count - 1, column_titles, column_widths
4417
+ )
4418
+ if body_row_count else []
4419
+ )
4420
+ header_specs = []
4421
+ if self.__header_color and background_hex(self.__header_color):
4422
+ drawn = sum(
4423
+ 1 for i, _ in enumerate(column_widths)
4424
+ if i not in set(hidden)
4425
+ )
4426
+ header_specs = [self.__header_color] * drawn
4427
+
4428
+ superior = separators.superior_header_line
4429
+ if header_specs:
4430
+ superior = paint(superior, header_specs)
4431
+ elif border and superior is not None:
4432
+ superior = colorize(superior, border)
4433
+
4434
+ inferior = separators.inferior_header_line
4435
+ if first_specs:
4436
+ inferior = paint(inferior, first_specs)
4437
+ elif border and inferior is not None:
4438
+ inferior = colorize(inferior, border)
4439
+
4440
+ superior_nh = separators.superior_header_line_no_header
4441
+ if first_specs:
4442
+ superior_nh = paint(superior_nh, first_specs)
4443
+ elif border and superior_nh is not None:
4444
+ superior_nh = colorize(superior_nh, border)
4445
+
4446
+ end_line = separators.table_end_line
4447
+ if last_specs:
4448
+ end_line = paint(end_line, last_specs)
4449
+ elif border and end_line is not None:
4450
+ end_line = colorize(end_line, border)
4451
+
4452
+ plain_body = separators.table_body_line
4453
+ body_template = plain_body
4454
+ if border and body_template is not None and not first_specs:
4455
+ body_template = colorize(body_template, border)
4456
+
4457
+ painted = HorizontalComposition(
4458
+ superior,
4459
+ inferior,
4460
+ superior_nh,
4461
+ body_template if not first_specs else plain_body,
4462
+ end_line,
4463
+ )
4464
+
4465
+ gap_separator = None
4466
+ if plain_body is not None and body_row_count:
4467
+ def gap_separator(after_row, _plain=plain_body):
4468
+ specs = self.__rule_specs_for_row(
4469
+ after_row, column_titles, column_widths
4470
+ )
4471
+ return paint_rule_cell_backgrounds(
4472
+ _plain, layout, specs, border
4473
+ )
4474
+
4475
+ return painted, gap_separator
4476
+
4048
4477
  def __regions_with_colors(self):
4049
4478
  """
4050
4479
  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.12
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -355,7 +355,7 @@ flexablelib/ # GitHub repository
355
355
  ├── docs/ issue history and design notes
356
356
  ├── logos/ brand assets — see logos/README.md
357
357
  ├── ARCHITECTURE.md how it all fits together
358
- ├── style_examples.md all 44 styles rendered
358
+ ├── style_examples.md all 56 styles rendered
359
359
  ├── package.json canonical version number; drives the release
360
360
  └── setup.py reads the version from package.json
361
361
  ```
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
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
 
@@ -273,7 +275,7 @@ def test_html_export_preserves_merged_cells():
273
275
 
274
276
 
275
277
  def test_merged_region_color_fills_ansi():
276
- table = Table(style_name='flush')
278
+ table = Table(style_name='pretty_grid')
277
279
  table.use_colors = True
278
280
  table.add_column('A', ['alpha-0', 'alpha-1', 'alpha-2'])
279
281
  table.add_column('B', ['bravo-0', 'bravo-1', 'bravo-2'])
@@ -287,7 +289,7 @@ def test_merged_region_color_fills_ansi():
287
289
 
288
290
 
289
291
  def test_merged_region_inherits_column_color():
290
- table = Table(style_name='flush')
292
+ table = Table(style_name='pretty_grid')
291
293
  table.use_colors = True
292
294
  # Wide unmerged content so the merge span can hold the label.
293
295
  table.add_column('A', ['alpha-0', 'alpha-1'])
@@ -299,20 +301,99 @@ def test_merged_region_inherits_column_color():
299
301
  assert 'INHERIT' in rendered
300
302
 
301
303
 
302
- def test_flush_style_is_catalogued():
303
- assert 'flush' in Table().possible_styles
304
304
 
305
305
 
306
306
  def test_html_and_excel_carry_merge_fill(tmp_path):
307
- table = Table(style_name='flush')
307
+ table = Table(style_name='pretty_grid')
308
308
  table.use_colors = True
309
309
  table.add_column('A', ['a0', 'a1'])
310
310
  table.add_column('B', ['b0', 'b1'])
311
311
  table.merge_cells(0, 0, last_column=1, value='BOX', color='black on cyan')
312
312
  html = table.to_html(title='m')
313
313
  assert 'background-color' in html
314
+ openpyxl = pytest.importorskip('openpyxl')
314
315
  path = tmp_path / 'm.xlsx'
315
316
  table.to_excel(path)
316
- from openpyxl import load_workbook
317
- ws = load_workbook(path).active
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
+
320
+ def test_horizontal_rules_carry_cell_bg():
321
+ """H-rule dash runs inherit the cell-above background (no dark band)."""
322
+ import re
323
+ table = Table(style_name='pretty_grid')
324
+ table.use_colors = True
325
+ table.add_column('A', ['a0', 'a1'])
326
+ table.add_column('B', ['b0', 'b1'])
327
+ table.column_colors = {'A': 'black on cyan', 'B': 'black on yellow'}
328
+ rendered = str(table)
329
+ found_cyan_on_rule = False
330
+ found_yellow_on_rule = False
331
+ for line in rendered.splitlines():
332
+ plain = re.sub('\x1b' r'\[[0-9;]*m', '', line)
333
+ if '─' not in plain and '═' not in plain:
334
+ continue
335
+ if '46m' in line:
336
+ found_cyan_on_rule = True
337
+ if '43m' in line:
338
+ found_yellow_on_rule = True
339
+ assert found_cyan_on_rule and found_yellow_on_rule
340
+
341
+
342
+ def test_border_color_foreground_on_modern_and_ascii():
343
+ import os
344
+ os.environ['FORCE_COLOR'] = '1'
345
+ os.environ.pop('NO_COLOR', None)
346
+ for style in ('modern', 'ascii'):
347
+ table = Table(style_name=style)
348
+ table.use_colors = True
349
+ table.border_color = 'cyan'
350
+ table.add_column('A', ['x'])
351
+ table.add_column('B', ['y'])
352
+ rendered = str(table)
353
+ assert '\x1b[' in rendered or '\033[' in rendered
354
+ assert '36m' in rendered # cyan FG
355
+
356
+
357
+ def test_border_text_on_top_rule_with_color():
358
+ import os
359
+ os.environ['FORCE_COLOR'] = '1'
360
+ os.environ.pop('NO_COLOR', None)
361
+ table = Table(style_name='ascii')
362
+ table.use_colors = True
363
+ table.border_color = 'blue'
364
+ table.add_column('name', ['C', 'Go'])
365
+ table.add_column('year', [1972, 2009])
366
+ table.border_text('Languages', where='top', color='bold yellow', offset=2)
367
+ rendered = str(table)
368
+ plain_lines = []
369
+ import re
370
+ for line in rendered.splitlines():
371
+ plain_lines.append(re.sub('\x1b' r'\[[0-9;]*m', '', line))
372
+ assert any('Languages' in line for line in plain_lines)
373
+ assert 'Languages' in plain_lines[0]
374
+ assert '33m' in rendered or '1;33m' in rendered
375
+ assert '34m' in rendered # blue chrome
376
+
377
+
378
+ def test_border_text_left_vertical():
379
+ table = Table(style_name='ascii')
380
+ table.add_column('A', ['1', '2'])
381
+ table.border_text('AB', where='left', offset=1)
382
+ import re
383
+ plain = [re.sub('\x1b' r'\[[0-9;]*m', '', line) for line in str(table).splitlines()]
384
+ # First data-ish lines after offset should start with A then B
385
+ assert plain[1].startswith('A')
386
+ assert plain[2].startswith('B')
387
+
388
+
389
+ def test_blocks_style_still_works_with_colors():
390
+ import os
391
+ os.environ['FORCE_COLOR'] = '1'
392
+ os.environ.pop('NO_COLOR', None)
393
+ table = Table(style_name='blocks')
394
+ table.use_colors = True
395
+ table.header_color = 'bold white on blue'
396
+ table.column_colors = {'A': 'black on green'}
397
+ table.add_column('A', ['x', 'y'])
398
+ rendered = str(table)
399
+ assert '42m' in rendered or '44m' in rendered
@@ -36,7 +36,7 @@ def build_table(style_name):
36
36
  def test_the_catalogue_holds_43_styles():
37
37
  # A canary: adding a style is meant to be purely additive, and the README,
38
38
  # ARCHITECTURE.md and style_examples.md all quote this number.
39
- assert len(ALL_STYLES) == 44
39
+ assert len(ALL_STYLES) == 56
40
40
 
41
41
 
42
42
  def test_style_names_are_unique():
@@ -212,3 +212,25 @@ def test_blocks_style_keeps_cell_padding_for_background_fills():
212
212
  rendered = str(table)
213
213
  assert '\x1b[' in rendered or '\033[' in rendered or '[' in rendered
214
214
  assert '42m' in rendered or '44m' in rendered # green or blue bg
215
+
216
+
217
+ TABLED_STYLES = [
218
+ 'ascii', 'modern', 'sharp', 'rounded', 'modern_rounded', 'extended',
219
+ 'psql', 'markdown', 're_structured_text', 'dots', 'ascii_rounded',
220
+ 'blank', 'empty',
221
+ ]
222
+
223
+
224
+ @pytest.mark.parametrize('style_name', TABLED_STYLES)
225
+ def test_tabled_style_names_are_catalogued(style_name):
226
+ assert style_name in ALL_STYLES
227
+
228
+
229
+ @pytest.mark.parametrize('style_name', TABLED_STYLES)
230
+ def test_tabled_styles_render_without_error(style_name):
231
+ rendered = str(build_table(style_name))
232
+ assert rendered
233
+
234
+
235
+ def test_flush_style_removed():
236
+ assert 'flush' not in ALL_STYLES
File without changes
File without changes
File without changes
File without changes