From a8868e7bd9b4a253fa922e4dc47cf889761a9393 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Tue, 8 May 2018 20:57:49 +0300 Subject: [PATCH] [C] Changed default alignment --- README.md | 31 ++++++++---- example/main.c | 16 ++++++ lib/fort.c | 2 +- src/options.c | 2 +- tests/bb_tests/test_table_basic.c | 84 +++++++++++++++---------------- 5 files changed, 81 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 4e95467..d6d7abf 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,31 @@ ## Example ```C -ft_table_t *table = ft_create_table(); -ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER); -ft_write_ln(table, "Rank", "Title", "Year", "Rating"); +#include "fort.h" +int main(void) +{ + ft_table_t *table = ft_create_table();; + ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER); + ft_write_ln(table, "N", "Planet", "Speed, km/s"); -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, "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); + printf("%s\n", ft_to_string(table)); + ft_destroy_table(table); +} ``` - Output: +```text ++---+---------+-------------+ +| N | Planet | Speed, km/s | ++---+---------+-------------+ +| 1 | Mercury | 47.362 | +| 2 | Venus | 35.02 | +| 3 | Earth | 29.78 | ++---+---------+-------------+ +``` diff --git a/example/main.c b/example/main.c index 8398731..e627eb0 100644 --- a/example/main.c +++ b/example/main.c @@ -33,8 +33,24 @@ void print_char_str(const char *str) } +void base_example(void) +{ + ft_table_t *table = ft_create_table();; + ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_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); +} + int main(void) { + base_example(); + int result = 0; ft_table_t *table = NULL; diff --git a/lib/fort.c b/lib/fort.c index 66f796f..4db611e 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -674,7 +674,7 @@ struct fort_cell_options g_default_cell_option = { | FT_COPT_EMPTY_STR_HEIGHT, 0, /* col_min_width */ - FT_ALIGNED_RIGHT, /* align */ + FT_ALIGNED_LEFT, /* align */ 0, /* cell_padding_top */ 0, /* cell_padding_bottom */ 1, /* cell_padding_left */ diff --git a/src/options.c b/src/options.c index 82cd0bd..238ac0b 100644 --- a/src/options.c +++ b/src/options.c @@ -17,7 +17,7 @@ struct fort_cell_options g_default_cell_option = { | FT_COPT_EMPTY_STR_HEIGHT, 0, /* col_min_width */ - FT_ALIGNED_RIGHT, /* align */ + FT_ALIGNED_LEFT, /* align */ 0, /* cell_padding_top */ 0, /* cell_padding_bottom */ 1, /* cell_padding_left */ diff --git a/tests/bb_tests/test_table_basic.c b/tests/bb_tests/test_table_basic.c index e9fdc4a..2e4ebaf 100644 --- a/tests/bb_tests/test_table_basic.c +++ b/tests/bb_tests/test_table_basic.c @@ -85,15 +85,15 @@ void test_table_basic(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -116,15 +116,15 @@ void test_table_basic(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); @@ -147,11 +147,11 @@ void test_table_basic(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| | | 234 | 3.140000 |\n" + "| | | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | |\n" + "| c | 234 | 3.140000 | |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" @@ -178,11 +178,11 @@ void test_table_basic(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| | | 234 | 3.140000 |\n" + L"| | | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | |\n" + L"| c | 234 | 3.140000 | |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" @@ -279,11 +279,11 @@ void test_wcs_table_boundaries(void) const wchar_t *table_str_etalon = L"+-----+-----------+---+\n" L"| | | |\n" - L"| 3 | 12345\x8888\x8888 | c |\n" + L"| 3 | 12345\x8888\x8888 | c |\n" L"| | | |\n" L"+-----+-----------+---+\n" L"| | | |\n" - L"| c | 12345678\x500 | c |\n" + L"| c | 12345678\x500 | c |\n" L"| | | |\n" L"+-----+-----------+---+\n" L"| | | |\n" @@ -333,15 +333,15 @@ void test_table_write(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -381,15 +381,15 @@ void test_table_write(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); @@ -417,15 +417,15 @@ void test_table_write(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -453,15 +453,15 @@ void test_table_write(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); @@ -495,15 +495,15 @@ void test_table_write(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -536,15 +536,15 @@ void test_table_write(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); @@ -570,15 +570,15 @@ void test_table_write(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -604,15 +604,15 @@ void test_table_write(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); @@ -644,15 +644,15 @@ void test_table_write(void) const char *table_str_etalon = "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" + "| 3 | c | 234 | 3.140000 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" + "| c | 234 | 3.140000 | 3 |\n" "| | | | |\n" "+-----+----------+----------+----------+\n" "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" + "| 234 | 3.140000 | 3 | c |\n" "| | | | |\n" "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); @@ -684,15 +684,15 @@ void test_table_write(void) const wchar_t *table_str_etalon = L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" + L"| 3 | c | 234 | 3.140000 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" + L"| c | 234 | 3.140000 | 3 |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n" L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" + L"| 234 | 3.140000 | 3 | c |\n" L"| | | | |\n" L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon);