[R] Renames directory

This commit is contained in:
seleznevae
2019-09-21 12:58:23 +03:00
parent d7bd8e4a55
commit 895cd8bfdf
12 changed files with 1 additions and 1 deletions

72
examples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,72 @@
add_executable(${PROJECT_NAME}_simple_table
simple_table.c)
target_link_libraries(${PROJECT_NAME}_simple_table
fort)
add_executable(${PROJECT_NAME}_custom_table
custom_table.c)
target_link_libraries(${PROJECT_NAME}_custom_table
fort)
add_executable(${PROJECT_NAME}_fill_table
fill_table.c)
target_link_libraries(${PROJECT_NAME}_fill_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
fort)
add_executable(${PROJECT_NAME}_math_table
math_table.c)
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}_complex_layout
complex_layout.c)
target_link_libraries(${PROJECT_NAME}_complex_layout
fort)
add_executable(${PROJECT_NAME}_non_ascii_table
non_ascii_table.c)
target_link_libraries(${PROJECT_NAME}_non_ascii_table
fort)
add_executable(${PROJECT_NAME}_ex_cpp
main.cpp)
target_link_libraries(${PROJECT_NAME}_ex_cpp
fort)
set(${PROJECT_NAME}_examples
${PROJECT_NAME}_simple_table
${PROJECT_NAME}_custom_table
${PROJECT_NAME}_fill_table
${PROJECT_NAME}_custom_border_style
${PROJECT_NAME}_print_styles
${PROJECT_NAME}_math_table
${PROJECT_NAME}_beautiful_table
${PROJECT_NAME}_complex_layout
${PROJECT_NAME}_non_ascii_table
${PROJECT_NAME}_ex_cpp
PARENT_SCOPE)
if(DEFINED FORT_LINK_LIBRARIES)
foreach(exe ${${PROJECT_NAME}_examples})
target_link_libraries(${exe} "${FORT_LINK_LIBRARIES}")
endforeach()
endif()

137
examples/beautiful_table.c Normal file
View 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;
}

34
examples/complex_layout.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include "fort.h"
int main(void)
{
ft_table_t *table = ft_create_table();
/* Change border style */
ft_set_border_style(table, FT_DOUBLE2_STYLE);
/* Setup header */
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Sed", "Aenean", "Text");
/* Fill table */
ft_write_ln(table, "Duis", "Aliquam",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
"In accumsan felis eros, nec malesuada sapien bibendum eget.");
ft_write_ln(table, "Mauris", "Curabitur",
"Proin condimentum eros viverra nunc ultricies, at fringilla \n"
"quam pellentesque.");
ft_write_ln(table, "Summary", "", "Sed tempor est eget odio varius dignissim.");
/* Setup alignments and cell span */
ft_set_cell_prop(table, 0, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, 3, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_span(table, 3, 0, 2);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
return 0;
}

View 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;
}

34
examples/custom_table.c Normal file
View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include "fort.h"
int main(void)
{
ft_table_t *table = ft_create_table();
/* Change border style */
ft_set_border_style(table, FT_NICE_STYLE);
/* Setup header */
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
/* Fill table */
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
ft_write_ln(table, "2", "12 Angry Men", "1957", "8.8");
ft_write_ln(table, "3", "It's a Wonderful Life", "1946", "8.6");
ft_add_separator(table);
ft_write_ln(table, "4", "2001: A Space Odyssey", "1968", "8.5");
ft_write_ln(table, "5", "Blade Runner", "1982", "8.1");
/* Set alignments for columns */
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
return 0;
}

83
examples/fill_table.c Normal file
View File

@@ -0,0 +1,83 @@
#include <stdio.h>
#include "fort.h"
#include <wchar.h>
#include <locale.h>
#include <string.h>
void use_printf(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_printf_ln(table, "N|Planet|Speed, km/s");
ft_printf_ln(table, "%d|%s|%5.2f", 1, "Mercury", 47.362);
ft_printf_ln(table, "%d|%s|%5.2f", 2, "Venus", 35.02);
ft_printf_ln(table, "%d|%s|%5.2f", 3, "Earth", 29.78);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
void use_write(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", "Planet", "Speed, km/s");
ft_write_ln(table, "1", "Mercury", "47.362");
ft_write_ln(table, "2", "Venus", "35.02");
ft_write_ln(table, "3", "Earth", "29.78");
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
void use_row_write(void)
{
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
const char *header[] = {"N", "Planet", "Speed, km/s"};
const char *row1[] = {"1", "Mercury", "47.362"};
const char *row2[] = {"2", "Venus", "35.02"};
const char *row3[] = {"3", "Earth", "29.78"};
ft_row_write_ln(table, 3, header);
ft_row_write_ln(table, 3, row1);
ft_row_write_ln(table, 3, row2);
ft_row_write_ln(table, 3, row3);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
void use_table_write(void)
{
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
const char *ctab[4][3] = {
{"N", "Planet", "Speed, km/s"},
{"1", "Mercury", "47.362"},
{"2", "Venus", "35.02"},
{"3", "Earth", "29.78"}
};
ft_table_write_ln(table, 4, 3, (const char **)ctab);
printf("%s\n", ft_to_string(table));
ft_destroy_table(table);
}
int main(void)
{
use_printf();
use_write();
use_row_write();
use_table_write();
return 0;
}

176
examples/main.cpp Normal file
View File

@@ -0,0 +1,176 @@
#include <iostream>
#include <vector>
#include "fort.hpp"
fort::table create_basic_table(void)
{
fort::table table;
/* Set table border style */
table.set_border_style(FT_BASIC_STYLE);
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
<< fort::separator
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
<< fort::endr;
table.column(0).set_cell_text_align(fort::text_align::center);
table.column(1).set_cell_text_align(fort::text_align::left);
std::cout << table.to_string() << std::endl;
return table;
}
void base_example(void)
{
fort::table table;
table << fort::header
<< "N" << "Driver" << "Time" << "Avg Speed" << fort::endr
<< "1" << "Ricciardo" << "1:25.945" << "47.362" << fort::endr
<< "2" << "Hamilton" << "1:26.373" << "35.02" << fort::endr
<< "3" << "Verstappen" << "1:26.469" << "29.78" << fort::endr;
std::cout << table.to_string() << std::endl;
}
void different_cell_properties_example(void)
{
fort::table table;
/* Change border style */
table.set_border_style(FT_DOUBLE2_STYLE);
table << fort::header
<< "Movie title" << "Director" << "Year" << "Rating" << fort::endr
<< "The Shawshank Redemption" << "Frank Darabont" << "1994" << "9.5" << fort::endr
<< "The Godfather" << "Francis Ford Coppola" << "1972" << "9.2" << fort::endr
<< "2001: A Space Odyssey" << "Stanley Kubrick" << "1968" << "8.5" << fort::endr;
/* Set center alignment for the 1st and 3rd columns */
table.column(1).set_cell_text_align(fort::text_align::center);
table.column(3).set_cell_text_align(fort::text_align::center);
std::cout << table.to_string() << std::endl;
}
void fill_table_with_data_example(void)
{
fort::table table;
table << fort::header;
/* Fill each cell with operator[] */
table [0][0] = "N";
table [0][1] = "Planet";
table [0][2] = "Speed, km/s";
table [0][3] = "Temperature, K";
table << fort::endr;
/* Fill with iostream operator<< */
table << 1 << "Mercury" << 47.362 << 340 << fort::endr;
/* Fill row explicitly with strings */
table.write_ln("2", "Venus", "35.02", "737");
/* Fill row with data from the container */
std::vector<std::string> arr = {"3", "Earth", "29.78", "288"};
table.range_write_ln(std::begin(arr), std::end(arr));
std::cout << table.to_string() << std::endl;
}
int main()
{
base_example();
different_cell_properties_example();
fill_table_with_data_example();
{
fort::table table;
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
<< fort::separator
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
<< fort::endr;
table[0][0].set_cell_min_width(20);
table[0][0].set_cell_text_align(fort::text_align::left);
table[2].set_cell_row_type(fort::row_type::header);
std::cout << table.to_string() << std::endl;
}
{
fort::table table;
// Fill table with data
table << fort::header;
table.write_ln("Rank", "Title", "Year", "Rating");
table.write_ln("1", "The Shawshank Redemption", "1994", "9.5");
table.write_ln("2", "12 Angry Men", "1957", "8.8");
table.write_ln("3", "It's a Wonderful Life", "1946", "8.6");
table.write_ln("4", "2001: A Space Odyssey", "1968", "8.5");
table.write_ln("5", "Blade Runner", "1982", "8.1");
table[0][0].set_cell_min_width(20);
table[0][0].set_cell_text_align(fort::text_align::left);
table.row(2).set_cell_row_type(fort::row_type::header);
table.set_left_margin(4);
table.set_border_style(FT_SOLID_STYLE);
std::cout << table.to_string();
}
{
fort::table table;
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
<< fort::endr;
table[0][0].set_cell_min_width(20);
table.column(1).set_cell_text_align(fort::text_align::center);
table[3][3].set_cell_left_padding(15);
std::cout << table.to_string() << std::endl;
}
{
fort::table table;
/* Set table border style */
table.set_border_style(FT_BASIC_STYLE);
// Fill table with data
table << fort::header
<< "Rank" << "Title" << "Year" << "Rating" << fort::endr
<< "1" << "The Shawshank Redemption" << "1994" << "9.5" << fort::endr
<< "2" << "12 Angry Men" << "1957" << "8.8" << fort::endr
<< "3" << "It's a Wonderful Life" << "1946" << "8.6" << fort::endr
<< fort::separator
<< "4" << "2001: A Space Odyssey" << "1968" << "8.5" << fort::endr
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
<< fort::endr;
table.column(0).set_cell_text_align(fort::text_align::center);
table.column(1).set_cell_text_align(fort::text_align::left);
std::cout << table.to_string() << std::endl;
}
return 0;
}

28
examples/math_table.c Normal file
View File

@@ -0,0 +1,28 @@
#include <stdio.h>
#include "fort.h"
int main(void)
{
#ifdef FT_HAVE_UTF8
ft_table_t *table = ft_create_table();
ft_set_border_style(table, FT_DOUBLE2_STYLE);
/* 2 last columns are 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);
/* Setup header */
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_u8write_ln(table, "Figure", "Formula", "Volume, cm³", "Accuracy");
ft_u8write_ln(table, "Sphere ○", "4πR³/3", "3.145", "±0.3");
ft_u8write_ln(table, "Cone ◸", "πR²h/3", "4.95", "±0.25");
ft_u8write_ln(table, "Random", "ρdv", "12.95", "±0.75");
printf("%s\n", (const char *)ft_to_u8string(table));
ft_destroy_table(table);
#endif /* FT_HAVE_UTF8 */
return 0;
}

View File

@@ -0,0 +1,42 @@
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include "fort.h"
int main(void)
{
#if defined(FT_HAVE_WCHAR) && !defined(FT_MICROSOFT_COMPILER)
setlocale(LC_CTYPE, "");
ft_set_default_border_style(FT_BASIC_STYLE);
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_wwrite_ln(table, L"Ранг", L"Название", L"Год", L"Рейтинг");
ft_wwrite_ln(table, L"1", L"Побег из Шоушенка", L"1994", L"9.5");
ft_wwrite_ln(table, L"2", L"12 разгневанных мужчин", L"1957", L"8.8");
ft_wwrite_ln(table, L"3", L"Космическая одиссея 2001 года", L"1968", L"8.5");
ft_wwrite_ln(table, L"4", L"Бегущий по лезвию", L"1982", L"8.1");
/* Ранг | Название | Год | Рейтинг */
/*FT_NWWRITE_LN(table, L"\x420\x430\x43d\x433", L"\x41d\x430\x437\x432\x430\x43d\x438\x435", L"\x413\x43e\x434", L"\x420\x435\x439\x442\x438\x43d\x433"); */
/*FT_NWWRITE_LN(table, L"1", L"\x41f\x43e\x431\x435\x433 \x438\x437 \x428\x43e\x443\x448\x435\x43d\x43a\x430", L"1994", L"9.5");*/ /* Побег из Шоушенка */
/*FT_NWWRITE_LN(table, L"2", L"12 \x440\x430\x437\x433\x43d\x435\x432\x430\x43d\x43d\x44b\x445 \x43c\x443\x436\x447\x438\x43d", L"1957", L"8.8");*/ /* 12 разгневанных мужчин */
/*FT_NWWRITE_LN(table, L"3", L"\x41a\x43e\x441\x43c\x438\x447\x435\x441\x43a\x430\x44f \x43e\x434\x438\x441\x441\x435\x44f 2001 \x433\x43e\x434\x430", L"1968", L"8.5");*/ /* Космическая одиссея 2001 года */
/*FT_NWWRITE_LN(table, L"4", L"\x411\x435\x433\x443\x449\x438\x439 \x43f\x43e \x43b\x435\x437\x432\x438\x44e", L"1982", L"8.1");*/ /* Бегущий по лезвию */
const wchar_t* table_wstr = ft_to_wstring(table);
fwprintf(stderr, L"%ls\n ", table_wstr);
ft_destroy_table(table);
#endif
return 0;
}

154
examples/print_styles.c Normal file
View File

@@ -0,0 +1,154 @@
#include <stdio.h>
#include "fort.h"
#include <wchar.h>
#include <locale.h>
#include <string.h>
void print_table_with_style(const struct ft_border_style *style, const char *name)
{
/* Just create a table with some content */
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
ft_write_ln(table, "2", "12 Angry Men", "1957", "8.8");
ft_write_ln(table, "3", "It's a Wonderful Life", "1946", "8.6");
ft_add_separator(table);
ft_write_ln(table, "4", "2001: A Space Odyssey", "1968", "8.5");
ft_write_ln(table, "5", "Blade Runner", "1982", "8.1");
/* Setup border style */
ft_set_border_style(table, style);
/* Print table */
printf("%s style:\n\n%s\n\n", name, ft_to_string(table));
ft_destroy_table(table);
}
void print_table_with_different_styles(void)
{
#define PRINT_TABLE_WITH_STYLE(style) \
print_table_with_style(style, #style)
PRINT_TABLE_WITH_STYLE(FT_BASIC_STYLE);
PRINT_TABLE_WITH_STYLE(FT_BASIC2_STYLE);
PRINT_TABLE_WITH_STYLE(FT_SIMPLE_STYLE);
PRINT_TABLE_WITH_STYLE(FT_PLAIN_STYLE);
PRINT_TABLE_WITH_STYLE(FT_DOT_STYLE);
PRINT_TABLE_WITH_STYLE(FT_EMPTY_STYLE);
PRINT_TABLE_WITH_STYLE(FT_EMPTY2_STYLE);
PRINT_TABLE_WITH_STYLE(FT_SOLID_STYLE);
PRINT_TABLE_WITH_STYLE(FT_SOLID_ROUND_STYLE);
PRINT_TABLE_WITH_STYLE(FT_NICE_STYLE);
PRINT_TABLE_WITH_STYLE(FT_DOUBLE_STYLE);
PRINT_TABLE_WITH_STYLE(FT_DOUBLE2_STYLE);
PRINT_TABLE_WITH_STYLE(FT_BOLD_STYLE);
PRINT_TABLE_WITH_STYLE(FT_BOLD2_STYLE);
PRINT_TABLE_WITH_STYLE(FT_FRAME_STYLE);
#undef PRINT_TABLE_WITH_STYLE
fflush(stdout);
}
#if defined(FT_HAVE_WCHAR)
static ft_table_t *create_basic_wtable(const struct ft_border_style *style)
{
ft_table_t *table = ft_create_table();
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
ft_wwrite_ln(table, L"Rank", L"Title", L"Year", L"Rating");
ft_wwrite_ln(table, L"1", L"The Shawshank Redemption", L"1994", L"9.5");
ft_wwrite_ln(table, L"2", L"12 Angry Men", L"1957", L"8.8");
ft_wwrite_ln(table, L"3", L"It's a Wonderful Life", L"1946", L"8.6");
ft_add_separator(table);
ft_wwrite_ln(table, L"4", L"2001: A Space Odyssey", L"1968", L"8.5");
ft_wwrite_ln(table, L"5", L"Blade Runner", L"1982", L"8.1");
ft_set_border_style(table, style);
return table;
}
#endif
void print_table_with_different_styles_in_tbl_format(void)
{
#if defined(FT_HAVE_WCHAR) && !defined(FT_MICROSOFT_COMPILER)
setlocale(LC_CTYPE, "");
ft_table_t *table = ft_create_table();
ft_set_border_style(table, FT_EMPTY_STYLE);
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 3);
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_LEFT_PADDING, 10);
const struct ft_border_style *styles[] = {
FT_BASIC_STYLE,
FT_BASIC2_STYLE,
FT_SIMPLE_STYLE,
FT_PLAIN_STYLE,
FT_DOT_STYLE,
FT_EMPTY_STYLE,
FT_EMPTY2_STYLE,
FT_SOLID_STYLE,
FT_SOLID_ROUND_STYLE,
FT_NICE_STYLE,
FT_DOUBLE_STYLE,
FT_DOUBLE2_STYLE,
FT_BOLD_STYLE,
FT_BOLD2_STYLE,
FT_FRAME_STYLE
};
const wchar_t *style_names[] = {
L"FT_BASIC_STYLE",
L"FT_BASIC2_STYLE",
L"FT_SIMPLE_STYLE",
L"FT_PLAIN_STYLE",
L"FT_DOT_STYLE",
L"FT_EMPTY_STYLE",
L"FT_EMPTY2_STYLE",
L"FT_SOLID_STYLE",
L"FT_SOLID_ROUND_STYLE",
L"FT_NICE_STYLE",
L"FT_DOUBLE_STYLE",
L"FT_DOUBLE2_STYLE",
L"FT_BOLD_STYLE",
L"FT_BOLD2_STYLE",
L"FT_FRAME_STYLE"
};
#define PRINT_TABLE_WITH_STYLE(style, style_name) \
do { \
ft_table_t *table_tmp = create_basic_wtable(style); \
ft_wprintf(table, L" %ls \n\n%ls", style_name, ft_to_wstring(table_tmp)); \
ft_destroy_table(table_tmp); \
} while (0)
for (size_t i = 0; i < sizeof(styles)/sizeof(styles[0]); ++i) {
PRINT_TABLE_WITH_STYLE(styles[i], style_names[i]);
if (i % 2)
ft_ln(table);
}
fwprintf(stderr, L"Table:\n%ls\n ", ft_to_wstring(table));
ft_destroy_table(table);
#undef PRINT_TABLE_WITH_STYLE
#endif
}
int main(void)
{
print_table_with_different_styles();
print_table_with_different_styles_in_tbl_format();
return 0;
}

22
examples/simple_table.c Normal file
View 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;
}