Remove trailing whitespace for FT_PLAIN_STYLE (& other similar styles)
pkbehera opened this issue · comments
If you look at the output of a table using this style:
------------
Key Value
-------------
Key1 true
Key2 2000
-------------
Every line of string that is generated has the same length, some of them have been appended with whitespaces for achieving same length. This is required for styles that use table borders, but not for styles like FT_PLAIN_STYLE
which do not have table borders.
Can such trailing whitespaces be removed? It would be good enhancement, the resulting test when copied from a terminal and pasted at other places, won't have these unnecessary trailing whitespace
Hi!
I don't think it is a good idea to modify these styles for 2 reasons:
- It will break backward compatibility since some code may already depend on these behavior
- These styles were intentionally designed to have that blank spaces at the beginning and at the end so that all lines of the output string representation will have equal size. So it was done on purpose.
Please also note that there are ft_set_border_style
, ft_set_default_border_style
(in C API
) and set_border_style
, set_default_border_style
(in C++ API
) functions which you can use to install your custom border style. In case in your application you need behavior you have described you can create your custom style FT_PLAIN_STYLE_CUSTOM
(there is a side_border_ch
property that controls characters on the both sides of the string table, you can set it to the empty string "" and get the desired behavior).
Therefore I am closing the ticket.
can you put a snippet for side_border_ch
(and the output) to get my desired behavior? Thanks!
Hi.
Here is a some snippet. Result is not quite the same you want but something close:
struct ft_border_style brdr_style;
brdr_style.border_chs.top_border_ch = "-";
brdr_style.border_chs.separator_ch = "";
brdr_style.border_chs.bottom_border_ch = "-";
brdr_style.border_chs.side_border_ch = "";
brdr_style.border_chs.out_intersect_ch = "";
brdr_style.border_chs.in_intersect_ch = "";
brdr_style.header_border_chs.top_border_ch = "-";
brdr_style.header_border_chs.separator_ch = "-";
brdr_style.header_border_chs.bottom_border_ch = "-";
brdr_style.header_border_chs.side_border_ch = "";
brdr_style.header_border_chs.out_intersect_ch = "";
brdr_style.header_border_chs.in_intersect_ch = "";
brdr_style.hor_separator_char = "";
table = ft_create_table();
ft_set_border_style(table, &brdr_style);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 0);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 0);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 1);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 0);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_EMPTY_STR_HEIGHT, 0);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
ft_write_ln(table, "Key", "Value");
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Key1", "true");
ft_write_ln(table, "Key2", "2000");
const char *table_str = ft_to_string(table);
const char *table_str_etalon =
"-----------\n" // Here is the result. No witespaces at the end.
" Key Value\n"
"-----------\n"
" Key1 true\n"
" Key2 2000\n"
"-----------\n";
assert_str_equal(table_str, table_str_etalon);
ft_destroy_table(table);