flexablelib 3.0.2__tar.gz → 3.1.0__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.2 → flexablelib-3.1.0}/CHANGELOG.md +54 -0
- {flexablelib-3.0.2/flexablelib.egg-info → flexablelib-3.1.0}/PKG-INFO +89 -1
- {flexablelib-3.0.2 → flexablelib-3.1.0}/README.md +88 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/__init__.py +3 -1
- flexablelib-3.1.0/flexablelib/box_topology.py +308 -0
- flexablelib-3.1.0/flexablelib/layout.py +1177 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/merges.py +167 -17
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/table.py +540 -56
- {flexablelib-3.0.2 → flexablelib-3.1.0/flexablelib.egg-info}/PKG-INFO +89 -1
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib.egg-info/SOURCES.txt +4 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/package.json +1 -1
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/conftest.py +13 -10
- flexablelib-3.1.0/tests/test_box_topology.py +109 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_merge_edge_matrix.py +3 -2
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_merge_fill.py +26 -4
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_merges.py +43 -39
- flexablelib-3.1.0/tests/test_v310_layout.py +573 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/LICENSE +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/MANIFEST.in +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/_speedups.c +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/_width_tables.h +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/cells.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/colors.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/columns.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/fast.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/options.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/py.typed +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/readers.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/style_compositions.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/table_strings.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/text_width.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/utils.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib/writers.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/pytest.ini +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/setup.cfg +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/setup.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/style_examples.md +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/helpers.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_align_indicators.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_cells.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_columns.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_excel.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_issues.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_public_api_edges.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_readme_examples.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_stress_matrix.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_style_line_widths.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_styles.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_text_width.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_upstream_issues.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v211_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v213_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v214_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v215_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v216_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v217_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v218_features.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v219_coverage.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v219_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v220_exports.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v221_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v222_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v223_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v224_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v230_none.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v231_fixes.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v232_merge_ansi.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tests/test_v300_style_names.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/benchmark.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/generate_width_tables.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/readme_gallery.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/stress_matrix.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/style_examples.py +0 -0
- {flexablelib-3.0.2 → flexablelib-3.1.0}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,60 @@
|
|
|
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.1.0] - 2026-11-11
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- `Card`: one record in a frame, in any of the 54 styles and the 15
|
|
9
|
+
themes. The title goes into the top border (`╭─ Title ───╮`) when the
|
|
10
|
+
style draws one; subtitle, `label value` fields (or a grid of tiles with
|
|
11
|
+
`field_columns=2`/`'auto'`), any renderable as `body`, footer and
|
|
12
|
+
`[ action ]` chips. Colours fill the card frame to frame; panel and
|
|
13
|
+
shadow work as on tables.
|
|
14
|
+
- `Grid` and `GridCell`: lay cards, tables, text and other grids out in
|
|
15
|
+
columns that reflow with the width (`columns='auto'` or n, `min_width`,
|
|
16
|
+
spans, nesting, equal-height rows) -- a grid of cards or a whole terminal
|
|
17
|
+
screen.
|
|
18
|
+
- `Table.render(width)` / `responsive=True`: the table when it fits, then
|
|
19
|
+
squeezed, then without low-priority columns (`column_priority`), then as
|
|
20
|
+
cards (`to_cards()`) in a responsive grid. `breakpoints`,
|
|
21
|
+
`card_options`, `render_mode()` and `natural_width()`.
|
|
22
|
+
- `Table.subtitle`, `title_position='border'`, `caption_position='border'`,
|
|
23
|
+
`title_align`, `title_color`. A border title never covers a corner or a
|
|
24
|
+
column junction; it falls back to a line above.
|
|
25
|
+
- `flexablelib.layout.wrap_panel` / `add_shadow`, shared by tables and
|
|
26
|
+
cards.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
- Columns in `hide_columns` no longer count toward the width the fit pass
|
|
30
|
+
has to save, so a table that fits once they are hidden is no longer
|
|
31
|
+
squeezed as if they were still drawn.
|
|
32
|
+
|
|
33
|
+
## [3.0.3] - 2026-11-11
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
- A leftover `ESC[0m` kept by `strip_by_width` no longer lands in the
|
|
37
|
+
padded text of a coloured merge and closes the fill mid-cell. The
|
|
38
|
+
background now covers the whole interior rectangle, including internal
|
|
39
|
+
separators and padding (theme `dark` and other themes).
|
|
40
|
+
- Column-only styles again draw a top and bottom rule around a
|
|
41
|
+
multi-column merge, clamped to the merge width, with `├`/`┤` tees that
|
|
42
|
+
do not bleed into neighbouring cells. A vertical-only merge still
|
|
43
|
+
gets no cap.
|
|
44
|
+
- Junctions on a fully absorbed separator (side-by-side merges, or a
|
|
45
|
+
rule that is almost entirely merge interiors) are repaired even when
|
|
46
|
+
the line no longer looks like a rule, so leftover `┼`/`╟`/`╢` become
|
|
47
|
+
`│`/`║`.
|
|
48
|
+
- Dotted-row `:` junctions become `.` when a vertical arm is missing;
|
|
49
|
+
markdown header separators stay `|---|---|` so the format remains
|
|
50
|
+
valid; ascii-rounded outer frames are not rewritten.
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
- A glyph-topology verifier (`flexablelib.box_topology`) and tests over
|
|
54
|
+
every style, with and without colour, covering horizontal, vertical
|
|
55
|
+
and 2D merges at corners, edges, and next to the header or footer.
|
|
56
|
+
Colour must not change the glyphs, and every interior column of a
|
|
57
|
+
coloured merge must carry that merge's background.
|
|
58
|
+
|
|
5
59
|
## [3.0.2] - 2026-11-11
|
|
6
60
|
|
|
7
61
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
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
|
|
@@ -504,6 +504,94 @@ table.merge_cells(0, 0, 2, 2, value='Total', align='r')
|
|
|
504
504
|
A merge never widens the table -- columns are still sized by their unmerged
|
|
505
505
|
content -- so text longer than its span is truncated.
|
|
506
506
|
|
|
507
|
+
## Cards, grids and responsive tables
|
|
508
|
+
|
|
509
|
+
`Card` draws one record in a frame, in any of the table styles. The title goes
|
|
510
|
+
into the top border when the style draws one:
|
|
511
|
+
|
|
512
|
+
```python
|
|
513
|
+
from flexablelib import Card
|
|
514
|
+
|
|
515
|
+
card = Card(title='Ana', subtitle='Norte',
|
|
516
|
+
fields={'Edad': 28, 'Ciudad': 'Guadalajara'},
|
|
517
|
+
footer='actualizado hoy')
|
|
518
|
+
print(card.render(width=30))
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
```
|
|
522
|
+
╭─ Ana ──────────────────────╮
|
|
523
|
+
│ Norte │
|
|
524
|
+
├────────────────────────────┤
|
|
525
|
+
│ Edad 28 │
|
|
526
|
+
│ Ciudad Guadalajara │
|
|
527
|
+
├────────────────────────────┤
|
|
528
|
+
│ actualizado hoy │
|
|
529
|
+
╰────────────────────────────╯
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
`field_columns=2` (or `'auto'`) lays the fields out as a grid of tiles, and
|
|
533
|
+
`actions` adds `[ Action ]` chips:
|
|
534
|
+
|
|
535
|
+
```
|
|
536
|
+
╭─ Pedido 42 ────────────────────╮
|
|
537
|
+
│ Cliente Total │
|
|
538
|
+
│ José $1,200 │
|
|
539
|
+
│ Estado Fecha │
|
|
540
|
+
│ Enviado 11/11 │
|
|
541
|
+
├────────────────────────────────┤
|
|
542
|
+
│ [ Ver ] [ Editar ] │
|
|
543
|
+
╰────────────────────────────────╯
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
Cards take `style_name`, `theme` (the table themes), `border_color`,
|
|
547
|
+
`title_color`, `label_color`, `value_colors`, `color` (a background for the
|
|
548
|
+
whole card), `zebra`, `panel` and `shadow`.
|
|
549
|
+
|
|
550
|
+
`table.render(width)` makes a table responsive: the normal table when it fits,
|
|
551
|
+
without its low-priority columns next, squeezed and wrapped after that, and
|
|
552
|
+
one card per row when nothing else fits. `width` defaults to
|
|
553
|
+
`max_width`, then the terminal width; `responsive=True` makes `print(table)` do
|
|
554
|
+
the same.
|
|
555
|
+
|
|
556
|
+
```python
|
|
557
|
+
table.title, table.title_position = 'Personas', 'border'
|
|
558
|
+
table.column_priority = {'Correo': 3} # hidden first
|
|
559
|
+
table.card_options = {'subtitle_field': 'Grupo', 'fields': ['Edad', 'Ciudad']}
|
|
560
|
+
table.render(width=80) # table
|
|
561
|
+
table.render(width=46) # table without "Correo"
|
|
562
|
+
table.render(width=30) # cards
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
```
|
|
566
|
+
╭─────────┬────────┬──────┬─ Personas ──┬──────────────────╮
|
|
567
|
+
│ Nombre │ Grupo │ Edad │ Ciudad │ Correo │
|
|
568
|
+
├─────────┼────────┼──────┼─────────────┼──────────────────┤
|
|
569
|
+
│ Ana │ Norte │ 28 │ Guadalajara │ ana@example.com │
|
|
570
|
+
│ Luna 🌸 │ Centro │ 22 │ Mérida │ luna@example.com │
|
|
571
|
+
╰─────────┴────────┴──────┴─────────────┴──────────────────╯
|
|
572
|
+
|
|
573
|
+
Personas
|
|
574
|
+
╭─ Ana ──────────────────────╮
|
|
575
|
+
│ Norte │
|
|
576
|
+
├────────────────────────────┤
|
|
577
|
+
│ Edad 28 │
|
|
578
|
+
│ Ciudad Guadalajara │
|
|
579
|
+
╰────────────────────────────╯
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
`Grid` places cards, tables, text and other grids in columns that reflow with
|
|
583
|
+
the width -- a grid of cards or a whole terminal screen:
|
|
584
|
+
|
|
585
|
+
```python
|
|
586
|
+
from flexablelib import Grid, GridCell
|
|
587
|
+
|
|
588
|
+
Grid(table.to_cards(), min_width=28).render(width=100) # 3 columns, 2 at 62, 1 at 40
|
|
589
|
+
Grid([GridCell('Ventas de noviembre', span=3),
|
|
590
|
+
GridCell(table, span=2), Grid(cards, columns=1)], columns=3)
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
More in [docs/LAYOUT.md](https://github.com/Opus-Perpetuus/flexablelib/blob/main/docs/LAYOUT.md).
|
|
594
|
+
|
|
507
595
|
## Notes
|
|
508
596
|
|
|
509
597
|
- A column named ``"i"`` does not collide with the index column (`utils.IndexColumnTitle`).
|
|
@@ -439,6 +439,94 @@ table.merge_cells(0, 0, 2, 2, value='Total', align='r')
|
|
|
439
439
|
A merge never widens the table -- columns are still sized by their unmerged
|
|
440
440
|
content -- so text longer than its span is truncated.
|
|
441
441
|
|
|
442
|
+
## Cards, grids and responsive tables
|
|
443
|
+
|
|
444
|
+
`Card` draws one record in a frame, in any of the table styles. The title goes
|
|
445
|
+
into the top border when the style draws one:
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
from flexablelib import Card
|
|
449
|
+
|
|
450
|
+
card = Card(title='Ana', subtitle='Norte',
|
|
451
|
+
fields={'Edad': 28, 'Ciudad': 'Guadalajara'},
|
|
452
|
+
footer='actualizado hoy')
|
|
453
|
+
print(card.render(width=30))
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
╭─ Ana ──────────────────────╮
|
|
458
|
+
│ Norte │
|
|
459
|
+
├────────────────────────────┤
|
|
460
|
+
│ Edad 28 │
|
|
461
|
+
│ Ciudad Guadalajara │
|
|
462
|
+
├────────────────────────────┤
|
|
463
|
+
│ actualizado hoy │
|
|
464
|
+
╰────────────────────────────╯
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
`field_columns=2` (or `'auto'`) lays the fields out as a grid of tiles, and
|
|
468
|
+
`actions` adds `[ Action ]` chips:
|
|
469
|
+
|
|
470
|
+
```
|
|
471
|
+
╭─ Pedido 42 ────────────────────╮
|
|
472
|
+
│ Cliente Total │
|
|
473
|
+
│ José $1,200 │
|
|
474
|
+
│ Estado Fecha │
|
|
475
|
+
│ Enviado 11/11 │
|
|
476
|
+
├────────────────────────────────┤
|
|
477
|
+
│ [ Ver ] [ Editar ] │
|
|
478
|
+
╰────────────────────────────────╯
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
Cards take `style_name`, `theme` (the table themes), `border_color`,
|
|
482
|
+
`title_color`, `label_color`, `value_colors`, `color` (a background for the
|
|
483
|
+
whole card), `zebra`, `panel` and `shadow`.
|
|
484
|
+
|
|
485
|
+
`table.render(width)` makes a table responsive: the normal table when it fits,
|
|
486
|
+
without its low-priority columns next, squeezed and wrapped after that, and
|
|
487
|
+
one card per row when nothing else fits. `width` defaults to
|
|
488
|
+
`max_width`, then the terminal width; `responsive=True` makes `print(table)` do
|
|
489
|
+
the same.
|
|
490
|
+
|
|
491
|
+
```python
|
|
492
|
+
table.title, table.title_position = 'Personas', 'border'
|
|
493
|
+
table.column_priority = {'Correo': 3} # hidden first
|
|
494
|
+
table.card_options = {'subtitle_field': 'Grupo', 'fields': ['Edad', 'Ciudad']}
|
|
495
|
+
table.render(width=80) # table
|
|
496
|
+
table.render(width=46) # table without "Correo"
|
|
497
|
+
table.render(width=30) # cards
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
```
|
|
501
|
+
╭─────────┬────────┬──────┬─ Personas ──┬──────────────────╮
|
|
502
|
+
│ Nombre │ Grupo │ Edad │ Ciudad │ Correo │
|
|
503
|
+
├─────────┼────────┼──────┼─────────────┼──────────────────┤
|
|
504
|
+
│ Ana │ Norte │ 28 │ Guadalajara │ ana@example.com │
|
|
505
|
+
│ Luna 🌸 │ Centro │ 22 │ Mérida │ luna@example.com │
|
|
506
|
+
╰─────────┴────────┴──────┴─────────────┴──────────────────╯
|
|
507
|
+
|
|
508
|
+
Personas
|
|
509
|
+
╭─ Ana ──────────────────────╮
|
|
510
|
+
│ Norte │
|
|
511
|
+
├────────────────────────────┤
|
|
512
|
+
│ Edad 28 │
|
|
513
|
+
│ Ciudad Guadalajara │
|
|
514
|
+
╰────────────────────────────╯
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
`Grid` places cards, tables, text and other grids in columns that reflow with
|
|
518
|
+
the width -- a grid of cards or a whole terminal screen:
|
|
519
|
+
|
|
520
|
+
```python
|
|
521
|
+
from flexablelib import Grid, GridCell
|
|
522
|
+
|
|
523
|
+
Grid(table.to_cards(), min_width=28).render(width=100) # 3 columns, 2 at 62, 1 at 40
|
|
524
|
+
Grid([GridCell('Ventas de noviembre', span=3),
|
|
525
|
+
GridCell(table, span=2), Grid(cards, columns=1)], columns=3)
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
More in [docs/LAYOUT.md](https://github.com/Opus-Perpetuus/flexablelib/blob/main/docs/LAYOUT.md).
|
|
529
|
+
|
|
442
530
|
## Notes
|
|
443
531
|
|
|
444
532
|
- A column named ``"i"`` does not collide with the index column (`utils.IndexColumnTitle`).
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from .table import Table
|
|
2
2
|
from .style_compositions import TableComposition, SeparatorLine
|
|
3
|
+
from .layout import Card, Grid, GridCell
|
|
3
4
|
|
|
4
5
|
# Names, not the objects themselves: `from flexablelib import *` walks this
|
|
5
6
|
# list and raises TypeError on anything that is not a string.
|
|
6
|
-
__all__ = ['Table', 'TableComposition', 'SeparatorLine'
|
|
7
|
+
__all__ = ['Table', 'TableComposition', 'SeparatorLine', 'Card', 'Grid',
|
|
8
|
+
'GridCell']
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Box-drawing topology: every arm of a grid glyph must meet a matching arm.
|
|
3
|
+
|
|
4
|
+
Used to verify merged tables: a │ must not point into a space, a ┼ must
|
|
5
|
+
have lines on all four sides, and a merge cap must not send a horizontal
|
|
6
|
+
arm into a neighbour column that has no rule.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
from typing import Iterable, List, Optional, Sequence, Tuple
|
|
13
|
+
|
|
14
|
+
from .fast import char_width, strip_ansi, visible_width
|
|
15
|
+
from .text_width import tokenize
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# (north, south, east, west) — 1 if the glyph carries an arm that way.
|
|
19
|
+
_ARMS = {}
|
|
20
|
+
# Glyphs that can stand in for any tee (ASCII has only '+').
|
|
21
|
+
_SOFT = set('+')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _reg(ch: str, n, s, e, w):
|
|
25
|
+
_ARMS[ch] = (bool(n), bool(s), bool(e), bool(w))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Light
|
|
29
|
+
for ch, key in {
|
|
30
|
+
'─': (0, 0, 1, 1), '│': (1, 1, 0, 0),
|
|
31
|
+
'┌': (0, 1, 1, 0), '┐': (0, 1, 0, 1), '└': (1, 0, 1, 0), '┘': (1, 0, 0, 1),
|
|
32
|
+
'├': (1, 1, 1, 0), '┤': (1, 1, 0, 1), '┬': (0, 1, 1, 1), '┴': (1, 0, 1, 1),
|
|
33
|
+
'┼': (1, 1, 1, 1),
|
|
34
|
+
'╭': (0, 1, 1, 0), '╮': (0, 1, 0, 1), '╰': (1, 0, 1, 0), '╯': (1, 0, 0, 1),
|
|
35
|
+
}.items():
|
|
36
|
+
_reg(ch, *key)
|
|
37
|
+
|
|
38
|
+
# Heavy
|
|
39
|
+
for ch, key in {
|
|
40
|
+
'━': (0, 0, 1, 1), '┃': (1, 1, 0, 0),
|
|
41
|
+
'┏': (0, 1, 1, 0), '┓': (0, 1, 0, 1), '┗': (1, 0, 1, 0), '┛': (1, 0, 0, 1),
|
|
42
|
+
'┣': (1, 1, 1, 0), '┫': (1, 1, 0, 1), '┳': (0, 1, 1, 1), '┻': (1, 0, 1, 1),
|
|
43
|
+
'╋': (1, 1, 1, 1),
|
|
44
|
+
'┝': (1, 1, 1, 0), '┥': (1, 1, 0, 1), '┯': (0, 1, 1, 1), '┷': (1, 0, 1, 1),
|
|
45
|
+
'┿': (1, 1, 1, 1),
|
|
46
|
+
'┠': (1, 1, 1, 0), '┨': (1, 1, 0, 1), '┯': (0, 1, 1, 1),
|
|
47
|
+
'┍': (0, 1, 1, 0), '┑': (0, 1, 0, 1), '┕': (1, 0, 1, 0), '┙': (1, 0, 0, 1),
|
|
48
|
+
}.items():
|
|
49
|
+
_reg(ch, *key)
|
|
50
|
+
|
|
51
|
+
# Double and mixed
|
|
52
|
+
for ch, key in {
|
|
53
|
+
'═': (0, 0, 1, 1), '║': (1, 1, 0, 0),
|
|
54
|
+
'╔': (0, 1, 1, 0), '╗': (0, 1, 0, 1), '╚': (1, 0, 1, 0), '╝': (1, 0, 0, 1),
|
|
55
|
+
'╠': (1, 1, 1, 0), '╣': (1, 1, 0, 1), '╦': (0, 1, 1, 1), '╩': (1, 0, 1, 1),
|
|
56
|
+
'╬': (1, 1, 1, 1),
|
|
57
|
+
'╒': (0, 1, 1, 0), '╓': (0, 1, 1, 0), '╕': (0, 1, 0, 1), '╖': (0, 1, 0, 1),
|
|
58
|
+
'╘': (1, 0, 1, 0), '╙': (1, 0, 1, 0), '╛': (1, 0, 0, 1), '╜': (1, 0, 0, 1),
|
|
59
|
+
'╞': (1, 1, 1, 0), '╟': (1, 1, 1, 0), '╡': (1, 1, 0, 1), '╢': (1, 1, 0, 1),
|
|
60
|
+
'╤': (0, 1, 1, 1), '╥': (0, 1, 1, 1), '╧': (1, 0, 1, 1), '╨': (1, 0, 1, 1),
|
|
61
|
+
'╪': (1, 1, 1, 1), '╫': (1, 1, 1, 1),
|
|
62
|
+
}.items():
|
|
63
|
+
_reg(ch, *key)
|
|
64
|
+
|
|
65
|
+
# Dashed / dotted / light variants used by shipped styles
|
|
66
|
+
for ch in '┄┅┈┉╌╍▬−':
|
|
67
|
+
_reg(ch, 0, 0, 1, 1)
|
|
68
|
+
for ch in '┊┋┆┇╎╏':
|
|
69
|
+
_reg(ch, 1, 1, 0, 0)
|
|
70
|
+
|
|
71
|
+
# ASCII
|
|
72
|
+
_reg('-', 0, 0, 1, 1)
|
|
73
|
+
_reg('=', 0, 0, 1, 1)
|
|
74
|
+
_reg('~', 0, 0, 1, 1)
|
|
75
|
+
_reg('|', 1, 1, 0, 0)
|
|
76
|
+
_reg('+', 1, 1, 1, 1)
|
|
77
|
+
|
|
78
|
+
# Extra light/heavy mixed tees often produced by repairs
|
|
79
|
+
for ch, key in {
|
|
80
|
+
'┞': (1, 1, 1, 0), '┟': (1, 1, 1, 0), '┡': (1, 1, 1, 0), '┢': (1, 1, 1, 0),
|
|
81
|
+
'┩': (1, 1, 0, 1), '┪': (1, 1, 0, 1), '┦': (1, 1, 0, 1), '┧': (1, 1, 0, 1),
|
|
82
|
+
'┱': (0, 1, 1, 1), '┲': (0, 1, 1, 1), '.items': (1, 0, 1, 1), '┺': (1, 0, 1, 1),
|
|
83
|
+
'╀': (1, 1, 1, 1), '╁': (1, 1, 1, 1), '╂': (1, 1, 1, 1),
|
|
84
|
+
'╃': (1, 1, 1, 1), '╄': (1, 1, 1, 1), '╅': (1, 1, 1, 1), '╆': (1, 1, 1, 1),
|
|
85
|
+
'╇': (1, 1, 1, 1), '╈': (1, 1, 1, 1), '╉': (1, 1, 1, 1), '╊': (1, 1, 1, 1),
|
|
86
|
+
}.items():
|
|
87
|
+
if ch != '.items':
|
|
88
|
+
_reg(ch, *key)
|
|
89
|
+
|
|
90
|
+
# I typo'd one key - fix ┹
|
|
91
|
+
_reg('┹', 1, 0, 1, 1)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
Break = Tuple[int, int, str, str, str] # row, col, glyph, direction, neighbor
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def arms(ch: str):
|
|
98
|
+
"""Return (n, s, e, w) or None if ``ch`` is not a grid glyph."""
|
|
99
|
+
if not ch:
|
|
100
|
+
return None
|
|
101
|
+
return _ARMS.get(ch)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def grid(line: str) -> List[str]:
|
|
105
|
+
"""Visible-column list; a width-2 character occupies two cells (second '')."""
|
|
106
|
+
out: List[str] = []
|
|
107
|
+
for ch in strip_ansi(line):
|
|
108
|
+
w = char_width(ch)
|
|
109
|
+
if w <= 0:
|
|
110
|
+
continue
|
|
111
|
+
out.append(ch)
|
|
112
|
+
if w == 2:
|
|
113
|
+
out.append('')
|
|
114
|
+
return out
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
_SGR = re.compile(r'\x1b\[([0-9;]*)m')
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _apply_sgr(params, fg, bg):
|
|
121
|
+
if not params:
|
|
122
|
+
return None, None
|
|
123
|
+
i = 0
|
|
124
|
+
n = len(params)
|
|
125
|
+
while i < n:
|
|
126
|
+
p = params[i]
|
|
127
|
+
if p == 0:
|
|
128
|
+
fg, bg = None, None
|
|
129
|
+
elif p == 39:
|
|
130
|
+
fg = None
|
|
131
|
+
elif p == 49:
|
|
132
|
+
bg = None
|
|
133
|
+
elif p in (38, 48):
|
|
134
|
+
kind = 'fg' if p == 38 else 'bg'
|
|
135
|
+
if i + 1 < n and params[i + 1] == 2 and i + 4 < n:
|
|
136
|
+
val = ('2', params[i + 2], params[i + 3], params[i + 4])
|
|
137
|
+
i += 4
|
|
138
|
+
elif i + 1 < n and params[i + 1] == 5 and i + 2 < n:
|
|
139
|
+
val = ('5', params[i + 2])
|
|
140
|
+
i += 2
|
|
141
|
+
else:
|
|
142
|
+
val = ('raw', p)
|
|
143
|
+
if kind == 'fg':
|
|
144
|
+
fg = val
|
|
145
|
+
else:
|
|
146
|
+
bg = val
|
|
147
|
+
elif 40 <= p <= 47 or 100 <= p <= 107:
|
|
148
|
+
bg = p
|
|
149
|
+
elif 30 <= p <= 37 or 90 <= p <= 97:
|
|
150
|
+
fg = p
|
|
151
|
+
i += 1
|
|
152
|
+
return fg, bg
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def visible_cells(line: str):
|
|
156
|
+
"""List of (column, character, bg) for each visible column."""
|
|
157
|
+
out = []
|
|
158
|
+
i = 0
|
|
159
|
+
col = 0
|
|
160
|
+
fg = bg = None
|
|
161
|
+
while i < len(line):
|
|
162
|
+
match = _SGR.match(line, i)
|
|
163
|
+
if match:
|
|
164
|
+
raw = match.group(1)
|
|
165
|
+
params = [int(part) if part else 0 for part in raw.split(';')] if raw else [0]
|
|
166
|
+
fg, bg = _apply_sgr(params, fg, bg)
|
|
167
|
+
i = match.end()
|
|
168
|
+
continue
|
|
169
|
+
ch = line[i]
|
|
170
|
+
width = char_width(ch)
|
|
171
|
+
if width <= 0:
|
|
172
|
+
i += 1
|
|
173
|
+
continue
|
|
174
|
+
out.append((col, ch, bg))
|
|
175
|
+
for _ in range(width - 1):
|
|
176
|
+
out.append((col + 1, '', bg))
|
|
177
|
+
col += 1
|
|
178
|
+
col += width
|
|
179
|
+
i += 1
|
|
180
|
+
return out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def bg_runs(line: str, wanted):
|
|
184
|
+
"""Contiguous [start, end) column ranges whose background is ``wanted``."""
|
|
185
|
+
runs = []
|
|
186
|
+
start = None
|
|
187
|
+
for col, _ch, bg in visible_cells(line):
|
|
188
|
+
hit = (
|
|
189
|
+
bg == ('2',) + wanted
|
|
190
|
+
if isinstance(wanted, tuple) and len(wanted) == 3
|
|
191
|
+
else bg == wanted
|
|
192
|
+
)
|
|
193
|
+
if hit:
|
|
194
|
+
if start is None:
|
|
195
|
+
start = col
|
|
196
|
+
elif start is not None:
|
|
197
|
+
runs.append((start, col))
|
|
198
|
+
start = None
|
|
199
|
+
if start is not None:
|
|
200
|
+
runs.append((start, visible_width(line)))
|
|
201
|
+
return runs
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def check_topology(lines: Sequence[str]) -> List[Break]:
|
|
205
|
+
"""
|
|
206
|
+
Return arm mismatches in ``lines``.
|
|
207
|
+
|
|
208
|
+
A glyph with an arm toward a neighbour must meet a glyph with the
|
|
209
|
+
opposite arm. A glyph with no arm that way must not meet an opposite
|
|
210
|
+
arm. Space, text and the edge of the table have no arms.
|
|
211
|
+
"""
|
|
212
|
+
rows = [grid(line) for line in lines]
|
|
213
|
+
breaks: List[Break] = []
|
|
214
|
+
# (direction, d_row, d_col, my_arm_index, neighbour_arm_index)
|
|
215
|
+
dirs = (
|
|
216
|
+
('up', -1, 0, 0, 1),
|
|
217
|
+
('down', 1, 0, 1, 0),
|
|
218
|
+
('right', 0, 1, 2, 3),
|
|
219
|
+
('left', 0, -1, 3, 2),
|
|
220
|
+
)
|
|
221
|
+
for r, row in enumerate(rows):
|
|
222
|
+
for c, ch in enumerate(row):
|
|
223
|
+
a = arms(ch)
|
|
224
|
+
if not a:
|
|
225
|
+
continue
|
|
226
|
+
for name, dr, dc, mine, theirs in dirs:
|
|
227
|
+
has = a[mine]
|
|
228
|
+
rr, cc = r + dr, c + dc
|
|
229
|
+
if 0 <= rr < len(rows) and 0 <= cc < len(rows[rr]):
|
|
230
|
+
nch = rows[rr][cc]
|
|
231
|
+
na = arms(nch)
|
|
232
|
+
n_has = bool(na and na[theirs])
|
|
233
|
+
neighbor = nch or ' '
|
|
234
|
+
else:
|
|
235
|
+
# Off the canvas (including a shorter neighbouring line):
|
|
236
|
+
# a dangling arm at the edge of the table is allowed.
|
|
237
|
+
continue
|
|
238
|
+
# ASCII '+' stands in for every tee, so unused arms do not
|
|
239
|
+
# have to meet a neighbour. Incoming arms still match.
|
|
240
|
+
if ch in _SOFT and has and not n_has:
|
|
241
|
+
continue
|
|
242
|
+
if has and not n_has:
|
|
243
|
+
breaks.append((r, c, ch, name, neighbor or ''))
|
|
244
|
+
elif n_has and not has:
|
|
245
|
+
breaks.append((r, c, ch, 'no-' + name, neighbor or ''))
|
|
246
|
+
return breaks
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def check_merge_fill(lines: Sequence[str], wanted, label: str = '') -> List[str]:
|
|
250
|
+
"""
|
|
251
|
+
The background ``wanted`` (24-bit r,g,b or an SGR code) must form a
|
|
252
|
+
single rectangle: every line that carries it has one run, all runs
|
|
253
|
+
share the same [start, end), and the rows are contiguous.
|
|
254
|
+
"""
|
|
255
|
+
problems = []
|
|
256
|
+
hits = []
|
|
257
|
+
for index, line in enumerate(lines):
|
|
258
|
+
runs = bg_runs(line, wanted)
|
|
259
|
+
if not runs:
|
|
260
|
+
continue
|
|
261
|
+
if len(runs) != 1:
|
|
262
|
+
problems.append(
|
|
263
|
+
f'{label}: line {index} has non-contiguous fill {runs}'
|
|
264
|
+
)
|
|
265
|
+
continue
|
|
266
|
+
hits.append((index, runs[0][0], runs[0][1]))
|
|
267
|
+
if not hits:
|
|
268
|
+
problems.append(f'{label}: background {wanted} never appeared')
|
|
269
|
+
return problems
|
|
270
|
+
indexes = [i for i, _, _ in hits]
|
|
271
|
+
if indexes != list(range(indexes[0], indexes[-1] + 1)):
|
|
272
|
+
problems.append(f'{label}: fill rows are not a solid block {indexes}')
|
|
273
|
+
spans = {(s, e) for _, s, e in hits}
|
|
274
|
+
if len(spans) != 1:
|
|
275
|
+
problems.append(f'{label}: fill width is not rectangular {spans}')
|
|
276
|
+
return problems
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def signatures(lines: Sequence[str]):
|
|
280
|
+
"""Set of (direction, glyph, neighbour) from ``check_topology``."""
|
|
281
|
+
return {(d, ch, n) for _r, _c, ch, d, n in check_topology(lines)}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def new_breaks(merged_lines: Sequence[str], baseline_lines: Sequence[str]) -> List[Break]:
|
|
285
|
+
"""Breaks in ``merged_lines`` whose signature is not in the unmerged table."""
|
|
286
|
+
allowed = signatures(baseline_lines)
|
|
287
|
+
out = []
|
|
288
|
+
for brk in check_topology(merged_lines):
|
|
289
|
+
if (brk[3], brk[2], brk[4]) in allowed:
|
|
290
|
+
continue
|
|
291
|
+
row, _c, ch, direction, _n = brk
|
|
292
|
+
if (
|
|
293
|
+
ch == '|'
|
|
294
|
+
and direction in ('up', 'down', 'no-up', 'no-down')
|
|
295
|
+
and 0 <= row < len(merged_lines)
|
|
296
|
+
and _is_markdown_separator(merged_lines[row])
|
|
297
|
+
):
|
|
298
|
+
continue
|
|
299
|
+
out.append(brk)
|
|
300
|
+
return out
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _is_markdown_separator(line: str) -> bool:
|
|
304
|
+
"""'|---|---:|' style header rules must keep '|', even over a merge."""
|
|
305
|
+
plain = strip_ansi(line).strip()
|
|
306
|
+
return bool(plain) and plain[0] == '|' and plain[-1] == '|' and all(
|
|
307
|
+
ch in '|-: ' for ch in plain
|
|
308
|
+
)
|