From 48d1594be4bedd185800cd6bedabf877a02c5198 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Tue, 8 May 2018 22:13:52 +0300 Subject: [PATCH] [A] Added example --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++-- example/main.c | 27 +++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f18691e..ed42ee4 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,13 @@ - Support of multiple lines in cells - Support of wide characters -## Example +## Examples + +### Basic using ```C +#include #include "fort.h" -#include "stdio.h" int main(void) { ft_table_t *table = ft_create_table(); @@ -47,6 +49,54 @@ Output: ``` +### Customize table appearance + +```C +#include +#include "fort.h" +int main(void) +{ + ft_table_t *table = ft_create_table(); + ft_set_border_style(table, FT_DOUBLE2_STYLE); + /* Set center alignment for the 0th column */ + ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER); + /* Set center alignment for the 3rd column */ + ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER); + + /* Set "header" type for the first row */ + ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_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", "2001: A Space Odyssey", "1968", "8.5"); + ft_write_ln(table, "4", "Blade Runner", "1982", "8.1"); + + ft_write_ln(table, "Average", "", "", "8.7"); + ft_set_cell_span(table, 5, 0, 3); + ft_set_cell_option(table, 5, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER); + + printf("%s\n", ft_to_string(table)); + ft_destroy_table(table); +} +``` +Output: +```text +╔══════╤══════════════════════════╤══════╤════════╗ +║ Rank │ Title │ Year │ Rating ║ +╠══════╪══════════════════════════╪══════╪════════╣ +║ 1 │ The Shawshank Redemption │ 1994 │ 9.5 ║ +╟──────┼──────────────────────────┼──────┼────────╢ +║ 2 │ 12 Angry Men │ 1957 │ 8.8 ║ +╟──────┼──────────────────────────┼──────┼────────╢ +║ 3 │ 2001: A Space Odyssey │ 1968 │ 8.5 ║ +╟──────┼──────────────────────────┼──────┼────────╢ +║ 4 │ Blade Runner │ 1982 │ 8.1 ║ +╠══════╧══════════════════════════╧══════╪════════╣ +║ Average │ 8.7 ║ +╚════════════════════════════════════════╧════════╝ +``` + ## Installation diff --git a/example/main.c b/example/main.c index 16811ba..30691b4 100644 --- a/example/main.c +++ b/example/main.c @@ -48,9 +48,36 @@ void base_example(void) ft_destroy_table(table); } +void different_cell_options(void) +{ + ft_table_t *table = ft_create_table(); + ft_set_border_style(table, FT_DOUBLE2_STYLE); + /* Set center alignment for the 0th column */ + ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER); + /* Set center alignment for the 3rd column */ + ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER); + + /* Set "header" type for the first row */ + ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_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", "2001: A Space Odyssey", "1968", "8.5"); + ft_write_ln(table, "4", "Blade Runner", "1982", "8.1"); + + ft_write_ln(table, "Average", "", "", "8.7"); + ft_set_cell_span(table, 5, 0, 3); + ft_set_cell_option(table, 5, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER); + + printf("%s\n", ft_to_string(table)); + ft_destroy_table(table); +} + int main(void) { base_example(); + different_cell_options(); int result = 0;