{"id":13576950,"url":"https://github.com/seleznevae/libfort","last_synced_at":"2025-04-04T13:09:00.905Z","repository":{"id":30270081,"uuid":"124448051","full_name":"seleznevae/libfort","owner":"seleznevae","description":"C/C++ library to create formatted ASCII tables for console applications","archived":false,"fork":false,"pushed_at":"2024-06-05T01:29:02.000Z","size":1896,"stargazers_count":511,"open_issues_count":27,"forks_count":66,"subscribers_count":18,"default_branch":"develop","last_synced_at":"2025-03-28T12:05:41.745Z","etag":null,"topics":["ascii","c","console","cpp","cpp11","table"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seleznevae.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-08T21:05:29.000Z","updated_at":"2025-03-22T10:51:03.000Z","dependencies_parsed_at":"2024-01-16T20:25:45.925Z","dependency_job_id":"8dc7a7a8-a981-492b-9c9e-e54dda31ff3c","html_url":"https://github.com/seleznevae/libfort","commit_stats":{"total_commits":531,"total_committers":6,"mean_commits":88.5,"dds":0.00941619585687381,"last_synced_commit":"41237162a9bd34a30a88069ee4e230584ae8d674"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Flibfort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Flibfort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Flibfort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seleznevae%2Flibfort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seleznevae","download_url":"https://codeload.github.com/seleznevae/libfort/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182334,"owners_count":20897379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ascii","c","console","cpp","cpp11","table"],"created_at":"2024-08-01T15:01:16.194Z","updated_at":"2025-04-04T13:09:00.874Z","avatar_url":"https://github.com/seleznevae.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# libfort (Library to create FORmatted Tables)\n\n[![Build Status](https://travis-ci.com/seleznevae/libfort.svg?branch=master)](https://travis-ci.com/seleznevae/libfort)\n[![Build Status](https://api.cirrus-ci.com/github/seleznevae/libfort.svg)](https://cirrus-ci.com/github/seleznevae/libfort)\n[![Build status](https://ci.appveyor.com/api/projects/status/ll1qygb56pho95xw/branch/master?svg=true)](https://ci.appveyor.com/project/seleznevae/libfort/branch/master)\n[![Build Status](https://cloud.drone.io/api/badges/seleznevae/libfort/status.svg?ref=refs/heads/master)](https://cloud.drone.io/seleznevae/libfort)\n[![Coverage Status](https://coveralls.io/repos/github/seleznevae/libfort/badge.svg?branch=master)](https://coveralls.io/github/seleznevae/libfort?branch=master)\n[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/h566MmC2bfdsZZDr)\n[![Documentation](https://img.shields.io/badge/docs-doxygen-blue.svg)](http://seleznevae.github.io/libfort)\n[![Doc](https://img.shields.io/badge/doc-wiki-blue.svg)](https://github.com/seleznevae/libfort/wiki)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**libfort** is a simple crossplatform library to create formatted text tables.\n\n![TableSample](https://github.com/seleznevae/libfort/blob/master/docs/images/color_table.png)\n\n**Features:**\n- Easy to integrate (only 2 files)\n- Customization of appearance (various [border styles](https://github.com/seleznevae/libfort/wiki/Border-styles-(C-API)) and row/column/cell [properties](https://github.com/seleznevae/libfort/wiki/Cell--and-table-properties-(C-API)) for indentation, alignment, padding)\n- A number of functions to fill the table (add content by adding separate cells, rows or use `printf` like functions)\n- Support of multiple lines in cells\n- Support of UTF-8 and wide characters\n\n## Design goals\n- **Portability**. All main OSes (Linux, Windows, macOS, FreeBSD) and compilers are supported.\n- **Maintainability and robustness**. **libfort** is written in C because it is much less complicated than C++ and it can be used in both C and C++ projects and even on platforms without C++ compiler.\n- **Trivial integration.** Therefore all source code files are amalgamed in only 2 files.\n- **Heavy testing.** The goal is to cover 100% of the code (it is not reached yet) and to run tests on all major compilers and platforms.\n\n## Integration\nAdd 2 files ( [`fort.c`](https://github.com/seleznevae/libfort/blob/master/lib/fort.c)  and [`fort.h`](https://github.com/seleznevae/libfort/blob/master/lib/fort.h) from [**lib**](https://github.com/seleznevae/libfort/tree/master/lib) directory) to your C or C++ project and include\n```C\n#include \"fort.h\"\n```\nin your source code where you will use **libfort** functions.\n\nFor C++ projects that use compiler with C++11 support (and later) there are also availabe convenient C++ wrappers around C functions (see [`fort.hpp`](https://github.com/seleznevae/libfort/blob/master/lib/fort.hpp) in **lib** direrctory). In that case instead of _fort.h_ you will need to include\n```CPP\n#include \"fort.hpp\"\n```\n\n### Integration with cmake\n\nIn case **libfort** is installed on the host system it should be sufficient to use `find_package`:\n```cmake\nfind_package(libfort)\ntarget_link_libraries(your_target PRIVATE libfort::fort)\n```\n\nIn case you downloaded **libfort** sources and embedded them in your project (e.g. put all sources in directory `third-party/libfort`) you can use `add_subdirectory`:\n```cmake\n# Disable building tests and examples in libfort project\nset(FORT_ENABLE_TESTING OFF CACHE INTERNAL \"\")\n\nadd_subdirectory(third-party/libfort)\ntarget_link_libraries(your_target PRIVATE fort)\n```\n\n## Documentation\nSee guide in [tutorial](https://github.com/seleznevae/libfort/blob/develop/docs/tutorial/Tutorial.md) of the library and doxygen [API documentation](http://seleznevae.github.io/libfort).\n\n## Getting Started\n\nThe common libfort usage pattern (C API): \n- create a table (`ft_create_table`);\n- fill it with data (`ft_write_ln`, `fr_ptrintf_ln`, `ft_row_write`, ...);\n- modify basic table appearance (`ft_set_cell_prop`, `ft_set_border_style` ...)\n- convert table to string representation (`ft_to_string`);\n- destroy the table (`ft_destroy_table`)\n\nHere are some examples:\n\n### Basic example\n\n\n```C\n/* C API */\n#include \u003cstdio.h\u003e\n#include \"fort.h\"\nint main(void)\n{\n    ft_table_t *table = ft_create_table();\n    /* Set \"header\" type for the first row */\n    ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);\n\n    ft_write_ln(table, \"N\", \"Driver\", \"Time\", \"Avg Speed\");\n\n    ft_write_ln(table, \"1\", \"Ricciardo\", \"1:25.945\", \"222.128\");\n    ft_write_ln(table, \"2\", \"Hamilton\", \"1:26.373\", \"221.027\");\n    ft_write_ln(table, \"3\", \"Verstappen\", \"1:26.469\", \"220.782\");\n\n    printf(\"%s\\n\", ft_to_string(table));\n    ft_destroy_table(table);\n}\n```\n\n```C++\n/* C++ API */\n#include \u003ciostream\u003e\n#include \"fort.hpp\"\nint main(void)\n{\n    fort::char_table table;\n    table \u003c\u003c fort::header\n        \u003c\u003c \"N\" \u003c\u003c \"Driver\" \u003c\u003c \"Time\" \u003c\u003c \"Avg Speed\" \u003c\u003c fort::endr\n        \u003c\u003c \"1\" \u003c\u003c \"Ricciardo\" \u003c\u003c \"1:25.945\" \u003c\u003c \"47.362\" \u003c\u003c fort::endr\n        \u003c\u003c \"2\" \u003c\u003c \"Hamilton\" \u003c\u003c \"1:26.373\" \u003c\u003c \"35.02\" \u003c\u003c fort::endr\n        \u003c\u003c \"3\" \u003c\u003c \"Verstappen\" \u003c\u003c \"1:26.469\" \u003c\u003c \"29.78\" \u003c\u003c fort::endr;\n\n    std::cout \u003c\u003c table.to_string() \u003c\u003c std::endl;\n}\n```\n\nOutput:\n```text\n+---+------------+----------+-----------+\n| N | Driver     | Time     | Avg Speed |\n+---+------------+----------+-----------+\n| 1 | Ricciardo  | 1:25.945 | 47.362    |\n| 2 | Hamilton   | 1:26.373 | 35.02     |\n| 3 | Verstappen | 1:26.469 | 29.78     |\n+---+------------+----------+-----------+\n```\n\n### Customize table appearance\n\n```C\n/* C API */\n#include \u003cstdio.h\u003e\n#include \"fort.h\"\nint main(void)\n{\n    ft_table_t *table = ft_create_table();\n    /* Change border style */\n    ft_set_border_style(table, FT_DOUBLE2_STYLE);\n\n    /* Set \"header\" type for the first row */\n    ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);\n    ft_write_ln(table, \"Movie title\", \"Director\", \"Year\", \"Rating\");\n\n    ft_write_ln(table, \"The Shawshank Redemption\", \"Frank Darabont\", \"1994\", \"9.5\");\n    ft_write_ln(table, \"The Godfather\", \"Francis Ford Coppola\", \"1972\", \"9.2\");\n    ft_write_ln(table, \"2001: A Space Odyssey\", \"Stanley Kubrick\", \"1968\", \"8.5\");\n\n    /* Set center alignment for the 1st and 3rd columns */\n    ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);\n    ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);\n\n    printf(\"%s\\n\", ft_to_string(table));\n    ft_destroy_table(table);\n}\n```\n\n```C++\n/* C++ API */\n#include \u003ciostream\u003e\n#include \"fort.hpp\"\nint main(void)\n{\n    fort::char_table table;\n    /* Change border style */\n    table.set_border_style(FT_DOUBLE2_STYLE);\n\n    table \u003c\u003c fort::header\n        \u003c\u003c \"Movie title\" \u003c\u003c \"Director\" \u003c\u003c \"Year\" \u003c\u003c \"Rating\" \u003c\u003c fort::endr\n        \u003c\u003c \"The Shawshank Redemption\" \u003c\u003c \"Frank Darabont\" \u003c\u003c \"1994\" \u003c\u003c \"9.5\" \u003c\u003c fort::endr\n        \u003c\u003c \"The Godfather\" \u003c\u003c \"Francis Ford Coppola\" \u003c\u003c \"1972\" \u003c\u003c \"9.2\" \u003c\u003c fort::endr\n        \u003c\u003c \"2001: A Space Odyssey\" \u003c\u003c \"Stanley Kubrick\" \u003c\u003c \"1968\" \u003c\u003c \"8.5\" \u003c\u003c fort::endr;\n\n    /* Set center alignment for the 1st and 3rd columns */\n    table.column(1).set_cell_text_align(fort::text_align::center);\n    table.column(3).set_cell_text_align(fort::text_align::center);\n\n    std::cout \u003c\u003c table.to_string() \u003c\u003c std::endl;\n}\n```\n\nOutput:\n```text\n╔══════════════════════════╤══════════════════════╤══════╤════════╗\n║ Movie title              │       Director       │ Year │ Rating ║\n╠══════════════════════════╪══════════════════════╪══════╪════════╣\n║ The Shawshank Redemption │    Frank Darabont    │ 1994 │  9.5   ║\n╟──────────────────────────┼──────────────────────┼──────┼────────╢\n║ The Godfather            │ Francis Ford Coppola │ 1972 │  9.2   ║\n╟──────────────────────────┼──────────────────────┼──────┼────────╢\n║ 2001: A Space Odyssey    │   Stanley Kubrick    │ 1968 │  8.5   ║\n╚══════════════════════════╧══════════════════════╧══════╧════════╝\n```\n\n### Different ways to fill table with data\n\n```C\n/* C API */\n#include \u003cstdio.h\u003e\n#include \"fort.h\"\nint main(void)\n{\n    ft_table_t *table = ft_create_table();\n    /* Set \"header\" type for the first row */\n    ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);\n    ft_write_ln(table, \"N\", \"Planet\", \"Speed, km/s\", \"Temperature, K\");\n\n    /* Fill row with printf like function */\n    ft_printf_ln(table, \"1|%s|%6.3f|%d\", \"Mercury\", 47.362, 340);\n\n    /* Fill row explicitly with strings */\n    ft_write_ln(table, \"2\", \"Venus\", \"35.02\", \"737\");\n\n    /* Fill row with the array of strings */\n    const char *arr[4] = {\"3\", \"Earth\", \"29.78\", \"288\"};\n    ft_row_write_ln(table, 4, arr);\n\n    printf(\"%s\\n\", ft_to_string(table));\n    ft_destroy_table(table);\n}\n```\n\n```C++\n/* C++ API */\n#include \u003ciostream\u003e\n#include \"fort.hpp\"\nint main(void)\n{\n    fort::char_table table;\n    table \u003c\u003c fort::header;\n    /* Fill each cell with operator[] */\n    table [0][0] = \"N\";\n    table [0][1] = \"Planet\";\n    table [0][2] = \"Speed, km/s\";\n    table [0][3] = \"Temperature, K\";\n    table \u003c\u003c fort::endr;\n\n    /* Fill with iostream operator\u003c\u003c */\n    table \u003c\u003c 1 \u003c\u003c \"Mercury\" \u003c\u003c 47.362 \u003c\u003c 340 \u003c\u003c fort::endr;\n\n    /* Fill row explicitly with strings */\n    table.write_ln(\"2\", \"Venus\", \"35.02\", \"737\");\n\n    /* Fill row with data from the container */\n    std::vector\u003cstd::string\u003e arr = {\"3\", \"Earth\", \"29.78\", \"288\"};\n    table.range_write_ln(std::begin(arr), std::end(arr));\n\n    std::cout \u003c\u003c table.to_string() \u003c\u003c std::endl;\n}\n```\n\nOutput:\n```text\n+---+---------+-------------+----------------+\n| N | Planet  | Speed, km/s | Temperature, K |\n+---+---------+-------------+----------------+\n| 1 | Mercury | 47.362      | 340            |\n| 2 | Venus   | 35.02       | 737            |\n| 3 | Earth   | 29.78       | 288            |\n+---+---------+-------------+----------------+\n```\n\n### Working with multibyte-character-strings\n`libfort` supports `wchar_t` and utf-8 strings. Here are simple examples of working with utf-8 strings:\n\n\n```C\n/* C API */\n#include \u003cstdio.h\u003e\n#include \"fort.h\"\nint main(void)\n{\n    ft_table_t *table = ft_create_table();\n    ft_set_border_style(table, FT_NICE_STYLE);\n    ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);\n    ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);\n    ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);\n\n    ft_u8write_ln(table, \"Ранг\", \"Название\", \"Год\", \"Рейтинг\");\n    ft_u8write_ln(table, \"1\", \"Побег из Шоушенка\", \"1994\", \"9.5\");\n    ft_u8write_ln(table, \"2\", \"12 разгневанных мужчин\", \"1957\", \"8.8\");\n    ft_u8write_ln(table, \"3\", \"Космическая одиссея 2001 года\", \"1968\", \"8.5\");\n    ft_u8write_ln(table, \"4\", \"Бегущий по лезвию\", \"1982\", \"8.1\");\n\n    printf(\"%s\\n\", (const char *)ft_to_u8string(table));\n    ft_destroy_table(table);\n}\n```\n\n```C++\n/* C++ API */\n#include \u003ciostream\u003e\n#include \"fort.hpp\"\nint main(void)\n{\n    fort::utf8_table table;\n    table.set_border_style(FT_NICE_STYLE);\n    table.column(0).set_cell_text_align(fort::text_align::center);\n    table.column(1).set_cell_text_align(fort::text_align::center);\n\n    table \u003c\u003c fort::header\n          \u003c\u003c \"Ранг\" \u003c\u003c \"Название\" \u003c\u003c \"Год\" \u003c\u003c \"Рейтинг\" \u003c\u003c fort::endr\n          \u003c\u003c \"1\" \u003c\u003c \"Побег из Шоушенка\" \u003c\u003c \"1994\" \u003c\u003c \"9.5\"\u003c\u003c fort::endr\n          \u003c\u003c \"2\" \u003c\u003c \"12 разгневанных мужчин\" \u003c\u003c \"1957\" \u003c\u003c \"8.8\" \u003c\u003c fort::endr\n          \u003c\u003c \"3\" \u003c\u003c \"Космическая одиссея 2001 года\" \u003c\u003c \"1968\" \u003c\u003c \"8.5\" \u003c\u003c fort::endr\n          \u003c\u003c \"4\" \u003c\u003c \"Бегущий по лезвию\" \u003c\u003c \"1982\" \u003c\u003c \"8.1\" \u003c\u003c fort::endr;\n    std::cout \u003c\u003c table.to_string() \u003c\u003c std::endl;\n}\n```\n\nOutput:\n```text\n╔══════╦═══════════════════════════════╦══════╦═════════╗\n║ Ранг ║           Название            ║ Год  ║ Рейтинг ║\n╠══════╬═══════════════════════════════╬══════╬═════════╣\n║  1   ║       Побег из Шоушенка       ║ 1994 ║ 9.5     ║\n║  2   ║    12 разгневанных мужчин     ║ 1957 ║ 8.8     ║\n║  3   ║ Космическая одиссея 2001 года ║ 1968 ║ 8.5     ║\n║  4   ║       Бегущий по лезвию       ║ 1982 ║ 8.1     ║\n╚══════╩═══════════════════════════════╩══════╩═════════╝\n```\n\nPlease note:\n-  `libfort` internally has a very simple logic to compute visible width of utf-8\nstrings. It considers that each codepoint will occupy one position on the\nterminal in case of monowidth font (some east asians wide and fullwidth\ncharacters (see http://www.unicode.org/reports/tr11/tr11-33.html) will occupy\n2 positions). This logic is very simple and covers wide range of cases. But\nobviously there a lot of cases when it is not sufficient. In such cases user\nshould use some external libraries and provide an appropriate function to\n`libfort` via `ft_set_u8strwid_func` function.\n\n## Supported platforms and compilers\n\nThe following compilers are currently used in continuous integration at [Travis](https://travis-ci.org/seleznevae/libfort), [AppVeyor](https://ci.appveyor.com/project/seleznevae/libfort) and [Cirrus](https://cirrus-ci.com/github/seleznevae/libfort):\n\n| Compiler           | Operating System             |\n|--------------------|------------------------------|\n| GCC 5.5.0          | Ubuntu 16.04.11              |\n| GCC 4.9.4          | Ubuntu 16.04.11              |\n| GCC 5.5.0          | Ubuntu 16.04.11              |\n| GCC 6.5.0          | Ubuntu 16.04.11              |\n| GCC 7.5.0          | Ubuntu 16.04.11              |\n| GCC 8.4.0          | Ubuntu 16.04.11              |\n| GCC 9.3.0          | Ubuntu 16.04.11              |\n| Clang 5.0.0        | Ubuntu 16.04.11              |\n| AppleClang 7.3.0   | Darwin Kernel Version 15.6.0 |\n| AppleClang 8.1.0   | Darwin Kernel Version 16.7.0 |\n| AppleClang 9.1.0   | Darwin Kernel Version 17.4.0 |\n| Clang 8.0.1        | FreeBSD 12.1                 |\n| Clang 11.0.1       | FreeBSD 13.0                 |\n| Visual Studio 2017 | Windows Server 2016          |\n\n\nPlease note:\n- In case of clang on OS X before using **libfort** with ```wchar_t``` with real unicode symbols it may be necessary to set ```setlocale(LC_CTYPE, \"\");``` because otherwise standard function ```swprintf```, that libfort uses internally, may fail and ```ft_to_string``` will return error.\n\n\n## Contributing to libfort\n\nSee the [contribution guidelines](https://github.com/seleznevae/libfort/blob/develop/CONTRIBUTING.md) for more information.\n\n\n## License\n\n\u003cimg align=\"right\" src=\"http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png\"\u003e\n\nThe class is licensed under the [MIT License](http://opensource.org/licenses/MIT):\n\nCopyright \u0026copy; 2017 - 2020 Seleznev Anton\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseleznevae%2Flibfort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseleznevae%2Flibfort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseleznevae%2Flibfort/lists"}