From 9df2a65796d059a75a47f1c43beba71e033f44b2 Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sun, 30 Oct 2022 18:05:13 -0600 Subject: [PATCH] fix: reduce extra space left and right of plain --- table2ascii/preset_style.py | 2 +- table2ascii/table_style.py | 18 ++++++++++++++++++ tests/test_styles.py | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/table2ascii/preset_style.py b/table2ascii/preset_style.py index 5732219..4ef96b0 100644 --- a/table2ascii/preset_style.py +++ b/table2ascii/preset_style.py @@ -46,4 +46,4 @@ class PresetStyle: ascii_rounded = TableStyle.from_string(r"/===\|| |=|=||-|-|\|=/") ascii_rounded_box = TableStyle.from_string(r"/===\||||=||||-|||\||/") markdown = TableStyle.from_string(" ||||-||| ") - plain = TableStyle.from_string(" ") + plain = TableStyle.from_string(" ").set(left_and_right_edge="") diff --git a/table2ascii/table_style.py b/table2ascii/table_style.py index 2239616..323c7d2 100644 --- a/table2ascii/table_style.py +++ b/table2ascii/table_style.py @@ -75,3 +75,21 @@ def from_string(cls, string: str) -> "TableStyle": TableStyle.from_string("╔═╦═╗║║ ╟─╫─╢ ╚╩═╝") """ return cls(*string) + + def set(self, **kwargs) -> "TableStyle": + """ + Set attributes of the TableStyle + + Args: + kwargs: The attributes to set + + Returns: + A TableStyle object with the attributes set + + Example:: + + TableStyle().set(top_left_corner="╔", top_and_bottom_edge="═") + """ + for key, value in kwargs.items(): + setattr(self, key, value) + return self diff --git a/tests/test_styles.py b/tests/test_styles.py index 3becd44..422f0c1 100644 --- a/tests/test_styles.py +++ b/tests/test_styles.py @@ -661,9 +661,9 @@ def test_plain(): style=PresetStyle.plain, ) expected = ( - " # G H R S \n" - " 1 30 40 35 30 \n" - " 2 30 40 35 30 \n" - " SUM 130 140 135 130 " + " # G H R S \n" + " 1 30 40 35 30 \n" + " 2 30 40 35 30 \n" + " SUM 130 140 135 130 " ) assert text == expected