{"id":13486110,"url":"https://github.com/rebus-org/Tababular","last_synced_at":"2025-03-27T20:32:10.279Z","repository":{"id":37851150,"uuid":"52158012","full_name":"rebus-org/Tababular","owner":"rebus-org","description":":page_with_curl: Simple monospace text table formatting","archived":false,"fork":false,"pushed_at":"2024-08-21T08:58:09.000Z","size":23421,"stargazers_count":88,"open_issues_count":2,"forks_count":16,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-21T13:58:11.134Z","etag":null,"topics":["cli","console","monospace"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rebus-org.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2016-02-20T14:45:08.000Z","updated_at":"2024-08-21T08:57:47.000Z","dependencies_parsed_at":"2024-08-21T10:20:37.439Z","dependency_job_id":null,"html_url":"https://github.com/rebus-org/Tababular","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FTababular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FTababular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FTababular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FTababular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rebus-org","download_url":"https://codeload.github.com/rebus-org/Tababular/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222313668,"owners_count":16965352,"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":["cli","console","monospace"],"created_at":"2024-07-31T18:00:39.775Z","updated_at":"2024-10-30T21:30:53.563Z","avatar_url":"https://github.com/rebus-org.png","language":"C#","readme":"# Tababular\r\n\r\nA simple .NET monospace text table formatting library for .NET 4.5 and .NET Standard 1.6.\r\n\r\nYou can use it if you are standing with a bunch of objects or dictionaries in your hand, and you\r\nwish for them to become as nice as this:\r\n\r\n\t+-------------+--------------+-------------+\r\n\t| FirstColumn | SecondColumn | ThirdColumn |\r\n\t+-------------+--------------+-------------+\r\n\t| r1          | hej          | hej igen    |\r\n\t+-------------+--------------+-------------+\r\n\t| r2          | hej          | hej igen    |\r\n\t+-------------+--------------+-------------+\r\n\r\nThis can easily be achieved by newing up the `TableFormatter` like this:\r\n\r\n\tvar formatter = new TableFormatter();\r\n\r\nand then you call an appropriate `Format***` method on it, e.g. `FormatObjects`:\r\n\r\n\tvar objects = new[]\r\n\t{\r\n\t\tnew {FirstColumn = \"r1\", SecondColumn = \"hej\", ThirdColumn = \"hej igen\"},\r\n\t\tnew {FirstColumn = \"r2\", SecondColumn = \"hej\", ThirdColumn = \"hej igen\"},\r\n\t};\r\n\r\n\tvar text = tableFormatter.FormatObjects(objects);\r\n\r\n\tConsole.WriteLine(text);\r\n\r\nwhich will result in the table shown above.\r\n\r\nFor now, Tababular does not support that much stuff - but one nice thing about it is that\r\nit will properly format lines in cells, so that e.g.\r\n\r\n\tvar objects = new[]\r\n\t{\r\n\t\tnew  { MachineName = \"ctxtest01\", Ip = \"10.0.0.10\", Ports = new[] {80, 8080, 9090}},\r\n\t\tnew  { MachineName = \"ctxtest02\", Ip = \"10.0.0.11\", Ports = new[] {80, 5432}}\r\n\t};\r\n\r\n\tvar text = new TableFormatter().FormatObjects(objects);\r\n\r\n\tConsole.WriteLine(text);\r\n\r\nbecomes nice like this:\r\n\r\n\t+-----------+-------------+-------+\r\n\t| Ip        | MachineName | Ports |\r\n\t+-----------+-------------+-------+\r\n\t| 10.0.0.10 | ctxtest01   | 80    |\r\n\t|           |             | 8080  |\r\n\t|           |             | 9090  |\r\n\t+-----------+-------------+-------+\r\n\t| 10.0.0.11 | ctxtest02   | 80    |\r\n\t|           |             | 5432  |\r\n\t+-----------+-------------+-------+\r\n\r\nwhich looks pretty neat if you ask me.\r\n\r\n# Formatting different things\r\n\r\nTababular can format different things, which at the moment includes:\r\n\r\n* Objects: `formatter.FormatObjects(objects)`\r\n* Dictionaries: `formatter.FormatDictionaries(dictionaries)`\r\n* JSON: `formatter.FormatJson(jsonText)`\r\n\r\n# More niceness\r\n\r\nWhat about longs texts? Consider this example where the \"Comments\" column can be used to supply arbitrarily long texts:\r\n\r\n\tvar objects = new[]\r\n\t{\r\n\t\tnew {MachineName = \"ctxtest01\", Ip = \"10.0.0.10\", Ports = new[] {80, 8080, 9090}, Comments = \"\"},\r\n\t\tnew {MachineName = \"ctxtest02\", Ip = \"10.0.0.11\", Ports = new[] {5432},\r\n\t\t\tComments = @\"This bad boy hosts our database and a couple of internal jobs.\"}\r\n\t};\r\n\r\n\tvar text = new TableFormatter().FormatObjects(objects);\r\n\r\nIn this case, the resulting table would look like this:\r\n\r\n\t+----------------------------------------------------------------+-----------+-------------+-------+\r\n\t| Comments                                                       | Ip        | MachineName | Ports |\r\n\t+----------------------------------------------------------------+-----------+-------------+-------+\r\n\t|                                                                | 10.0.0.10 | ctxtest01   | 80    |\r\n\t|                                                                |           |             | 8080  |\r\n\t|                                                                |           |             | 9090  |\r\n\t+----------------------------------------------------------------+-----------+-------------+-------+\r\n\t| This bad boy hosts our database and a couple of internal jobs. | 10.0.0.11 | ctxtest02   | 5432  |\r\n\t+----------------------------------------------------------------+-----------+-------------+-------+\r\n\r\nwhich might be fine, but since the texts can be even longer than this, it might end up being a problem.\r\n\r\nFear not! We can supply a small hint to the table formatter like this:\r\n\r\n\tvar hints = new Hints { MaxTableWidth = 80 };\r\n\tvar formatter = new TableFormatter(hints);\r\n\r\nand then when we\r\n\r\n\tvar text = formatter.FormatObjects(objects);\r\n\r\nit will look like this:\r\n\r\n\t+------------------------------------------------+-----------+-------------+-------+\r\n\t| Comments                                       | Ip        | MachineName | Ports |\r\n\t+------------------------------------------------+-----------+-------------+-------+\r\n\t|                                                | 10.0.0.10 | ctxtest01   | 80    |\r\n\t|                                                |           |             | 8080  |\r\n\t|                                                |           |             | 9090  |\r\n\t+------------------------------------------------+-----------+-------------+-------+\r\n\t| This bad boy hosts our database and a couple   | 10.0.0.11 | ctxtest02   | 5432  |\r\n\t| of internal jobs.                              |           |             |       |\r\n\t+------------------------------------------------+-----------+-------------+-------+\r\n\r\nand the table will never become wider than at most 80 characters. Objectively speaking, this is actually freaking awesome.\r\n\r\n# License\r\n\r\n[The MIT License (MIT)](http://opensource.org/licenses/MIT)","funding_links":[],"categories":["C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebus-org%2FTababular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebus-org%2FTababular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebus-org%2FTababular/lists"}