diff --git a/examples/5-beautiful_table.cpp b/examples/5-beautiful_table.cpp new file mode 100644 index 0000000..836978e --- /dev/null +++ b/examples/5-beautiful_table.cpp @@ -0,0 +1,62 @@ +#include + +#include "fort.hpp" + + +int main(void) +{ +#if defined(FT_HAVE_UTF8) + fort::utf8_table table; + table.set_border_style(FT_NICE_STYLE); + + table.column(0).set_cell_text_align(fort::text_align::center); + table.column(1).set_cell_text_align(fort::text_align::center); + + /* Filling table with data */ + table << fort::header + << "Тест" << "Итерации" << "ms/op" << "Тики" << "Результат" << fort::endr + << "n-body" << "1000" << "1.6" << "1,500,000" << "✔"<< fort::endr + << fort::separator + << "regex-redux" << "1000" << "0.8" << "8,000,000" << fort::endr + << "" << "2500" << "3.9" << "27,000,000" << "✖" << fort::endr + << "" << "10000" << "12.5" << "96,800,000" << fort::endr + << fort::separator + << "mandelbrot" << "1000" << "8.1" << "89,000,000" << fort::endr + << "" << "2500" << "19.8" << "320,000,000" << "✔" << fort::endr + << "" << "10000" << "60.7" << "987,000,000" << fort::endr + << fort::separator + << "Итог" << "" << "" << "" << "✖" << fort::endr; + + table[8][0].set_cell_span(4); + + /* Setting text styles */ + table.row(0).set_cell_content_text_style(fort::text_style::bold); + table.row(8).set_cell_content_text_style(fort::text_style::bold); + table.column(0).set_cell_content_text_style(fort::text_style::bold); + table.column(4).set_cell_content_text_style(fort::text_style::bold); + table.set_cell_content_text_style(fort::text_style::italic); + + /* Set alignment */ + table.column(1).set_cell_text_align(fort::text_align::right); + table.column(2).set_cell_text_align(fort::text_align::right); + table.column(3).set_cell_text_align(fort::text_align::right); + table.column(4).set_cell_text_align(fort::text_align::center); + table[8][0].set_cell_text_align(fort::text_align::center); + + /* Set colors */ + table[1][4].set_cell_content_fg_color(fort::color::green); + table[3][4].set_cell_content_fg_color(fort::color::red); + table[6][4].set_cell_content_fg_color(fort::color::green); + table[8][4].set_cell_content_fg_color(fort::color::red); + table[3][2].set_cell_content_fg_color(fort::color::red); + table[4][3].set_cell_content_bg_color(fort::color::light_red); + table.row(0).set_cell_content_fg_color(fort::color::light_blue); + + /* Move table to the center of the screen */ + table.set_top_margin(1); + table.set_left_margin(10); + + std::cout << table.to_string() << std::endl; +#endif + return 0; +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f004724..f7193ce 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -67,17 +67,17 @@ add_executable(${PROJECT_NAME}_fill_table_cpp target_link_libraries(${PROJECT_NAME}_fill_table_cpp fort) +add_executable(${PROJECT_NAME}_beautiful_table_cpp + 5-beautiful_table.cpp) +target_link_libraries(${PROJECT_NAME}_beautiful_table_cpp + fort) + add_executable(${PROJECT_NAME}_non_ascii_table_cpp 9-non_ascii_table.cpp) target_link_libraries(${PROJECT_NAME}_non_ascii_table_cpp 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 @@ -89,11 +89,11 @@ set(${PROJECT_NAME}_examples ${PROJECT_NAME}_complex_layout ${PROJECT_NAME}_non_ascii_table - ${PROJECT_NAME}_ex_cpp ${PROJECT_NAME}_simple_table_cpp ${PROJECT_NAME}_custom_table_cpp ${PROJECT_NAME}_complex_layout_cpp ${PROJECT_NAME}_fill_table_cpp + ${PROJECT_NAME}_beautiful_table_cpp ${PROJECT_NAME}_non_ascii_table_cpp PARENT_SCOPE) diff --git a/examples/main.cpp b/examples/main.cpp deleted file mode 100644 index 04ae0a5..0000000 --- a/examples/main.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include -#include "fort.hpp" - - -int main() -{ - { - fort::char_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::char_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::char_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::char_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; -}