{"id":13413942,"url":"https://github.com/bndr/gotabulate","last_synced_at":"2025-03-14T20:30:51.044Z","repository":{"id":19912914,"uuid":"23178566","full_name":"bndr/gotabulate","owner":"bndr","description":"Gotabulate - Easily pretty-print your tabular data with Go","archived":false,"fork":false,"pushed_at":"2021-02-09T14:02:15.000Z","size":44,"stargazers_count":333,"open_issues_count":5,"forks_count":31,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-25T05:25:14.015Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bndr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-21T07:44:28.000Z","updated_at":"2024-10-08T09:28:45.000Z","dependencies_parsed_at":"2022-07-23T14:17:39.091Z","dependency_job_id":null,"html_url":"https://github.com/bndr/gotabulate","commit_stats":null,"previous_names":["bndr/go-tabulate"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgotabulate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgotabulate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgotabulate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgotabulate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bndr","download_url":"https://codeload.github.com/bndr/gotabulate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243642012,"owners_count":20323949,"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":"2024-07-30T20:01:53.288Z","updated_at":"2025-03-14T20:30:50.632Z","avatar_url":"https://github.com/bndr.png","language":"Go","readme":"# Gotabulate - Easily pretty-print tabular data\n[![GoDoc](https://godoc.org/github.com/bndr/gotabulate?status.svg)](https://godoc.org/github.com/bndr/gotabulate)\n[![Build Status](https://travis-ci.org/bndr/gotabulate.svg?branch=master)](https://travis-ci.org/bndr/gotabulate)\n\n## Summary\n\nGo-Tabulate - Generic Go Library for easy pretty-printing of tabular data. \n\n## Installation\n\n    go get github.com/bndr/gotabulate\n\n## Description\n\nSupported data types:\n- 2D Array of `Int`, `Int64`, `Float64`, `String`, `interface{}`\n- Map of `String`, `interface{}` (Keys will be used as header)\n\n## Usage\n\n```go\n// Create Some Fake Rows\nrow_1 := []interface{}{\"john\", 20, \"ready\"}\nrow_2 := []interface{}{\"bndr\", 23, \"ready\"}\n\n// Create an object from 2D interface array\nt := gotabulate.Create([][]interface{}{row_1, row_2})\n\n// Set the Headers (optional)\nt.SetHeaders([]string{\"age\", \"status\"})\n\n// Set the Empty String (optional)\nt.SetEmptyString(\"None\")\n\n// Set Align (Optional)\nt.SetAlign(\"right\")\n\n// Print the result: grid, or simple\nfmt.Println(t.Render(\"grid\"))\n\n+---------+--------+-----------+\n|         |    age |    status |\n+=========+========+===========+\n|    john |     20 |     ready |\n+---------+--------+-----------+\n|    bndr |     23 |     ready |\n+---------+--------+-----------+\n```\n\n## Example with String\n\n```go\n// Some Strings\nstring_1 := []string{\"TV\", \"1000$\", \"Sold\"}\nstring_2 := []string{\"PC\", \"50%\", \"on Hold\"}\n\n// Create Object\ntabulate := gotabulate.Create([][]string{string_1, string_2})\n\n// Set Headers\ntabulate.SetHeaders([]string{\"Type\", \"Cost\", \"Status\"})\n\n// Render\nfmt.Println(tabulate.Render(\"simple\"))\n\n---------  ----------  ------------\n    Type        Cost        Status\n---------  ----------  ------------\n      TV       1000$          Sold\n\n      PC         50%       on Hold\n---------  ----------  ------------\n```\n\n## Example with String Wrapping\n\n```go\ntabulate := gotabulate.Create([][]string{[]string{\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\",\n\t\"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\", \"zzLorem ipsum\", \" test\", \"test\"}, []string{\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\",\n\t\"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\", \"zzLorem ipsum\", \" test\", \"test\"}, STRING_ARRAY, []string{\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\",\n\t\"Vivamus laoreet vestibulum pretium. Nulla et ornare elit. Cum sociis natoque penatibus et magnis\", \"zzLorem ipsum\", \" test\", \"test\"}, STRING_ARRAY})\n\ntabulate.SetHeaders([]string{\"Header 1\", \"header 2\", \"header 3\", \"header 4\"})\n// Set Max Cell Size\ntabulate.SetMaxCellSize(16)\n\n// Turn On String Wrapping\ntabulate.SetWrapStrings(true)\n\n// Render the table\nfmt.Println(tabulate.Render(\"grid\"))\n\n+---------------------+---------------------+----------------+-------------+-------------+\n|                     |            Header 1 |       header 2 |    header 3 |    header 4 |\n+=====================+=====================+================+=============+=============+\n|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |\n|    r sit amet, cons |    vestibulum preti |                |             |             |\n|    ectetur adipisci |    um. Nulla et orn |                |             |             |\n|    ng elit. Vivamus |    are elit. Cum so |                |             |             |\n|     laoreet vestibu |    ciis natoque pen |                |             |             |\n|    lum pretium. Nul |    atibus et magnis |                |             |             |\n|    la et ornare eli |                     |                |             |             |\n|    t. Cum sociis na |                     |                |             |             |\n|    toque penatibus  |                     |                |             |             |\n|           et magnis |                     |                |             |             |\n+---------------------+---------------------+----------------+-------------+-------------+\n|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |\n|    r sit amet, cons |    vestibulum preti |                |             |             |\n|    ectetur adipisci |    um. Nulla et orn |                |             |             |\n|    ng elit. Vivamus |    are elit. Cum so |                |             |             |\n|     laoreet vestibu |    ciis natoque pen |                |             |             |\n|    lum pretium. Nul |    atibus et magnis |                |             |             |\n|    la et ornare eli |                     |                |             |             |\n|    t. Cum sociis na |                     |                |             |             |\n|    toque penatibus  |                     |                |             |             |\n|           et magnis |                     |                |             |             |\n+---------------------+---------------------+----------------+-------------+-------------+\n|         test string |       test string 2 |           test |         row |        bndr |\n+---------------------+---------------------+----------------+-------------+-------------+\n|    Lorem ipsum dolo |    Vivamus laoreet  |    Lorem ipsum |        test |        test |\n|    r sit amet, cons |    vestibulum preti |                |             |             |\n|    ectetur adipisci |    um. Nulla et orn |                |             |             |\n|    ng elit. Vivamus |    are elit. Cum so |                |             |             |\n|     laoreet vestibu |    ciis natoque pen |                |             |             |\n|    lum pretium. Nul |    atibus et magnis |                |             |             |\n|    la et ornare eli |                     |                |             |             |\n|    t. Cum sociis na |                     |                |             |             |\n|    toque penatibus  |                     |                |             |             |\n|           et magnis |                     |                |             |             |\n+---------------------+---------------------+----------------+-------------+-------------+\n|         test string |       test string 2 |           test |         row |        bndr |\n+---------------------+---------------------+----------------+-------------+-------------+\n```\n## Examples\n\n```go\nt := gotabulate.Create([][]string{STRING_ARRAY, STRING_ARRAY})\n\nt.SetHeaders(HEADERS) // If not headers are set, the first row will be used.\n\nt.SetEmptyString(\"None\") // Set what will be printed in the empty cell\n\nrendered_string := t.Render(\"simple\") // Render() will return a string\n\nSimple Table\n----------------------  ----------------------  ----------------------  -------------  -------------\n             Header 1                Header 2                Header 3       Header 4       Header 5 \n----------------------  ----------------------  ----------------------  -------------  -------------\n          test string           test string 2                    test            row           bndr \n\n          test string           test string 2                    test            row           bndr \n\n    4th element empty       4th element empty       4th element empty           None           None \n----------------------  ----------------------  ----------------------  -------------  -------------\n\nGrid Table (Align Right)\n+-------------+-------------+-------------+-------------+-------------+\n|    Header 1 |    Header 2 |    Header 3 |    Header 4 |    Header 5 |\n+=============+=============+=============+=============+=============+\n|       10.01 |      12.002 |      -123.5 |    20.00005 |        1.01 |\n+-------------+-------------+-------------+-------------+-------------+\n|       10.01 |      12.002 |      -123.5 |    20.00005 |        1.01 |\n+-------------+-------------+-------------+-------------+-------------+\n|       10.01 |      12.002 |      -123.5 |    20.00005 |        None |\n+-------------+-------------+-------------+-------------+-------------+\n\nPadded Headers:\n+----------------------+----------------------+----------------------+-------------+-------------+\n|                      |             Header 1 |             header 2 |    header 3 |    header 4 |\n+======================+======================+======================+=============+=============+\n|          test string |        test string 2 |                 test |         row |        bndr |\n+----------------------+----------------------+----------------------+-------------+-------------+\n|          test string |        test string 2 |                 test |         row |        bndr |\n+----------------------+----------------------+----------------------+-------------+-------------+\n|    4th element empty |    4th element empty |    4th element empty |        None |        None |\n+----------------------+----------------------+----------------------+-------------+-------------+\n\nAlign Center:\n+-------------+-------------+-------------+-------------+-------------+\n|   Header 1  |   Header 2  |   Header 3  |   Header 4  |   Header 5  |\n+=============+=============+=============+=============+=============+\n|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |\n+-------------+-------------+-------------+-------------+-------------+\n|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |\n+-------------+-------------+-------------+-------------+-------------+\n|    10.01    |    12.002   |    -123.5   |   20.00005  |     1.01    |\n+-------------+-------------+-------------+-------------+-------------+\n\nAlign Left:\n+-------------+-------------+-------------+-------------+-------------+\n| Header 1    | Header 2    | Header 3    | Header 4    | Header 5    |\n+=============+=============+=============+=============+=============+\n| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |\n+-------------+-------------+-------------+-------------+-------------+\n| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |\n+-------------+-------------+-------------+-------------+-------------+\n| 10.01       | 12.002      | -123.5      | 20.00005    | 1.01        |\n+-------------+-------------+-------------+-------------+-------------+\n```\n\n### Status\n\nBeta version. There may be edge cases that I have missed, so if your tables don't render properly please open up an issue. \n\n## Contribute\n\nAll Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.\n\n## License\n\nApache License 2.0\n\n## TODO\n\n- [ ] Add more examples\n- [ ] Better Documentation\n- [ ] Implement more data table formats\n- [ ] Decimal point alignment for floats\n\n## Acknowledgement\n\nInspired by Python package [tabulate](https://pypi.python.org/pypi/tabulate)\n","funding_links":[],"categories":["Text Processing","Misc","Template Engines","文本处理","文本处理`解析和操作文本的代码库`","Bot Building","Utility","\u003cspan id=\"文字处理-text-processing\"\u003e文字处理 Text Processing\u003c/span\u003e"],"sub_categories":["HTTP Clients","Formatters","格式器","格式化工具","Advanced Console UIs","查询语","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgotabulate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbndr%2Fgotabulate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgotabulate/lists"}