flexablelib 3.5.3__tar.gz → 3.5.5__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.5.3 → flexablelib-3.5.5}/CHANGELOG.md +46 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/PKG-INFO +9 -9
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/columns.py +38 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/table.py +8 -3
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/writers.py +22 -4
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib.egg-info/PKG-INFO +9 -9
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib.egg-info/SOURCES.txt +2 -0
- flexablelib-3.5.5/flexablelib.egg-info/requires.txt +35 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/package.json +1 -1
- flexablelib-3.5.5/tests/test_v354_fixes.py +219 -0
- flexablelib-3.5.5/tests/test_v355_fixes.py +173 -0
- flexablelib-3.5.3/flexablelib.egg-info/requires.txt +0 -35
- {flexablelib-3.5.3 → flexablelib-3.5.5}/.coveragerc +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/LICENSE +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/MANIFEST.in +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/README.md +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/admin.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/dashboard.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/keys.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/video/demo.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/video/render.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/video/scenes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/examples/video/thumbnail.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/__init__.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_frames.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_images.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_legacy/__init__.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_legacy/screen.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_legacy/widgets.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_speedups.c +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/_width_tables.h +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/box_topology.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/cells.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/colors.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/fast.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/identifiers.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/layout.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/merges.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/options.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/py.typed +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/readers.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/screen.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/style_compositions.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/table_strings.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/text_width.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/utils.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib/widgets.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/pytest.ini +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/setup.cfg +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/setup.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/style_examples.md +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/conftest.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/helpers.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_align_indicators.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_box_topology.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_cells.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_columns.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_excel.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_issues.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_merge_fill.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_merges.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_public_api_edges.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_readme_examples.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_stress_matrix.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_style_line_widths.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_styles.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_text_width.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_upstream_issues.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v211_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v213_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v214_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v215_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v216_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v217_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v218_features.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v219_coverage.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v219_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v220_exports.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v221_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v222_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v223_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v224_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v230_none.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v231_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v232_merge_ansi.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v300_style_names.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v310_layout.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v320_tui.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v330_components.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v330_frames.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v330_layout.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v330_tui.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v331_formats.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v331_panel_width.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v331_readers_bom.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v331_readers_edges.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v331_tabs.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v340_accessibility.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v340_core.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v340_input.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v350_images.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v350_images_core.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v352_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/test_v353_fixes.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tests/wincon_child.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/bench_frames.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/bench_images.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/benchmark.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/gen_ascii_table.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/generate_width_tables.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/image_demo.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/pty_check.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/readme_gallery.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/stress_matrix.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/style_examples.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/text_to_png.py +0 -0
- {flexablelib-3.5.3 → flexablelib-3.5.5}/tools/wheel_check.py +0 -0
|
@@ -2,6 +2,52 @@
|
|
|
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.5.5] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **Line breaks in Markdown, reStructuredText, AsciiDoc and LaTeX exports**:
|
|
9
|
+
every break `compose()` and the readers honour (`\r\n`, a lone `\r`,
|
|
10
|
+
`\u2028`, `\u2029`, vertical tab, form feed, `\x85`, `\x1c`-`\x1e`) now
|
|
11
|
+
becomes a space, as `\n` already did. A cell with a Windows line ending
|
|
12
|
+
split its Markdown row in two, so `from_markdown()` read back extra rows
|
|
13
|
+
and shifted every column after it; the RST grid came out ragged.
|
|
14
|
+
- **Fitting a float column to `max_width`** no longer pads its shorter
|
|
15
|
+
numbers with zeros: `-0.5` printed as `-0.50000000` when another number
|
|
16
|
+
in the column set the decimal budget.
|
|
17
|
+
- **A number written with an exponent** (`6.01e+16`) counts whole towards
|
|
18
|
+
how narrow its column can go. Only its integer digits were counted, so
|
|
19
|
+
the reduction was booked against a column that could not give it back
|
|
20
|
+
and the other columns kept their decimals while the table stayed too
|
|
21
|
+
wide.
|
|
22
|
+
|
|
23
|
+
## [3.5.4] - 2026-11-13
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- **Kitty keyboard reports with out-of-range code points** (`CSI 97;1;99999999u`,
|
|
27
|
+
a shifted key above U+10FFFF) no longer raise `ValueError` from
|
|
28
|
+
`KeyParser.feed()`: the invalid text or shifted code is ignored and the
|
|
29
|
+
key is reported as usual.
|
|
30
|
+
- **Escape followed by a bracketed paste** in the same read: the paste text
|
|
31
|
+
no longer starts with `\x1b[200~`.
|
|
32
|
+
- **Input split across reads** parses like the whole input: `ESC ESC` waits
|
|
33
|
+
for the next byte, so `ESC ESC [A` read in pieces is still `alt+up`
|
|
34
|
+
(a lone double Escape still gives two `escape` keys after the pause).
|
|
35
|
+
- **`MoneyInput` clicks** put the cursor under the clicked character (the
|
|
36
|
+
currency symbol was counted as text, so the cursor landed one place to
|
|
37
|
+
the right); clicking an empty field and then pressing `ctrl+left` no
|
|
38
|
+
longer raises `IndexError`.
|
|
39
|
+
- **`TextInput`** (and every input built on it) keeps a `cursor_pos` set
|
|
40
|
+
out of range from outside within the text instead of raising on word
|
|
41
|
+
moves.
|
|
42
|
+
- **`CoordinatesInput`** renders at widths 1 and 2 (latitude above
|
|
43
|
+
longitude) instead of raising `ValueError`.
|
|
44
|
+
- **An empty `Table` with `show_index=True`** renders like without the index
|
|
45
|
+
instead of raising `TypeError`.
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
- `Key` and `MouseEvent` keep all their fields through `copy`, `deepcopy`
|
|
49
|
+
and `pickle` (a `MouseEvent` could not be copied at all).
|
|
50
|
+
|
|
5
51
|
## [3.5.3] - 2026-11-12
|
|
6
52
|
|
|
7
53
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.5.
|
|
3
|
+
Version: 3.5.5
|
|
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
|
|
@@ -46,15 +46,15 @@ Requires-Dist: openpyxl>=3.0; extra == "excel"
|
|
|
46
46
|
Provides-Extra: html
|
|
47
47
|
Requires-Dist: lxml>=4.0; extra == "html"
|
|
48
48
|
Provides-Extra: tui
|
|
49
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
49
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "tui"
|
|
50
50
|
Provides-Extra: components
|
|
51
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
51
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "components"
|
|
52
52
|
Provides-Extra: speed
|
|
53
|
-
Requires-Dist: flexablelib-speedups==3.5.
|
|
53
|
+
Requires-Dist: flexablelib-speedups==3.5.5; extra == "speed"
|
|
54
54
|
Provides-Extra: images
|
|
55
55
|
Requires-Dist: Pillow>=8; extra == "images"
|
|
56
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
57
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
56
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "images"
|
|
57
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "images"
|
|
58
58
|
Provides-Extra: svg
|
|
59
59
|
Requires-Dist: cairosvg>=2.5; extra == "svg"
|
|
60
60
|
Provides-Extra: all
|
|
@@ -62,9 +62,9 @@ Requires-Dist: pandas>=1.0; extra == "all"
|
|
|
62
62
|
Requires-Dist: openpyxl>=3.0; extra == "all"
|
|
63
63
|
Requires-Dist: lxml>=4.0; extra == "all"
|
|
64
64
|
Requires-Dist: Pillow>=8; extra == "all"
|
|
65
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
66
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
67
|
-
Requires-Dist: flexablelib-speedups==3.5.
|
|
65
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "all"
|
|
66
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "all"
|
|
67
|
+
Requires-Dist: flexablelib-speedups==3.5.5; extra == "all"
|
|
68
68
|
Dynamic: author
|
|
69
69
|
Dynamic: author-email
|
|
70
70
|
Dynamic: classifier
|
|
@@ -497,6 +497,36 @@ def _float_extents(cells: Union[list, tuple],
|
|
|
497
497
|
)
|
|
498
498
|
|
|
499
499
|
|
|
500
|
+
def _float_shrink_floor(cells: Union[list, tuple],
|
|
501
|
+
skip_rows: frozenset = frozenset()) -> int:
|
|
502
|
+
"""
|
|
503
|
+
Narrowest a float column can be drawn without changing a number.
|
|
504
|
+
|
|
505
|
+
The integer digits always stay, and so does all of a number written
|
|
506
|
+
with an exponent: :func:`_round_float_cell` never rounds one, so its
|
|
507
|
+
point and everything after it keep their width too. Counting only the
|
|
508
|
+
integer digits booked reductions the column could not give back, and
|
|
509
|
+
the table came out wider than ``max_width``.
|
|
510
|
+
|
|
511
|
+
Example::
|
|
512
|
+
|
|
513
|
+
_float_shrink_floor([9.651, 6.5e+16]) -> 7 # '6' + '.5e+16'
|
|
514
|
+
"""
|
|
515
|
+
extents = _float_extents(cells, skip_rows)
|
|
516
|
+
floor = extents.left
|
|
517
|
+
for row_i, cell in enumerate(cells):
|
|
518
|
+
if row_i in skip_rows:
|
|
519
|
+
continue
|
|
520
|
+
parts = cell if is_some_instance(cell, tuple, list) else (cell,)
|
|
521
|
+
for part in parts:
|
|
522
|
+
text = str(part)
|
|
523
|
+
if EXP_FILTER(text) is None or FLT_FILTER(text) is None:
|
|
524
|
+
continue
|
|
525
|
+
_, point, right = text.partition(FLOAT_SEPARATOR)
|
|
526
|
+
floor = max(floor, extents.left + len(point) + visible_width(right))
|
|
527
|
+
return floor
|
|
528
|
+
|
|
529
|
+
|
|
500
530
|
def _round_float_cell(cell: Any, decimals: int) -> Any:
|
|
501
531
|
"""
|
|
502
532
|
Re-render one numeric cell with ``decimals`` digits after the point.
|
|
@@ -511,6 +541,7 @@ def _round_float_cell(cell: Any, decimals: int) -> Any:
|
|
|
511
541
|
_round_float_cell(9.651, 2) -> '9.65'
|
|
512
542
|
_round_float_cell(245.7, 0) -> '246'
|
|
513
543
|
_round_float_cell(3, 2) -> 3
|
|
544
|
+
_round_float_cell(0.5, 4) -> 0.5
|
|
514
545
|
_round_float_cell('n/a', 2) -> 'n/a'
|
|
515
546
|
"""
|
|
516
547
|
text = str(cell)
|
|
@@ -520,6 +551,13 @@ def _round_float_cell(cell: Any, decimals: int) -> Any:
|
|
|
520
551
|
# claim entirely.
|
|
521
552
|
return cell
|
|
522
553
|
|
|
554
|
+
_, point, written = text.partition(FLOAT_SEPARATOR)
|
|
555
|
+
if point and len(written) <= max(decimals, 0):
|
|
556
|
+
# Already short enough. Formatting it anyway pads it with zeros:
|
|
557
|
+
# -0.5 came out as -0.50000000 when another cell set the budget,
|
|
558
|
+
# widening the column this is trying to narrow.
|
|
559
|
+
return cell
|
|
560
|
+
|
|
523
561
|
if decimals <= 0:
|
|
524
562
|
# No point either: a column with nothing after the point should not
|
|
525
563
|
# keep paying a character for one.
|
|
@@ -23,6 +23,7 @@ from .columns import (
|
|
|
23
23
|
_align_columns,
|
|
24
24
|
_align_headers,
|
|
25
25
|
_float_extents,
|
|
26
|
+
_float_shrink_floor,
|
|
26
27
|
_is_numeric_cell,
|
|
27
28
|
_round_float_cell,
|
|
28
29
|
TYPE_NAMES,
|
|
@@ -3146,8 +3147,10 @@ class Table(object):
|
|
|
3146
3147
|
self.__semi_processed_columns_with_i
|
|
3147
3148
|
)
|
|
3148
3149
|
|
|
3150
|
+
# A table with no columns has nothing to number: the index column
|
|
3151
|
+
# alone would have no cells, so it is drawn as without the index.
|
|
3149
3152
|
return self.__form_string(
|
|
3150
|
-
table_with_i=self.__show_index
|
|
3153
|
+
table_with_i=self.__show_index and len(self.__columns) != 0
|
|
3151
3154
|
)
|
|
3152
3155
|
|
|
3153
3156
|
def __get_string_table_width(self) -> int:
|
|
@@ -3345,8 +3348,10 @@ class Table(object):
|
|
|
3345
3348
|
if type_name != TYPE_NAMES.float_ or column is None:
|
|
3346
3349
|
floor = MIN_COLUMN_SIZE
|
|
3347
3350
|
else:
|
|
3348
|
-
|
|
3349
|
-
|
|
3351
|
+
floor = max(
|
|
3352
|
+
MIN_COLUMN_SIZE,
|
|
3353
|
+
_float_shrink_floor(column['data'], skip_rows),
|
|
3354
|
+
)
|
|
3350
3355
|
lo = self.__bound_for_column(
|
|
3351
3356
|
self.__column_min_width, header, user_i
|
|
3352
3357
|
)
|
|
@@ -59,6 +59,24 @@ def _plain(value: Any) -> str:
|
|
|
59
59
|
return strip_ansi(str(value)) if value is not None else ''
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
# Every character str.splitlines() breaks on. compose() starts a new line at
|
|
63
|
+
# each of them, and so does a Markdown or AsciiDoc reader, so a single-line
|
|
64
|
+
# format has to flatten all of them, not just '\n'.
|
|
65
|
+
_LINE_BREAKS = re.compile('\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]')
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _one_line(text: str) -> str:
|
|
69
|
+
r"""
|
|
70
|
+
``text`` with every line break turned into a space.
|
|
71
|
+
|
|
72
|
+
Only replacing ``'\n'`` left the ``'\r'`` of Windows line endings, and
|
|
73
|
+
a lone ``'\r'``, ``'\u2028'`` or form feed, in the output: a cell
|
|
74
|
+
holding ``'a\r\nb'`` split its Markdown row in two, so reading the
|
|
75
|
+
table back shifted every row after it.
|
|
76
|
+
"""
|
|
77
|
+
return _LINE_BREAKS.sub(' ', text)
|
|
78
|
+
|
|
79
|
+
|
|
62
80
|
def _view(table, include_index: bool):
|
|
63
81
|
"""
|
|
64
82
|
The rows, columns and cell texts ``compose()`` would show.
|
|
@@ -327,7 +345,7 @@ def to_markdown(table, include_index: bool = False,
|
|
|
327
345
|
return ''
|
|
328
346
|
|
|
329
347
|
def cell(value):
|
|
330
|
-
return _plain(value).replace('|', '\\|')
|
|
348
|
+
return _one_line(_plain(value)).replace('|', '\\|')
|
|
331
349
|
|
|
332
350
|
header_texts = [cell(header) for header in headers]
|
|
333
351
|
row_texts = [[cell(value) for value in row] for row in view.text]
|
|
@@ -919,7 +937,7 @@ def to_rst(table, include_index: bool = False) -> str:
|
|
|
919
937
|
return ''
|
|
920
938
|
|
|
921
939
|
def cell(value):
|
|
922
|
-
return _plain(value)
|
|
940
|
+
return _one_line(_plain(value))
|
|
923
941
|
|
|
924
942
|
header_texts = [cell(h) for h in headers]
|
|
925
943
|
row_texts = [[cell(v) for v in row] for row in view.text]
|
|
@@ -962,7 +980,7 @@ def to_asciidoc(table, include_index: bool = False) -> str:
|
|
|
962
980
|
return ''
|
|
963
981
|
|
|
964
982
|
def cell(value):
|
|
965
|
-
return _plain(value).replace('|', '\\|')
|
|
983
|
+
return _one_line(_plain(value)).replace('|', '\\|')
|
|
966
984
|
|
|
967
985
|
lines = ['|===', '| ' + ' | '.join(cell(h) for h in headers)]
|
|
968
986
|
for row in view.text:
|
|
@@ -985,7 +1003,7 @@ def to_latex(table, include_index: bool = False) -> str:
|
|
|
985
1003
|
return ''
|
|
986
1004
|
|
|
987
1005
|
def escape_tex(value):
|
|
988
|
-
text = _plain(value)
|
|
1006
|
+
text = _one_line(_plain(value))
|
|
989
1007
|
out = []
|
|
990
1008
|
for ch in text:
|
|
991
1009
|
if ch == '\\':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 3.5.
|
|
3
|
+
Version: 3.5.5
|
|
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
|
|
@@ -46,15 +46,15 @@ Requires-Dist: openpyxl>=3.0; extra == "excel"
|
|
|
46
46
|
Provides-Extra: html
|
|
47
47
|
Requires-Dist: lxml>=4.0; extra == "html"
|
|
48
48
|
Provides-Extra: tui
|
|
49
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
49
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "tui"
|
|
50
50
|
Provides-Extra: components
|
|
51
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
51
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "components"
|
|
52
52
|
Provides-Extra: speed
|
|
53
|
-
Requires-Dist: flexablelib-speedups==3.5.
|
|
53
|
+
Requires-Dist: flexablelib-speedups==3.5.5; extra == "speed"
|
|
54
54
|
Provides-Extra: images
|
|
55
55
|
Requires-Dist: Pillow>=8; extra == "images"
|
|
56
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
57
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
56
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "images"
|
|
57
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "images"
|
|
58
58
|
Provides-Extra: svg
|
|
59
59
|
Requires-Dist: cairosvg>=2.5; extra == "svg"
|
|
60
60
|
Provides-Extra: all
|
|
@@ -62,9 +62,9 @@ Requires-Dist: pandas>=1.0; extra == "all"
|
|
|
62
62
|
Requires-Dist: openpyxl>=3.0; extra == "all"
|
|
63
63
|
Requires-Dist: lxml>=4.0; extra == "all"
|
|
64
64
|
Requires-Dist: Pillow>=8; extra == "all"
|
|
65
|
-
Requires-Dist: flexablelib-tui==3.5.
|
|
66
|
-
Requires-Dist: flexablelib-components==3.5.
|
|
67
|
-
Requires-Dist: flexablelib-speedups==3.5.
|
|
65
|
+
Requires-Dist: flexablelib-tui==3.5.5; extra == "all"
|
|
66
|
+
Requires-Dist: flexablelib-components==3.5.5; extra == "all"
|
|
67
|
+
Requires-Dist: flexablelib-speedups==3.5.5; extra == "all"
|
|
68
68
|
Dynamic: author
|
|
69
69
|
Dynamic: author-email
|
|
70
70
|
Dynamic: classifier
|
|
@@ -106,6 +106,8 @@ tests/test_v350_images.py
|
|
|
106
106
|
tests/test_v350_images_core.py
|
|
107
107
|
tests/test_v352_fixes.py
|
|
108
108
|
tests/test_v353_fixes.py
|
|
109
|
+
tests/test_v354_fixes.py
|
|
110
|
+
tests/test_v355_fixes.py
|
|
109
111
|
tests/wincon_child.py
|
|
110
112
|
tools/bench_frames.py
|
|
111
113
|
tools/bench_images.py
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
[all]
|
|
3
|
+
pandas>=1.0
|
|
4
|
+
openpyxl>=3.0
|
|
5
|
+
lxml>=4.0
|
|
6
|
+
Pillow>=8
|
|
7
|
+
flexablelib-tui==3.5.5
|
|
8
|
+
flexablelib-components==3.5.5
|
|
9
|
+
flexablelib-speedups==3.5.5
|
|
10
|
+
|
|
11
|
+
[components]
|
|
12
|
+
flexablelib-components==3.5.5
|
|
13
|
+
|
|
14
|
+
[excel]
|
|
15
|
+
openpyxl>=3.0
|
|
16
|
+
|
|
17
|
+
[html]
|
|
18
|
+
lxml>=4.0
|
|
19
|
+
|
|
20
|
+
[images]
|
|
21
|
+
Pillow>=8
|
|
22
|
+
flexablelib-tui==3.5.5
|
|
23
|
+
flexablelib-components==3.5.5
|
|
24
|
+
|
|
25
|
+
[pandas]
|
|
26
|
+
pandas>=1.0
|
|
27
|
+
|
|
28
|
+
[speed]
|
|
29
|
+
flexablelib-speedups==3.5.5
|
|
30
|
+
|
|
31
|
+
[svg]
|
|
32
|
+
cairosvg>=2.5
|
|
33
|
+
|
|
34
|
+
[tui]
|
|
35
|
+
flexablelib-tui==3.5.5
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""3.5.4: the key parser survives out-of-range code points in kitty
|
|
2
|
+
reports, an Escape followed by a bracketed paste keeps the paste intact,
|
|
3
|
+
input split anywhere parses like the whole; a click in a MoneyInput puts
|
|
4
|
+
the cursor under the click; CoordinatesInput renders at widths 1 and 2;
|
|
5
|
+
an empty Table with show_index renders; Key and MouseEvent survive copy
|
|
6
|
+
and pickle."""
|
|
7
|
+
|
|
8
|
+
import copy
|
|
9
|
+
import pickle
|
|
10
|
+
import random
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from flexablelib import Table
|
|
15
|
+
from flexablelib.text_width import strip_ansi, visible_width
|
|
16
|
+
|
|
17
|
+
T = pytest.importorskip('flexablelib_tui')
|
|
18
|
+
|
|
19
|
+
from flexablelib_tui.keys import (Key, KeyParser, MouseEvent, # noqa: E402
|
|
20
|
+
parse_keys)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def names(keys):
|
|
24
|
+
return [(str(k), k.char) for k in keys]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def chunked(data, step):
|
|
28
|
+
parser = KeyParser()
|
|
29
|
+
out = []
|
|
30
|
+
for i in range(0, len(data), step):
|
|
31
|
+
out += parser.feed(data[i:i + step])
|
|
32
|
+
return out + parser.flush()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def sig(keys):
|
|
36
|
+
return [(str(k), k.char, k.event, k.mouse, k.data) for k in keys]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class TestKittyOutOfRange:
|
|
40
|
+
def test_text_code_point_too_large_is_ignored(self):
|
|
41
|
+
assert names(parse_keys('\x1b[97;1;99999999u')) == [('a', 'a')]
|
|
42
|
+
|
|
43
|
+
def test_shifted_code_point_too_large_is_ignored(self):
|
|
44
|
+
keys = parse_keys('\x1b[97:9999999999;2u')
|
|
45
|
+
assert len(keys) == 1 and str(keys[0]).lower() == 'a'
|
|
46
|
+
|
|
47
|
+
def test_valid_text_still_used(self):
|
|
48
|
+
assert names(parse_keys('\x1b[97;1;241u')) == [('a', 'ñ')]
|
|
49
|
+
|
|
50
|
+
def test_following_keys_still_parsed(self):
|
|
51
|
+
keys = parse_keys('\x1b[97;1;99999999ub')
|
|
52
|
+
assert [str(k) for k in keys] == ['a', 'b']
|
|
53
|
+
|
|
54
|
+
def test_parser_state_survives(self):
|
|
55
|
+
parser = KeyParser(kitty=True)
|
|
56
|
+
parser.feed('\x1b[97:1114112;2;1114112u')
|
|
57
|
+
assert names(parser.feed('x')) == [('x', 'x')]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class TestEscapeThenPaste:
|
|
61
|
+
def test_paste_text_kept(self):
|
|
62
|
+
keys = parse_keys('\x1b\x1b[200~hola\x1b[201~')
|
|
63
|
+
assert names(keys) == [('escape', ''), ('paste', 'hola')]
|
|
64
|
+
|
|
65
|
+
def test_split_feed(self):
|
|
66
|
+
data = '\x1b\x1b[200~hola\x1b[201~'
|
|
67
|
+
for step in range(1, len(data) + 1):
|
|
68
|
+
assert names(chunked(data, step)) == \
|
|
69
|
+
[('escape', ''), ('paste', 'hola')], step
|
|
70
|
+
|
|
71
|
+
def test_paste_then_keys(self):
|
|
72
|
+
keys = parse_keys('\x1b\x1b[200~a b\x1b[201~x')
|
|
73
|
+
assert names(keys) == [('escape', ''), ('paste', 'a b'), ('x', 'x')]
|
|
74
|
+
|
|
75
|
+
def test_alt_arrow_unchanged(self):
|
|
76
|
+
assert [str(k) for k in parse_keys('\x1b\x1b[A')] == ['alt+up']
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class TestSplitInputMatchesWhole:
|
|
80
|
+
def test_escape_escape_waits_for_more(self):
|
|
81
|
+
parser = KeyParser()
|
|
82
|
+
assert parser.feed('\x1b\x1b') == []
|
|
83
|
+
assert parser.pending
|
|
84
|
+
assert [str(k) for k in parser.feed('[A')] == ['alt+up']
|
|
85
|
+
|
|
86
|
+
def test_escape_escape_then_flush(self):
|
|
87
|
+
parser = KeyParser()
|
|
88
|
+
parser.feed('\x1b\x1b')
|
|
89
|
+
assert [str(k) for k in parser.flush()] == ['escape', 'escape']
|
|
90
|
+
|
|
91
|
+
def test_alt_home_split(self):
|
|
92
|
+
assert [str(k) for k in chunked('\x1b\x1b[~', 1)] == \
|
|
93
|
+
[str(k) for k in parse_keys('\x1b\x1b[~')]
|
|
94
|
+
|
|
95
|
+
def test_random_split_points(self):
|
|
96
|
+
pieces = ['\x1b', '[', 'O', '1', ';', '5', 'A', '~', 'u', '<', 'M',
|
|
97
|
+
'm', '\x1b[200~', '\x1b[201~', 'a', 'ñ', '漢', '\t', ':',
|
|
98
|
+
'9', '$', '^', '?', '\x07', 'P', '\\']
|
|
99
|
+
rnd = random.Random(354)
|
|
100
|
+
for _ in range(3000):
|
|
101
|
+
data = ''.join(rnd.choice(pieces) for _ in range(rnd.randint(1, 14)))
|
|
102
|
+
whole = sig(parse_keys(data))
|
|
103
|
+
step = rnd.randint(1, 4)
|
|
104
|
+
assert sig(chunked(data, step)) == whole, (data, step)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class TestKeyCopyPickle:
|
|
108
|
+
EVENT = MouseEvent(0, 3, 4, True, 'drag', ('ctrl',))
|
|
109
|
+
|
|
110
|
+
@pytest.mark.parametrize('clone', [
|
|
111
|
+
copy.copy, copy.deepcopy, lambda o: pickle.loads(pickle.dumps(o))])
|
|
112
|
+
def test_mouse_event(self, clone):
|
|
113
|
+
got = clone(self.EVENT)
|
|
114
|
+
assert got == self.EVENT
|
|
115
|
+
assert (got.action, got.mods) == ('drag', ('ctrl',))
|
|
116
|
+
|
|
117
|
+
@pytest.mark.parametrize('clone', [
|
|
118
|
+
copy.copy, copy.deepcopy, lambda o: pickle.loads(pickle.dumps(o))])
|
|
119
|
+
def test_key(self, clone):
|
|
120
|
+
key = Key('ctrl+a', 'x', mouse=self.EVENT, event='repeat',
|
|
121
|
+
data=('dsr', '0'), raw='\x01')
|
|
122
|
+
got = clone(key)
|
|
123
|
+
assert isinstance(got, Key) and got == 'ctrl+a'
|
|
124
|
+
assert (got.char, got.mouse, got.event, got.data, got.raw) == \
|
|
125
|
+
('x', self.EVENT, 'repeat', ('dsr', '0'), '\x01')
|
|
126
|
+
assert got.mouse.action == 'drag'
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class TestEmptyTableWithIndex:
|
|
130
|
+
def test_renders_like_without_index(self):
|
|
131
|
+
plain = Table()
|
|
132
|
+
indexed = Table()
|
|
133
|
+
indexed.show_index = True
|
|
134
|
+
assert str(indexed) == str(plain)
|
|
135
|
+
|
|
136
|
+
def test_paginate(self):
|
|
137
|
+
table = Table()
|
|
138
|
+
table.show_index = True
|
|
139
|
+
assert list(table.paginate()) == [str(Table())]
|
|
140
|
+
|
|
141
|
+
def test_headers_only_keep_index(self):
|
|
142
|
+
table = Table(headers=['a', 'b'])
|
|
143
|
+
table.show_index = True
|
|
144
|
+
assert ' i ' in strip_ansi(str(table))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
C = pytest.importorskip('flexablelib_components')
|
|
148
|
+
|
|
149
|
+
from flexablelib_tui import App # noqa: E402
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def click(app, x, y):
|
|
153
|
+
app.dispatch(Key('mouse', mouse=MouseEvent(0, x, y, True, 'press')))
|
|
154
|
+
app.dispatch(Key('mouse', mouse=MouseEvent(0, x, y, False, 'release')))
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class TestMoneyInputClick:
|
|
158
|
+
def setup_method(self):
|
|
159
|
+
self.money = C.MoneyInput(label='Monto', value=1234)
|
|
160
|
+
self.app = App(body=C.Stack([self.money]), mouse=True)
|
|
161
|
+
self.app.run(keys=[], size=(30, 4))
|
|
162
|
+
# '› $1234.00': the marker and a space, then the symbol at x=2.
|
|
163
|
+
assert self.app.origin(self.money) == (0, 0)
|
|
164
|
+
|
|
165
|
+
def test_click_on_digit_puts_cursor_before_it(self):
|
|
166
|
+
click(self.app, 3, 1) # the '1'
|
|
167
|
+
assert self.money.cursor_pos == 0
|
|
168
|
+
click(self.app, 5, 1) # the '3'
|
|
169
|
+
assert self.money.cursor_pos == 2
|
|
170
|
+
|
|
171
|
+
def test_click_on_symbol_goes_to_start(self):
|
|
172
|
+
click(self.app, 2, 1)
|
|
173
|
+
assert self.money.cursor_pos == 0
|
|
174
|
+
|
|
175
|
+
def test_typing_after_click_inserts_there(self):
|
|
176
|
+
click(self.app, 4, 1) # the '2'
|
|
177
|
+
self.app.dispatch(Key('9', '9'))
|
|
178
|
+
assert self.money.text.startswith('192')
|
|
179
|
+
|
|
180
|
+
def test_click_past_end_of_empty_input(self):
|
|
181
|
+
money = C.MoneyInput(label='m')
|
|
182
|
+
app = App(body=C.Stack([money]), mouse=True)
|
|
183
|
+
app.run(keys=[], size=(30, 4))
|
|
184
|
+
click(app, 6, 1)
|
|
185
|
+
assert money.cursor_pos == 0
|
|
186
|
+
for name in ('ctrl+left', 'ctrl+right', 'ctrl+w', 'backspace'):
|
|
187
|
+
app.dispatch(Key(name)) # used to raise IndexError
|
|
188
|
+
app.render(30, 4)
|
|
189
|
+
assert money.text == ''
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class TestCursorOutOfRange:
|
|
193
|
+
@pytest.mark.parametrize('name', ['ctrl+left', 'ctrl+right', 'ctrl+w',
|
|
194
|
+
'alt+b', 'alt+f', 'backspace', 'left',
|
|
195
|
+
'delete', 'ctrl+k'])
|
|
196
|
+
def test_cursor_set_past_the_text(self, name):
|
|
197
|
+
field = C.TextInput(value='uno dos')
|
|
198
|
+
field.cursor_pos = 50
|
|
199
|
+
field.handle_key(Key(name))
|
|
200
|
+
assert 0 <= field.cursor_pos <= len(field.text)
|
|
201
|
+
|
|
202
|
+
def test_negative_cursor(self):
|
|
203
|
+
field = C.TextInput(value='uno')
|
|
204
|
+
field.cursor_pos = -4
|
|
205
|
+
field.handle_key(Key('x', 'x'))
|
|
206
|
+
assert field.text == 'xuno'
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class TestCoordinatesNarrow:
|
|
210
|
+
@pytest.mark.parametrize('width', [1, 2, 3, 4, 10])
|
|
211
|
+
def test_renders_within_width(self, width):
|
|
212
|
+
field = C.CoordinatesInput(label='Ubicación', value=(20.5, -103.2))
|
|
213
|
+
lines = field.render(width).split('\n')
|
|
214
|
+
assert all(visible_width(strip_ansi(l)) <= width for l in lines)
|
|
215
|
+
|
|
216
|
+
def test_narrow_stacks_both_fields(self):
|
|
217
|
+
field = C.CoordinatesInput(label='c')
|
|
218
|
+
assert len(field.render(2).split('\n')) > \
|
|
219
|
+
len(field.render(20).split('\n'))
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""3.5.5: single-line exports (Markdown, reStructuredText, AsciiDoc, LaTeX)
|
|
2
|
+
flatten every line break, not only '\\n'; a float column narrowed to fit
|
|
3
|
+
max_width never pads short numbers with zeros, and a number written with
|
|
4
|
+
an exponent counts whole towards how narrow its column can go."""
|
|
5
|
+
|
|
6
|
+
import io
|
|
7
|
+
import random
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
from flexablelib import Table
|
|
12
|
+
from flexablelib.text_width import visible_width
|
|
13
|
+
|
|
14
|
+
BREAKS = ['\r\n', '\r', '\n', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e',
|
|
15
|
+
'\x85', '\u2028', '\u2029']
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def table(rows, headers):
|
|
19
|
+
return Table.from_records(rows, headers=headers, parse_numbers=False)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class TestLineBreaksInExports:
|
|
23
|
+
@pytest.mark.parametrize('brk', BREAKS)
|
|
24
|
+
def test_markdown_row_stays_one_line(self, brk):
|
|
25
|
+
t = table([['a' + brk + 'b', 'z']], ['h' + brk + '1', 'k'])
|
|
26
|
+
md = t.to_markdown()
|
|
27
|
+
assert len(md.splitlines()) == 3
|
|
28
|
+
assert md.splitlines()[2].count('|') == 3
|
|
29
|
+
|
|
30
|
+
@pytest.mark.parametrize('brk', BREAKS)
|
|
31
|
+
def test_markdown_round_trip_keeps_rows_and_columns(self, brk):
|
|
32
|
+
t = table([['a' + brk + 'b', 'z'], ['c', 'd']], ['h', 'k'])
|
|
33
|
+
back = Table.from_markdown(t.to_markdown(), parse_numbers=False)
|
|
34
|
+
assert back.to_records() == [
|
|
35
|
+
{'h': 'a b', 'k': 'z'}, {'h': 'c', 'k': 'd'},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
def test_windows_line_ending_is_one_space(self):
|
|
39
|
+
t = table([['first\r\nsecond']], ['h'])
|
|
40
|
+
assert 'first second' in t.to_markdown()
|
|
41
|
+
assert '\r' not in t.to_markdown()
|
|
42
|
+
|
|
43
|
+
@pytest.mark.parametrize('brk', BREAKS)
|
|
44
|
+
def test_rst_grid_lines_all_same_width(self, brk):
|
|
45
|
+
t = table([['a' + brk + 'b', 'z']], ['h', 'k'])
|
|
46
|
+
lines = t.to_rst().splitlines()
|
|
47
|
+
assert len(lines) == 5
|
|
48
|
+
assert len({visible_width(line) for line in lines}) == 1
|
|
49
|
+
|
|
50
|
+
@pytest.mark.parametrize('brk', BREAKS)
|
|
51
|
+
def test_asciidoc_one_source_line_per_row(self, brk):
|
|
52
|
+
t = table([['a' + brk + 'b', 'z']], ['h', 'k'])
|
|
53
|
+
assert t.to_asciidoc().splitlines() == [
|
|
54
|
+
'|===', '| h | k', '| a b | z', '|===',
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
@pytest.mark.parametrize('brk', BREAKS)
|
|
58
|
+
def test_latex_row_on_one_line(self, brk):
|
|
59
|
+
t = table([['a' + brk + 'b', 'z']], ['h', 'k'])
|
|
60
|
+
assert 'a b & z \\\\' in t.to_latex().splitlines()
|
|
61
|
+
|
|
62
|
+
def test_pipes_still_escaped(self):
|
|
63
|
+
t = table([['x|y\r\nw']], ['h'])
|
|
64
|
+
assert '| x\\|y w |' in t.to_markdown()
|
|
65
|
+
assert '| x\\|y w' in t.to_asciidoc()
|
|
66
|
+
|
|
67
|
+
def test_csv_keeps_line_breaks_quoted(self):
|
|
68
|
+
t = table([['a\r\nb', 'c\rd']], ['h', 'k'])
|
|
69
|
+
back = Table.from_csv(io.StringIO(t.to_csv()), parse_numbers=False)
|
|
70
|
+
assert back.to_records() == [{'h': 'a\r\nb', 'k': 'c\rd'}]
|
|
71
|
+
|
|
72
|
+
def test_random_markdown_round_trip(self):
|
|
73
|
+
rng = random.Random(355)
|
|
74
|
+
alphabet = ['a', 'Z', ' ', '9', '.', '中', 'é', '|', '\\'] + BREAKS
|
|
75
|
+
for _ in range(300):
|
|
76
|
+
ncols = rng.randint(1, 4)
|
|
77
|
+
headers = ['h%d' % i for i in range(ncols)]
|
|
78
|
+
rows = [[''.join(rng.choice(alphabet)
|
|
79
|
+
for _ in range(rng.randint(0, 6)))
|
|
80
|
+
for _ in range(ncols)]
|
|
81
|
+
for _ in range(rng.randint(1, 4))]
|
|
82
|
+
md = table(rows, headers).to_markdown()
|
|
83
|
+
assert len(md.splitlines()) == 2 + len(rows), md
|
|
84
|
+
back = Table.from_markdown(md, parse_numbers=False)
|
|
85
|
+
assert len(back.to_records()) == len(rows), md
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class TestFloatColumnNarrowing:
|
|
89
|
+
def fitted(self, rows, headers, max_width):
|
|
90
|
+
t = table(rows, headers)
|
|
91
|
+
t.max_width = max_width
|
|
92
|
+
return t.compose()
|
|
93
|
+
|
|
94
|
+
def test_short_number_not_padded_with_zeros(self):
|
|
95
|
+
out = self.fitted([[6.013009189981389e+16, 1.123456789],
|
|
96
|
+
[-0.5, 2.5]], ['R', 'S'], 30)
|
|
97
|
+
assert '-0.5 ' in out
|
|
98
|
+
assert '0.50' not in out
|
|
99
|
+
|
|
100
|
+
def test_other_column_gives_up_decimals_instead(self):
|
|
101
|
+
# R cannot narrow (the exponent keeps all its digits), so S takes
|
|
102
|
+
# the whole reduction, down to the three-character column floor.
|
|
103
|
+
out = self.fitted([[6.013009189981389e+16, 1.123456789],
|
|
104
|
+
[-0.5, 2.5]], ['R', 'S'], 32)
|
|
105
|
+
assert '6.013009189981389e+16' in out
|
|
106
|
+
assert '| 1.1 |' in out
|
|
107
|
+
assert max(visible_width(line) for line in out.splitlines()) <= 32
|
|
108
|
+
|
|
109
|
+
def test_negative_zero_keeps_its_text(self):
|
|
110
|
+
rows = [[None, -1339, -6612, -1046],
|
|
111
|
+
[-4.06238450900009e+16, 168, -6.013009189981389e+16, None],
|
|
112
|
+
[-3.613745969155277e+16, -0.0, -0.0, -2846763.25]]
|
|
113
|
+
out = self.fitted(rows, ['P', 'abcdefghijkl', 'R', 'S'], 80)
|
|
114
|
+
assert '-0.000' not in out
|
|
115
|
+
|
|
116
|
+
def test_lines_stay_aligned(self):
|
|
117
|
+
out = self.fitted([[1.5e+16, 1.123456789, 'x' * 30],
|
|
118
|
+
[-0.25, 2.5, 'y']], ['A', 'B', 'C'], 40)
|
|
119
|
+
assert len({visible_width(line) for line in out.splitlines()}) == 1
|
|
120
|
+
|
|
121
|
+
def test_rounding_still_happens_when_needed(self):
|
|
122
|
+
out = self.fitted([[1.123456789, 'x' * 70], [22.5, 'y']],
|
|
123
|
+
['F', 'T'], 30)
|
|
124
|
+
assert '1.123456789' not in out
|
|
125
|
+
assert '22.5' in out or '23' in out or '22' in out
|
|
126
|
+
|
|
127
|
+
def test_stream_matches_compose_after_fit(self):
|
|
128
|
+
rows = [[6.013009189981389e+16, 1.123456789], [-0.5, 2.5]]
|
|
129
|
+
t = table(rows, ['R', 'S'])
|
|
130
|
+
t.max_width = 30
|
|
131
|
+
assert '\n'.join(t.stream([])) == t.compose()
|
|
132
|
+
|
|
133
|
+
def test_hidden_exponent_row_does_not_hold_the_column_wide(self):
|
|
134
|
+
rows = [[6.013009189981389e+16, 1.5, 'x' * 40], [2.25, 2.5, 'y']]
|
|
135
|
+
t = table(rows, ['R', 'S', 'T'])
|
|
136
|
+
t.row_filter = lambda row: row[0] != 6.013009189981389e+16
|
|
137
|
+
t.max_width = 20
|
|
138
|
+
out = t.compose()
|
|
139
|
+
assert 'e+16' not in out
|
|
140
|
+
assert max(visible_width(line) for line in out.splitlines()) <= 20
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class TestExportAlignmentSources:
|
|
144
|
+
"""Where Markdown and LaTeX take each column's alignment from."""
|
|
145
|
+
|
|
146
|
+
def base(self):
|
|
147
|
+
return Table.from_records([['a', 1], ['b', 2]], headers=['x', 'y'])
|
|
148
|
+
|
|
149
|
+
def test_one_code_for_every_column(self):
|
|
150
|
+
t = self.base()
|
|
151
|
+
t.col_alignment = 'c'
|
|
152
|
+
assert t.to_markdown().splitlines()[1] == '| :-: | :-: |'
|
|
153
|
+
assert t.to_latex().splitlines()[0] == r'\begin{tabular}{cc}'
|
|
154
|
+
|
|
155
|
+
def test_short_list_leaves_the_rest_to_the_data(self):
|
|
156
|
+
t = self.base()
|
|
157
|
+
t.col_alignment = ['c']
|
|
158
|
+
assert t.to_markdown().splitlines()[1] == '| :-: | --: |'
|
|
159
|
+
assert t.to_latex().splitlines()[0] == r'\begin{tabular}{cr}'
|
|
160
|
+
|
|
161
|
+
def test_mapping_by_header(self):
|
|
162
|
+
t = self.base()
|
|
163
|
+
t.col_alignment = {'y': 'l'}
|
|
164
|
+
assert t.to_markdown().splitlines()[1] == '| :-- | :-- |'
|
|
165
|
+
assert t.to_latex().splitlines()[0] == r'\begin{tabular}{ll}'
|
|
166
|
+
|
|
167
|
+
def test_merged_html_cell_takes_the_column_colour(self):
|
|
168
|
+
t = self.base()
|
|
169
|
+
t.column_colors = {'x': 'red'}
|
|
170
|
+
t.merge_cells(0, 0, 1, 0)
|
|
171
|
+
html = t._repr_html_()
|
|
172
|
+
assert 'rowspan="2"' in html
|
|
173
|
+
assert 'color:#' in html.split('rowspan="2"')[1].split('>')[0]
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
[all]
|
|
3
|
-
pandas>=1.0
|
|
4
|
-
openpyxl>=3.0
|
|
5
|
-
lxml>=4.0
|
|
6
|
-
Pillow>=8
|
|
7
|
-
flexablelib-tui==3.5.3
|
|
8
|
-
flexablelib-components==3.5.3
|
|
9
|
-
flexablelib-speedups==3.5.3
|
|
10
|
-
|
|
11
|
-
[components]
|
|
12
|
-
flexablelib-components==3.5.3
|
|
13
|
-
|
|
14
|
-
[excel]
|
|
15
|
-
openpyxl>=3.0
|
|
16
|
-
|
|
17
|
-
[html]
|
|
18
|
-
lxml>=4.0
|
|
19
|
-
|
|
20
|
-
[images]
|
|
21
|
-
Pillow>=8
|
|
22
|
-
flexablelib-tui==3.5.3
|
|
23
|
-
flexablelib-components==3.5.3
|
|
24
|
-
|
|
25
|
-
[pandas]
|
|
26
|
-
pandas>=1.0
|
|
27
|
-
|
|
28
|
-
[speed]
|
|
29
|
-
flexablelib-speedups==3.5.3
|
|
30
|
-
|
|
31
|
-
[svg]
|
|
32
|
-
cairosvg>=2.5
|
|
33
|
-
|
|
34
|
-
[tui]
|
|
35
|
-
flexablelib-tui==3.5.3
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|