{"id":24107628,"url":"https://github.com/bclehmann/ascii-table","last_synced_at":"2026-05-10T12:33:20.096Z","repository":{"id":157579752,"uuid":"345007414","full_name":"bclehmann/ascii-table","owner":"bclehmann","description":"A C++14 library for creating text-based tables.","archived":false,"fork":false,"pushed_at":"2021-03-07T09:25:33.000Z","size":32,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-10T22:42:13.616Z","etag":null,"topics":[],"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/bclehmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2021-03-06T04:46:37.000Z","updated_at":"2024-12-10T08:07:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"1a3dc582-48d1-40f7-81e5-f63dd562a488","html_url":"https://github.com/bclehmann/ascii-table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bclehmann%2Fascii-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bclehmann%2Fascii-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bclehmann%2Fascii-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bclehmann%2Fascii-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bclehmann","download_url":"https://codeload.github.com/bclehmann/ascii-table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241089059,"owners_count":19907677,"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":[],"created_at":"2025-01-10T22:39:50.944Z","updated_at":"2026-05-10T12:33:20.052Z","avatar_url":"https://github.com/bclehmann.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ascii-table\n\nA simple C++ 14 library to create text-based tables. Supports rows made of `std::string` as well as an interface to create your own row types.\n\n# Basics\n\n```cpp\nascii_table::ColumnInfo col1(20); // Minimum width of 20\nascii_table::ColumnInfo col2(20, ascii_table::alignment::right);\nascii_table::ColumnInfo col3(0, ascii_table::alignment::center);\nstd::vector\u003cascii_table::ColumnInfo\u003e colspec = {col1, col2, col3};\n\nascii_table::Table table(colspec);\ntable.first_row_header(true); // Turns on table header\ntable.add_row(ascii_table::StringRow({\"Column 1\", \"Column 2\", \"Column 3\"}));\ntable.add_row(ascii_table::StringRow({\"Ben\", \"Steve\", \"Bob\"}));\ntable.add_row(ascii_table::StringRow({\"Benjamin\", \"Stephen\", \"Robert\"}));\ntable.add_row(ascii_table::StringRow({\"Benjamin Smith\", \"Stephen Smith\", \"Robert Smith\"}));\ntable.add_row(ascii_table::StringRow({\"Benjamin Smithson\", \"Stephen Smithson\", \"Robert Smithson\"}));\n\nstd::cout \u003c\u003c table.get_table();\n```\n\nCreates this table:\n\n```\n+----------------------+----------------------+-----------------+\n| Column 1             | Column 2             | Column 3        |\n+----------------------+----------------------+-----------------+\n+----------------------+----------------------+-----------------+\n| Ben                  |                Steve |       Bob       |\n+----------------------+----------------------+-----------------+\n| Benjamin             |              Stephen |     Robert      |\n+----------------------+----------------------+-----------------+\n| Benjamin Smith       |        Stephen Smith |  Robert Smith   |\n+----------------------+----------------------+-----------------+\n| Benjamin Smithson    |     Stephen Smithson | Robert Smithson |\n+----------------------+----------------------+-----------------+\n```\n\n# Linking and Compilation\n\nThe `CMakeLists.txt` here [tests/CMakeLists.txt](https://github.com/bclehmann/ascii-table/blob/master/tests/CMakeLists.txt) should help anyone trying to link this with their own project.\n\nThis library was compiled with GCC with the C++ 14 standard, however it should build on any compiler with C++ 14 support. Compilation was done with this CMake file [src/CMakeLists.txt](https://github.com/bclehmann/ascii-table/blob/master/src/CMakeLists.txt)\n\n# Creating your own row class\n\nHere is the code for `StringRow`, note it is just a resource handle for `StringRowBase` which sets `handle` to an `std::shared_ptr\u003cStringRowBase\u003e`.\n```cpp\nclass StringRow : public Row {\npublic:\n\tStringRow() {\n\t\thandle = std::make_shared\u003cStringRowBase\u003e();\n\t}\n\n\texplicit StringRow(std::vector\u003cstd::string\u003e items)\n\t: StringRow()\n\t{\n\t\tdynamic_cast\u003cStringRowBase*\u003e(handle.get())-\u003eitems = items;\n\t}\n};\n```\n\n`handle` is a protected field that the base class `Row` uses internally. This is necessary because `std::vector` cannot hold abstract types, only pointers to them (or concrete wrapper classes). `StringRowBase` also adds a constructor for initializing the `items` field of `StringRowBase`, but this a convenience not a necessity.\n\n\nIf one looks at `StringRowBase` it's pretty compact:\n\n```cpp\nclass StringRowBase : public RowBase {\npublic:\n\tStringRowBase() = default;\n\texplicit StringRowBase(std::vector\u003cstd::string\u003e items)\n\t: items(std::move(items))\n\t{\n\n\t}\n\tstd::string get_item(int i) override{\n\t\treturn items[i];\n\t}\n\tsize_t size() override{\n\t\treturn items.size();\n\t}\n\tstd::vector\u003cstd::string\u003e items;\n};\n```\n\nAs you can see, this class merely provides a method `get_item` to provide the string output of a column and `size()` to provide the number of items in the row.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbclehmann%2Fascii-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbclehmann%2Fascii-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbclehmann%2Fascii-table/lists"}