{"id":18008435,"url":"https://github.com/ozancansel/tableprinter","last_synced_at":"2025-03-26T12:32:08.948Z","repository":{"id":43743975,"uuid":"435241867","full_name":"OzanCansel/tableprinter","owner":"OzanCansel","description":"Allows a programmer to print table-like outputs over std::ostream.","archived":false,"fork":false,"pushed_at":"2023-11-16T20:36:17.000Z","size":1617,"stargazers_count":26,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T19:12:38.361Z","etag":null,"topics":["cpp","cpp17","format","header-only","iostream","library","print","table","variant"],"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/OzanCansel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-05T18:06:50.000Z","updated_at":"2023-11-27T13:15:44.000Z","dependencies_parsed_at":"2022-09-02T14:00:54.958Z","dependency_job_id":null,"html_url":"https://github.com/OzanCansel/tableprinter","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OzanCansel%2Ftableprinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OzanCansel%2Ftableprinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OzanCansel%2Ftableprinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OzanCansel%2Ftableprinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OzanCansel","download_url":"https://codeload.github.com/OzanCansel/tableprinter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245654339,"owners_count":20650850,"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":["cpp","cpp17","format","header-only","iostream","library","print","table","variant"],"created_at":"2024-10-30T01:18:44.094Z","updated_at":"2025-03-26T12:32:08.348Z","avatar_url":"https://github.com/OzanCansel.png","language":"C++","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"gif/showcase-1.gif\"/\u003e\n  \u003ca href=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-linux.yml\"\u003e\n    \u003cimg src=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-linux.yml/badge.svg\" alt=\"codacy\"/\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-windows.yml\"\u003e\n    \u003cimg src=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-windows.yml/badge.svg\" alt=\"codacy\"/\u003e\n  \u003c/a\u003e\n  \n  \u003ca href=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-macos.yml\"\u003e\n    \u003cimg src=\"https://github.com/OzanCansel/tableprinter/actions/workflows/cmake-macos.yml/badge.svg\" alt=\"codacy\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n# tableprinter\nAllows a programmer to print table-like outputs over `std::ostream`.\n\n- It is a header only library.\n\n- No other dependency than STL.\n\n- Provides required files for cmake to be used with `find_package( tableprinter )`\n\n- C++17 compliant compiler is needed to make it worked.\n\n- Tested only on Linux.\n\n## Why ?\n- Very convenient to read table-like formatted input from a file. An [example](https://github.com/OzanCansel/tableprinter/blob/master/example/read-scores.cpp).\n- Outputs look pretty (c)lean so easier to cognize.\n- Able to be parsed by linux tools such as [awk](https://www.gnu.org/software/gawk/) or similars. An [example](https://github.com/OzanCansel/tableprinter/blob/master/example/print-scores.cpp#L33-L38).\n\n## Example\n\n``` C++\n#include \u003ciostream\u003e\n#include \u003cfstream\u003e\n#include \u003ctableprinter/tableprinter.hpp\u003e\n\nint main()\n{\n    using namespace tableprinter;\n\n    std::ofstream scores_f { \"scores.txt\" };\n\n    printer p\n    {\n        {\n            { name { \"id\" }      , width { 4 }  } ,\n            { name { \"name\" }    , width { 10 } } ,\n            { name { \"surname\" } , width { 10 } } ,\n            { name { \"rank\" }    , width { 6 }  } ,\n            { name { \"score\" }   , width { 7 } , fixed { } , precision { 2 } }\n        } ,\n        { std::cout , scores_f }\n    };\n\n    p.sanity_check()\n     .echo( \"The scores are listed below with their ranks :\" )\n     .print_headers()\n     .print( 1 , \"Lucy\"   , \"Ballmer\"  , 2 , 94.13 )\n     .print( 2 , \"Roger\"  , \"Bacon\"    , 5 , 77.13 )\n     .print( 3 , \"Anna\"   , \"Smith\"    , 3 , 87.13 )\n     .print( 4 , \"Robert\" , \"Schwartz\" , 1 , 98.34 )\n     .print( 5 , \"Robert\" , \"Brown\"    , 4 , 84.34 )\n     .print( std::make_tuple( 6 , \"David\" , \"Timothy\" , 6 , 71.34 ) );\n\n    /*\n       # Run the command if you want to see maximum score\n       ./print-scores | tail -n 5 | awk '{ printf \"%d %d %s %s %f\\n\" , $4 , $1 , $2 , $3 , $5 }' | sort | head -n 1 | awk '{ print $5 }'\n       # or lowest score\n       ./print-scores | tail -n 5 | awk '{ printf \"%d %d %s %s %f\\n\" , $4 , $1 , $2 , $3 , $5 }' | sort | tac | head -n 1 | awk '{ print $5 }'\n    */\n}\n```\n```console\nThe scores are listed below with their ranks :\n  id      name   surname  rank  score\n   1      Lucy   Ballmer     2  94.13\n   2     Roger     Bacon     5  77.13\n   3      Anna     Smith     3  87.13\n   4    Robert  Schwartz     1  98.34\n   5    Robert     Brown     4  84.34\n   6     David   Timothy     6  71.34\n```\n\n## How to use ?\n### Way 1. Install to the system\n- Install __tableprinter__ as system-wide.\n```bash\ncd $(mktemp -d)\ngit clone https://github.com/OzanCansel/tableprinter.git\ncd tableprinter\nmkdir build \u0026\u0026 cd build\ncmake ..\nsudo cmake --build . --target install -- -j$(nproc)\n```\n\n\n#### Way 1.1.\n- Include __tableprinter__ to your cmake project with `find_package( tableprinter )`\n``` cmake\ncmake_minimum_required( VERSION 3.10 )\nproject( my_project )\n\n# Allows you to use tableprinter\nfind_package( tableprinter REQUIRED )\n\nadd_executable( my_binary main.cpp )\n\ntarget_link_libraries( my_binary PRIVATE tableprinter::tableprinter )\n```\n\n#### Way 1.2.\n- It is not obliged to be included by a cmake project. tableprinter is header only so it will be visible after it is installed to the system. So just include it and make sure that you enabled C++17 standard.\n\n### Way 2. Add as a subdirectory\n- Add as an subdirectory to your existing cmake project.\n\n```bash\ncd already_existing_project\ngit clone https://github.com/OzanCansel/tableprinter.git\n```\n``` cmake\ncmake_minimum_required( VERSION 3.10 )\nproject( already_existing_project )\n\n# Allows you to use tableprinter\nadd_subdirectory( tableprinter EXCLUDE_FROM_ALL )\n\nadd_executable( my_binary main.cpp )\n\ntarget_link_libraries( my_binary PRIVATE tableprinter::tableprinter )\n```\n\n#### Way 3.\nJust download `tableprinter.hpp` and include it.\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://raw.githubusercontent.com/OzanCansel/tableprinter/master/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozancansel%2Ftableprinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fozancansel%2Ftableprinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fozancansel%2Ftableprinter/lists"}