diff --git a/CHANGELOG b/CHANGELOG index 0ed7bee..07f43fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Changelog +## Version 2.8.0 + +(released on 2026-01-24) + +- Pass `colalign` argument through to `tabulate`. + ## Version 2.7.0 (released on 2025-07-28) diff --git a/cli_helpers/tabular_output/tabulate_adapter.py b/cli_helpers/tabular_output/tabulate_adapter.py index f175f20..bb8f492 100644 --- a/cli_helpers/tabular_output/tabulate_adapter.py +++ b/cli_helpers/tabular_output/tabulate_adapter.py @@ -225,7 +225,14 @@ def addColorInElt(elt): def adapter(data, headers, table_format=None, preserve_whitespace=False, **kwargs): """Wrap tabulate inside a function for TabularOutputFormatter.""" - keys = ("floatfmt", "numalign", "stralign", "showindex", "disable_numparse") + keys = ( + "floatfmt", + "numalign", + "stralign", + "showindex", + "disable_numparse", + "colalign", + ) tkwargs = {"tablefmt": table_format} tkwargs.update(filter_dict_by_key(kwargs, keys)) diff --git a/tests/tabular_output/test_tabulate_adapter.py b/tests/tabular_output/test_tabulate_adapter.py index 6e7c7db..a8ceb1f 100644 --- a/tests/tabular_output/test_tabulate_adapter.py +++ b/tests/tabular_output/test_tabulate_adapter.py @@ -42,6 +42,24 @@ def test_tabulate_wrapper(): └─────────┴────────┘""" ) + data = [["abc", 1], ["d", 456]] + headers = ["letters", "number"] + output = tabulate_adapter.adapter( + iter(data), + headers, + colalign=["left", "left"], + table_format="psql_unicode", + ) + assert "\n".join(output) == dedent( + """\ + ┌─────────┬────────┐ + │ letters │ number │ + ├─────────┼────────┤ + │ abc │ 1 │ + │ d │ 456 │ + └─────────┴────────┘""" + ) + data = [["{1,2,3}", "{{1,2},{3,4}}", "{å,魚,текст}"], ["{}", "", "{}"]] headers = ["bigint_array", "nested_numeric_array", "配列"] output = tabulate_adapter.adapter(iter(data), headers, table_format="psql")