@@ -29,12 +29,6 @@ class SeparatorRowType(enum.Enum):
2929 box_bottom = enum .auto ()
3030
3131
32- class OutputStyle (enum .Flag ):
33- none = enum .auto ()
34- decorated = enum .auto ()
35- double = enum .auto ()
36-
37-
3832class FoldedTablePrinter (Printer [t .Iterable [t .Any ]]):
3933 """
4034 A printer to render an iterable of objects holding tabular data with cells folded
@@ -77,18 +71,10 @@ def echo(self, data: t.Iterable[t.Any], stream: t.IO[str] | None = None) -> None
7771 col_widths = table .calculate_column_widths ()
7872
7973 # if folded, print a leading separator line
80- table_style = OutputStyle .decorated if table .folded else OutputStyle .none
81-
8274 if table .folded :
8375 echo (_separator_line (col_widths , row_type = SeparatorRowType .box_top ))
84- # print the header row and a separator (double if folded)
85- echo (
86- table .header_row .serialize (
87- col_widths ,
88- style = table_style
89- | (OutputStyle .double if table .folded else OutputStyle .none ),
90- )
91- )
76+ # print the header row and a separator
77+ echo (table .header_row .serialize (col_widths ))
9278 echo (
9379 _separator_line (
9480 col_widths ,
@@ -103,15 +89,15 @@ def echo(self, data: t.Iterable[t.Any], stream: t.IO[str] | None = None) -> None
10389 # if the table is empty, print nothing, but normally there is more than one row
10490 if len (table .rows ) > 1 :
10591 for row in table .rows [1 :- 1 ]:
106- echo (row .serialize (col_widths , style = table_style ))
92+ echo (row .serialize (col_widths ))
10793 if table .folded :
10894 echo (
10995 _separator_line (
11096 col_widths ,
11197 row_type = SeparatorRowType .box_row_separator ,
11298 )
11399 )
114- echo (table .rows [- 1 ].serialize (col_widths , style = table_style ))
100+ echo (table .rows [- 1 ].serialize (col_widths ))
115101 if table .folded :
116102 echo (_separator_line (col_widths , row_type = SeparatorRowType .box_bottom ))
117103
@@ -246,25 +232,13 @@ def _calculate_col_width(self, idx: int) -> int:
246232 0 , * (len (subrow [idx ]) if idx < len (subrow ) else 0 for subrow in self .grid )
247233 )
248234
249- def serialize (
250- self , use_col_widths : tuple [int , ...], style : OutputStyle = OutputStyle .none
251- ) -> str :
252- if style & OutputStyle .decorated :
253- separator = "╎"
254- leader = "│ "
255- trailer = " │"
256- else :
257- leader = ""
258- trailer = ""
259- separator = "|"
260-
235+ def serialize (self , use_col_widths : tuple [int , ...]) -> str :
261236 if len (self .grid ) < 1 :
262237 raise ValueError ("Invalid state. Cannot serialize an empty row." )
263238
264239 if len (self .grid ) == 1 :
265- return _format_subrow (
266- self .grid [0 ], use_col_widths , separator , leader , trailer
267- )
240+ # format using ASCII characters (not folded)
241+ return _format_subrow (self .grid [0 ], use_col_widths , "|" , "" , "" )
268242
269243 lines : list [str ] = []
270244
@@ -274,9 +248,8 @@ def serialize(
274248 for i , subrow in enumerate (self .grid ):
275249 if i > 0 :
276250 lines .append (row_separator )
277- lines .append (
278- _format_subrow (subrow , use_col_widths , separator , leader , trailer )
279- )
251+ # format using box drawing characters (part of folded output)
252+ lines .append (_format_subrow (subrow , use_col_widths , "╎" , "│ " , " │" ))
280253 return "\n " .join (lines )
281254
282255
0 commit comments