[A] Added more examples
This commit is contained in:
parent
f632bee777
commit
e69f7c3af6
@ -4,6 +4,16 @@ add_executable(${PROJECT_NAME}_ex
|
||||
target_link_libraries(${PROJECT_NAME}_ex
|
||||
fort)
|
||||
|
||||
add_executable(${PROJECT_NAME}_simple_table
|
||||
simple_table.c)
|
||||
target_link_libraries(${PROJECT_NAME}_simple_table
|
||||
fort)
|
||||
|
||||
add_executable(${PROJECT_NAME}_custom_border_style
|
||||
custom_border_style.c)
|
||||
target_link_libraries(${PROJECT_NAME}_custom_border_style
|
||||
fort)
|
||||
|
||||
add_executable(${PROJECT_NAME}_print_styles
|
||||
print_styles.c)
|
||||
target_link_libraries(${PROJECT_NAME}_print_styles
|
||||
@ -14,6 +24,12 @@ add_executable(${PROJECT_NAME}_math_table
|
||||
target_link_libraries(${PROJECT_NAME}_math_table
|
||||
fort)
|
||||
|
||||
add_executable(${PROJECT_NAME}_beautiful_table
|
||||
beautiful_table.c)
|
||||
target_link_libraries(${PROJECT_NAME}_beautiful_table
|
||||
fort)
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME}_ex_cpp
|
||||
main.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_ex_cpp
|
||||
@ -21,8 +37,11 @@ target_link_libraries(${PROJECT_NAME}_ex_cpp
|
||||
|
||||
set(${PROJECT_NAME}_examples
|
||||
${PROJECT_NAME}_ex
|
||||
${PROJECT_NAME}_simple_table
|
||||
${PROJECT_NAME}_custom_border_style
|
||||
${PROJECT_NAME}_print_styles
|
||||
${PROJECT_NAME}_math_table
|
||||
${PROJECT_NAME}_beautiful_table
|
||||
${PROJECT_NAME}_ex_cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
|
137
example/beautiful_table.c
Normal file
137
example/beautiful_table.c
Normal file
@ -0,0 +1,137 @@
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "fort.h"
|
||||
|
||||
|
||||
void colorfull_table_wchar(void)
|
||||
{
|
||||
#if defined(FT_HAVE_WCHAR)
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_border_style(table, FT_NICE_STYLE);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
|
||||
/* Filling table with data */
|
||||
ft_wwrite_ln(table, L"Test", L"Iterations", L"ms/op", L"Ticks", L"Passed");
|
||||
ft_wwrite_ln(table, L"n-body", L"1000", L"1.6", L"1,500,000", L"✔");
|
||||
ft_add_separator(table);
|
||||
ft_wwrite_ln(table, L"regex-redux", L"1000", L"0.8", L"8,000,000");
|
||||
ft_wwrite_ln(table, L"", L"2500", L"3.9", L"27,000,000", L"✖");
|
||||
ft_wwrite_ln(table, L"", L"10000", L"12.5", L"96,800,000");
|
||||
ft_add_separator(table);
|
||||
ft_wwrite_ln(table, L"mandelbrot", L"1000", L"8.1", L"89,000,000");
|
||||
ft_wwrite_ln(table, L"", L"2500", L"19.8", L"320,000,000", L"✔");
|
||||
ft_wwrite_ln(table, L"", L"10000", L"60.7", L"987,000,000");
|
||||
ft_add_separator(table);
|
||||
ft_set_cell_span(table, 8, 0, 4);
|
||||
ft_wwrite_ln(table, L"Total result", L"", L"", L"", L"✖");
|
||||
|
||||
/* Setting text styles */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, 8, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_ITALIC);
|
||||
|
||||
/* Set alignment */
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
ft_set_cell_prop(table, 8, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
||||
/* Set colors */
|
||||
ft_set_cell_prop(table, 1, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 3, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 6, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 8, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 3, 2, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 4, 3, FT_CPROP_CONT_BG_COLOR, FT_COLOR_LIGHT_RED);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_FG_COLOR, FT_COLOR_LIGHT_BLUE);
|
||||
|
||||
/* Move table to the center of the screen */
|
||||
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 1);
|
||||
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 10);
|
||||
|
||||
const wchar_t *table_wstr = ft_to_wstring(table);
|
||||
if (table_wstr) {
|
||||
fwprintf(stderr, L"Table:\n%ls\n\n ", table_wstr);
|
||||
} else {
|
||||
fwprintf(stderr, L"Table conversion failed !!!\n ");
|
||||
}
|
||||
|
||||
ft_destroy_table(table);
|
||||
#endif
|
||||
}
|
||||
|
||||
void colorfull_table_utf8(void)
|
||||
{
|
||||
#if defined(FT_HAVE_UTF8)
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_border_style(table, FT_NICE_STYLE);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
|
||||
/* Filling table with data */
|
||||
ft_u8write_ln(table, "Тест", "Итерации", "ms/op", "Тики", "Результат");
|
||||
ft_u8write_ln(table, "n-body", "1000", "1.6", "1,500,000", "✔");
|
||||
ft_add_separator(table);
|
||||
ft_u8write_ln(table, "regex-redux", "1000", "0.8", "8,000,000");
|
||||
ft_u8write_ln(table, "", "2500", "3.9", "27,000,000", "✖");
|
||||
ft_u8write_ln(table, "", "10000", "12.5", "96,800,000");
|
||||
ft_add_separator(table);
|
||||
ft_u8write_ln(table, "mandelbrot", "1000", "8.1", "89,000,000");
|
||||
ft_u8write_ln(table, "", "2500", "19.8", "320,000,000", "✔");
|
||||
ft_u8write_ln(table, "", "10000", "60.7", "987,000,000");
|
||||
ft_add_separator(table);
|
||||
ft_set_cell_span(table, 8, 0, 4);
|
||||
ft_u8write_ln(table, "Итог", "", "", "", "✖");
|
||||
|
||||
/* Setting text styles */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, 8, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_ITALIC);
|
||||
|
||||
/* Set alignment */
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
ft_set_cell_prop(table, 8, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
||||
/* Set colors */
|
||||
ft_set_cell_prop(table, 1, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 3, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 6, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 8, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 3, 2, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 4, 3, FT_CPROP_CONT_BG_COLOR, FT_COLOR_LIGHT_RED);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_FG_COLOR, FT_COLOR_LIGHT_BLUE);
|
||||
|
||||
/* Move table to the center of the screen */
|
||||
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 1);
|
||||
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 10);
|
||||
|
||||
const char *table_str = ft_to_u8string(table);
|
||||
if (table_str) {
|
||||
printf("Table:\n%s\n\n ", table_str);
|
||||
} else {
|
||||
printf("Table conversion failed !!!\n ");
|
||||
}
|
||||
|
||||
ft_destroy_table(table);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
colorfull_table_wchar();
|
||||
colorfull_table_utf8();
|
||||
return 0;
|
||||
}
|
40
example/custom_border_style.c
Normal file
40
example/custom_border_style.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fort.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
|
||||
/* Setup header */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||
|
||||
/* Fill table */
|
||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||
ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
|
||||
ft_add_separator(table);
|
||||
ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");
|
||||
|
||||
/* Set custom border style */
|
||||
struct ft_border_chars border;
|
||||
border.top_border_ch = "^";
|
||||
border.separator_ch = "=";
|
||||
border.bottom_border_ch = "v";
|
||||
border.side_border_ch = "|";
|
||||
border.out_intersect_ch = "x";
|
||||
border.in_intersect_ch = "x";
|
||||
|
||||
struct ft_border_style border_style;
|
||||
memcpy(&border_style.border_chs, &border, sizeof(struct ft_border_chars));
|
||||
memcpy(&border_style.header_border_chs, &border, sizeof(struct ft_border_chars));
|
||||
border_style.hor_separator_char = "~";
|
||||
ft_set_border_style(table, &border_style);
|
||||
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
|
||||
return 0;
|
||||
}
|
172
example/main.c
172
example/main.c
@ -22,21 +22,6 @@ static ft_table_t *create_basic_table(void)
|
||||
return table;
|
||||
}
|
||||
|
||||
void base_example(void)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||
|
||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||
ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
|
||||
ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");
|
||||
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
void complex_layout_example(void)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
@ -105,170 +90,13 @@ void fill_table_with_data_example(void)
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
void custom_border_style_example(void)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||
|
||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||
ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
|
||||
ft_add_separator(table);
|
||||
ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");
|
||||
|
||||
/* Set custom border style */
|
||||
struct ft_border_chars border;
|
||||
border.top_border_ch = "^";
|
||||
border.separator_ch = "=";
|
||||
border.bottom_border_ch = "v";
|
||||
border.side_border_ch = "|";
|
||||
border.out_intersect_ch = "x";
|
||||
border.in_intersect_ch = "x";
|
||||
|
||||
struct ft_border_style border_style;
|
||||
memcpy(&border_style.border_chs, &border, sizeof(struct ft_border_chars));
|
||||
memcpy(&border_style.header_border_chs, &border, sizeof(struct ft_border_chars));
|
||||
border_style.hor_separator_char = "~";
|
||||
ft_set_border_style(table, &border_style);
|
||||
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
||||
void colorfull_table(void)
|
||||
{
|
||||
#if defined(FT_HAVE_WCHAR)
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_border_style(table, FT_NICE_STYLE);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
|
||||
/* Filling table with data */
|
||||
ft_wwrite_ln(table, L"Test", L"Iterations", L"ms/op", L"Ticks", L"Passed");
|
||||
ft_wwrite_ln(table, L"n-body", L"1000", L"1.6", L"1,500,000", L"✔");
|
||||
ft_add_separator(table);
|
||||
ft_wwrite_ln(table, L"regex-redux", L"1000", L"0.8", L"8,000,000");
|
||||
ft_wwrite_ln(table, L"", L"2500", L"3.9", L"27,000,000", L"✖");
|
||||
ft_wwrite_ln(table, L"", L"10000", L"12.5", L"96,800,000");
|
||||
ft_add_separator(table);
|
||||
ft_wwrite_ln(table, L"mandelbrot", L"1000", L"8.1", L"89,000,000");
|
||||
ft_wwrite_ln(table, L"", L"2500", L"19.8", L"320,000,000", L"✔");
|
||||
ft_wwrite_ln(table, L"", L"10000", L"60.7", L"987,000,000");
|
||||
ft_add_separator(table);
|
||||
ft_set_cell_span(table, 8, 0, 4);
|
||||
ft_wwrite_ln(table, L"Total result", L"", L"", L"", L"✖");
|
||||
|
||||
/* Setting text styles */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, 8, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_ITALIC);
|
||||
|
||||
/* Set alignment */
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
ft_set_cell_prop(table, 8, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
||||
/* Set colors */
|
||||
ft_set_cell_prop(table, 1, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 3, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 6, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 8, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 3, 2, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 4, 3, FT_CPROP_CONT_BG_COLOR, FT_COLOR_LIGHT_RED);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_FG_COLOR, FT_COLOR_LIGHT_BLUE);
|
||||
|
||||
/* Move table to the center of the screen */
|
||||
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 1);
|
||||
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 10);
|
||||
|
||||
const wchar_t *table_wstr = ft_to_wstring(table);
|
||||
if (table_wstr) {
|
||||
fwprintf(stderr, L"Table:\n%ls\n\n ", table_wstr);
|
||||
} else {
|
||||
fwprintf(stderr, L"Table conversion failed !!!\n ");
|
||||
}
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(FT_HAVE_UTF8)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_border_style(table, FT_NICE_STYLE);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
|
||||
/* Filling table with data */
|
||||
ft_u8write_ln(table, "Тест", "Итерации", "ms/op", "Тики", "Результат");
|
||||
ft_u8write_ln(table, "n-body", "1000", "1.6", "1,500,000", "✔");
|
||||
ft_add_separator(table);
|
||||
ft_u8write_ln(table, "regex-redux", "1000", "0.8", "8,000,000");
|
||||
ft_u8write_ln(table, "", "2500", "3.9", "27,000,000", "✖");
|
||||
ft_u8write_ln(table, "", "10000", "12.5", "96,800,000");
|
||||
ft_add_separator(table);
|
||||
ft_u8write_ln(table, "mandelbrot", "1000", "8.1", "89,000,000");
|
||||
ft_u8write_ln(table, "", "2500", "19.8", "320,000,000", "✔");
|
||||
ft_u8write_ln(table, "", "10000", "60.7", "987,000,000");
|
||||
ft_add_separator(table);
|
||||
ft_set_cell_span(table, 8, 0, 4);
|
||||
ft_u8write_ln(table, "Итог", "", "", "", "✖");
|
||||
|
||||
/* Setting text styles */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, 8, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_BOLD);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_CONT_TEXT_STYLE, FT_TSTYLE_ITALIC);
|
||||
|
||||
/* Set alignment */
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||
ft_set_cell_prop(table, FT_ANY_ROW, 4, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
ft_set_cell_prop(table, 8, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
||||
/* Set colors */
|
||||
ft_set_cell_prop(table, 1, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 3, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 6, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_GREEN);
|
||||
ft_set_cell_prop(table, 8, 4, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 3, 2, FT_CPROP_CONT_FG_COLOR, FT_COLOR_RED);
|
||||
ft_set_cell_prop(table, 4, 3, FT_CPROP_CONT_BG_COLOR, FT_COLOR_LIGHT_RED);
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_CONT_FG_COLOR, FT_COLOR_LIGHT_BLUE);
|
||||
|
||||
/* Move table to the center of the screen */
|
||||
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 1);
|
||||
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 10);
|
||||
|
||||
const char *table_str = ft_to_u8string(table);
|
||||
if (table_str) {
|
||||
printf("Table:\n%s\n\n ", table_str);
|
||||
} else {
|
||||
printf("Table conversion failed !!!\n ");
|
||||
}
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
base_example();
|
||||
different_cell_properties_example();
|
||||
fill_table_with_data_example();
|
||||
complex_layout_example();
|
||||
custom_border_style_example();
|
||||
colorfull_table();
|
||||
|
||||
int result = 0;
|
||||
|
||||
|
22
example/simple_table.c
Normal file
22
example/simple_table.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fort.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ft_table_t *table = ft_create_table();
|
||||
|
||||
/* Setup header */
|
||||
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||
|
||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||
ft_write_ln(table, "2", "Hamilton", "1:26.373", "221.027");
|
||||
ft_write_ln(table, "3", "Verstappen", "1:26.469", "220.782");
|
||||
|
||||
printf("%s\n", ft_to_string(table));
|
||||
ft_destroy_table(table);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user