[R] Refactoring of setting style
This commit is contained in:
parent
cea035285a
commit
87275e93fa
@ -110,6 +110,8 @@ int main()
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
@ -126,7 +128,72 @@ int main()
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
/*---------------- Different styles --------------------*/
|
||||
|
||||
ft_set_default_borders(FT_BASIC_STYLE);
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
FT_NWRITE_LN(table, "Rank", "Title", "Year", "Rating");
|
||||
|
||||
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||
FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
|
||||
FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5");
|
||||
FT_NWRITE_LN(table, "4", "Blade Runner", "1982", "8.1");
|
||||
|
||||
|
||||
printf("Table:\n");
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
|
||||
|
||||
/* ------------- */
|
||||
|
||||
// ft_set_default_borders(FT_SIMPLE_STYLE);
|
||||
|
||||
// table = ft_create_table();
|
||||
// ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
// ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
// ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
// FT_NWRITE_LN(table, "Rank", "Title", "Year", "Rating");
|
||||
|
||||
// FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||
// FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
|
||||
// FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5");
|
||||
// FT_NWRITE_LN(table, "4", "Blade Runner", "1982", "8.1");
|
||||
|
||||
|
||||
// printf("Table:\n");
|
||||
// printf("%s\n", ft_to_string(table));
|
||||
// ft_destroy_table(table);
|
||||
|
||||
// table = NULL;
|
||||
|
||||
// /* ------------- */
|
||||
|
||||
// ft_set_default_borders(FT_DOT_STYLE);
|
||||
|
||||
// table = ft_create_table();
|
||||
// ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
// ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
// ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
// FT_NWRITE_LN(table, "Rank", "Title", "Year", "Rating");
|
||||
|
||||
// FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||
// FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
|
||||
// FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5");
|
||||
// FT_NWRITE_LN(table, "4", "Blade Runner", "1982", "8.1");
|
||||
|
||||
|
||||
// printf("Table:\n");
|
||||
// printf("%s\n", ft_to_string(table));
|
||||
// ft_destroy_table(table);
|
||||
|
||||
table = NULL;
|
||||
|
||||
|
@ -282,12 +282,7 @@ FORT_EXTERN const wchar_t* ft_to_wstring(const FTABLE *FORT_RESTRICT table);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct border_chars
|
||||
struct ft_border_chars
|
||||
{
|
||||
char top_border_ch;
|
||||
char separator_ch;
|
||||
@ -297,8 +292,20 @@ struct border_chars
|
||||
char in_intersect_ch;
|
||||
};
|
||||
|
||||
FORT_EXTERN int ft_set_default_borders(struct border_chars *border_chs, struct border_chars *header_border_chs);
|
||||
FORT_EXTERN int ft_set_table_borders(FTABLE * FORT_RESTRICT table, struct border_chars *border_chs, struct border_chars *header_border_chs);
|
||||
struct ft_border_style
|
||||
{
|
||||
struct ft_border_chars border_chs;
|
||||
struct ft_border_chars header_border_chs;
|
||||
};
|
||||
|
||||
/* List of built-in table border styles */
|
||||
extern struct ft_border_style * FT_BASIC_STYLE;
|
||||
extern struct ft_border_style * FT_SIMPLE_STYLE;
|
||||
extern struct ft_border_style * FT_DOT_STYLE;
|
||||
|
||||
|
||||
FORT_EXTERN int ft_set_default_borders(struct ft_border_style *style);
|
||||
FORT_EXTERN int ft_set_table_borders(FTABLE * FORT_RESTRICT table, struct ft_border_style *style);
|
||||
|
||||
FORT_EXTERN int ft_set_default_cell_option(uint32_t option, int value);
|
||||
FORT_EXTERN int ft_set_cell_option(FTABLE * FORT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value);
|
||||
|
85
src/fort.c
85
src/fort.c
@ -662,8 +662,80 @@ int ft_add_separator(FTABLE *table)
|
||||
|
||||
|
||||
|
||||
static void set_border_options_for_options(fort_table_options_t *options, struct border_chars *border_chs, struct border_chars *header_border_chs)
|
||||
|
||||
/* ******************************************************************************* */
|
||||
|
||||
struct ft_border_style ft_basic_style =
|
||||
{
|
||||
{
|
||||
'-', /* top_border_ch */
|
||||
'\0', /* separator_ch */
|
||||
'-', /* bottom_border_ch */
|
||||
'|', /* side_border_ch */
|
||||
'+', /* out_intersect_ch */
|
||||
'\0', /* in_intersect_ch */
|
||||
},
|
||||
{
|
||||
'-', /* top_border_ch */
|
||||
'-', /* separator_ch */
|
||||
'-', /* bottom_border_ch */
|
||||
'|', /* side_border_ch */
|
||||
'+', /* out_intersect_ch */
|
||||
'+', /* in_intersect_ch */
|
||||
}
|
||||
};
|
||||
|
||||
//struct ft_border_style ft_simple_style =
|
||||
//{
|
||||
// {
|
||||
// ' ', /* top_border_ch */
|
||||
// '\0', /* separator_ch */
|
||||
// ' ', /* bottom_border_ch */
|
||||
// ' ', /* side_border_ch */
|
||||
// ' ', /* out_intersect_ch */
|
||||
// '\0', /* in_intersect_ch */
|
||||
// },
|
||||
// {
|
||||
// ' ', /* top_border_ch */
|
||||
// '-', /* separator_ch */
|
||||
// ' ', /* bottom_border_ch */
|
||||
// ' ', /* side_border_ch */
|
||||
// ' ', /* out_intersect_ch */
|
||||
// ' ', /* in_intersect_ch */
|
||||
// }
|
||||
//};
|
||||
|
||||
//struct ft_border_style ft_dot_style =
|
||||
//{
|
||||
// {
|
||||
// '.', /* top_border_ch */
|
||||
// '\0', /* separator_ch */
|
||||
// '.', /* bottom_border_ch */
|
||||
// ':', /* side_border_ch */
|
||||
// '.', /* out_intersect_ch */
|
||||
// '\0', /* in_intersect_ch */
|
||||
// },
|
||||
// {
|
||||
// '.', /* top_border_ch */
|
||||
// '.', /* separator_ch */
|
||||
// '.', /* bottom_border_ch */
|
||||
// ':', /* side_border_ch */
|
||||
// '.', /* out_intersect_ch */
|
||||
// '.', /* in_intersect_ch */
|
||||
// }
|
||||
//};
|
||||
|
||||
struct ft_border_style * FT_BASIC_STYLE = &ft_basic_style;
|
||||
//struct ft_border_style * FT_SIMPLE_STYLE = &ft_simple_style;
|
||||
//struct ft_border_style * FT_DOT_STYLE = &ft_dot_style;
|
||||
|
||||
|
||||
|
||||
static void set_border_options_for_options(fort_table_options_t *options, struct ft_border_style *style)
|
||||
{
|
||||
struct ft_border_chars *border_chs = &(style->border_chs);
|
||||
struct ft_border_chars *header_border_chs = &(style->header_border_chs);
|
||||
|
||||
#define BOR_CHARS options->border_chars
|
||||
#define H_BOR_CHARS options->header_border_chars
|
||||
|
||||
@ -712,13 +784,14 @@ static void set_border_options_for_options(fort_table_options_t *options, struct
|
||||
#undef H_BOR_CHARS
|
||||
}
|
||||
|
||||
int ft_set_default_borders(struct border_chars *border_chs, struct border_chars *header_border_chs)
|
||||
|
||||
int ft_set_default_borders(struct ft_border_style *style)
|
||||
{
|
||||
set_border_options_for_options(&g_table_options, border_chs, header_border_chs);
|
||||
set_border_options_for_options(&g_table_options, style);
|
||||
return F_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_set_table_borders(FTABLE *table, struct border_chars *border_chs, struct border_chars *header_border_chs)
|
||||
int ft_set_table_borders(FTABLE *table, struct ft_border_style *style)
|
||||
{
|
||||
assert(table);
|
||||
if (table->options == NULL) {
|
||||
@ -726,7 +799,7 @@ int ft_set_table_borders(FTABLE *table, struct border_chars *border_chs, struct
|
||||
if (table->options == NULL)
|
||||
return F_MEMORY_ERROR;
|
||||
}
|
||||
set_border_options_for_options(table->options, border_chs, header_border_chs);
|
||||
set_border_options_for_options(table->options, style);
|
||||
return F_SUCCESS;
|
||||
}
|
||||
|
||||
@ -754,3 +827,5 @@ int ft_set_default_cell_option(uint32_t option, int value)
|
||||
{
|
||||
return set_default_cell_option(option, value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -139,6 +139,13 @@ enum SeparatorItemPos
|
||||
};
|
||||
|
||||
|
||||
struct fort_border_style
|
||||
{
|
||||
char border_chars[BorderItemPosSize];
|
||||
char header_border_chars[BorderItemPosSize];
|
||||
char separator_chars[SepratorItemPosSize];
|
||||
};
|
||||
|
||||
struct fort_table_options
|
||||
{
|
||||
char border_chars[BorderItemPosSize];
|
||||
|
@ -23,22 +23,21 @@ int set_test_options_for_table(FTABLE *table)
|
||||
assert_true( status == F_SUCCESS );
|
||||
|
||||
|
||||
struct border_chars border_chs;
|
||||
border_chs.top_border_ch = '-';
|
||||
border_chs.separator_ch = '-';
|
||||
border_chs.bottom_border_ch = '-';
|
||||
border_chs.side_border_ch = '|';
|
||||
border_chs.out_intersect_ch = '+';
|
||||
border_chs.in_intersect_ch = '+';
|
||||
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 = '+';
|
||||
|
||||
struct border_chars header_border_chs;
|
||||
header_border_chs.top_border_ch = '-';
|
||||
header_border_chs.separator_ch = '-';
|
||||
header_border_chs.bottom_border_ch = '-';
|
||||
header_border_chs.side_border_ch = '|';
|
||||
header_border_chs.out_intersect_ch = '+';
|
||||
header_border_chs.in_intersect_ch = '+';
|
||||
return ft_set_table_borders(table, &border_chs, &header_border_chs);
|
||||
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 = '+';
|
||||
return ft_set_table_borders(table, &brdr_style);
|
||||
}
|
||||
|
||||
int set_test_options_as_default()
|
||||
@ -57,22 +56,21 @@ int set_test_options_as_default()
|
||||
assert_true( status == F_SUCCESS );
|
||||
|
||||
|
||||
struct border_chars border_chs;
|
||||
border_chs.top_border_ch = '-';
|
||||
border_chs.separator_ch = '-';
|
||||
border_chs.bottom_border_ch = '-';
|
||||
border_chs.side_border_ch = '|';
|
||||
border_chs.out_intersect_ch = '+';
|
||||
border_chs.in_intersect_ch = '+';
|
||||
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 = '+';
|
||||
|
||||
struct border_chars header_border_chs;
|
||||
header_border_chs.top_border_ch = '-';
|
||||
header_border_chs.separator_ch = '-';
|
||||
header_border_chs.bottom_border_ch = '-';
|
||||
header_border_chs.side_border_ch = '|';
|
||||
header_border_chs.out_intersect_ch = '+';
|
||||
header_border_chs.in_intersect_ch = '+';
|
||||
return ft_set_default_borders(&border_chs, &header_border_chs);
|
||||
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 = '+';
|
||||
return ft_set_default_borders(&brdr_style);
|
||||
}
|
||||
|
||||
void test_table_sizes(void **state)
|
||||
@ -564,22 +562,21 @@ void test_table_options(void **state)
|
||||
|
||||
WHEN("Changing cell separators") {
|
||||
|
||||
struct border_chars border_chs;
|
||||
border_chs.top_border_ch = '|';
|
||||
border_chs.separator_ch = '|';
|
||||
border_chs.bottom_border_ch = '|';
|
||||
border_chs.side_border_ch = '=';
|
||||
border_chs.out_intersect_ch = '+';
|
||||
border_chs.in_intersect_ch = '#';
|
||||
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 = '#';
|
||||
|
||||
struct border_chars header_border_chs;
|
||||
header_border_chs.top_border_ch = '*';
|
||||
header_border_chs.separator_ch = '*';
|
||||
header_border_chs.bottom_border_ch = '*';
|
||||
header_border_chs.side_border_ch = 'v';
|
||||
header_border_chs.out_intersect_ch = '+';
|
||||
header_border_chs.in_intersect_ch = '#';
|
||||
ft_set_default_borders(&border_chs, &header_border_chs);
|
||||
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 = 'v';
|
||||
brdr_style.header_border_chs.out_intersect_ch = '+';
|
||||
brdr_style.header_border_chs.in_intersect_ch = '#';
|
||||
ft_set_default_borders(&brdr_style);
|
||||
|
||||
|
||||
|
||||
@ -608,23 +605,21 @@ void test_table_options(void **state)
|
||||
|
||||
|
||||
|
||||
brdr_style.border_chs.top_border_ch = '|';
|
||||
brdr_style.border_chs.separator_ch = '\0';
|
||||
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 = '\0';
|
||||
|
||||
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 = 'v';
|
||||
brdr_style.header_border_chs.out_intersect_ch = '+';
|
||||
brdr_style.header_border_chs.in_intersect_ch = '#';
|
||||
|
||||
border_chs.top_border_ch = '|';
|
||||
border_chs.separator_ch = '\0';
|
||||
border_chs.bottom_border_ch = '|';
|
||||
border_chs.side_border_ch = '=';
|
||||
border_chs.out_intersect_ch = '+';
|
||||
border_chs.in_intersect_ch = '\0';
|
||||
|
||||
header_border_chs.top_border_ch = '*';
|
||||
header_border_chs.separator_ch = '*';
|
||||
header_border_chs.bottom_border_ch = '*';
|
||||
header_border_chs.side_border_ch = 'v';
|
||||
header_border_chs.out_intersect_ch = '+';
|
||||
header_border_chs.in_intersect_ch = '#';
|
||||
|
||||
ft_set_default_borders(&border_chs, &header_border_chs);
|
||||
ft_set_default_borders(&brdr_style);
|
||||
|
||||
ft_set_default_cell_option(FT_OPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_OPT_TOP_PADDING, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user