{"id":1339,"url":"https://github.com/scottrhoyt/SwiftyTextTable","last_synced_at":"2025-08-06T13:32:12.793Z","repository":{"id":43579908,"uuid":"51054966","full_name":"scottrhoyt/SwiftyTextTable","owner":"scottrhoyt","description":"A lightweight library for generating text tables.","archived":false,"fork":false,"pushed_at":"2023-02-25T21:18:37.000Z","size":377,"stargazers_count":318,"open_issues_count":8,"forks_count":30,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-29T20:35:01.473Z","etag":null,"topics":["carthage","cocoapods","command-line","linux","macos","swift","swift-package-manager","tabular-data"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/scottrhoyt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2016-02-04T05:42:16.000Z","updated_at":"2024-10-13T14:53:25.000Z","dependencies_parsed_at":"2023-12-07T00:34:08.170Z","dependency_job_id":null,"html_url":"https://github.com/scottrhoyt/SwiftyTextTable","commit_stats":{"total_commits":152,"total_committers":6,"mean_commits":"25.333333333333332","dds":0.5723684210526316,"last_synced_commit":"c6df6cf533d120716bff38f8ff9885e1ce2a4ac3"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrhoyt%2FSwiftyTextTable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrhoyt%2FSwiftyTextTable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrhoyt%2FSwiftyTextTable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrhoyt%2FSwiftyTextTable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scottrhoyt","download_url":"https://codeload.github.com/scottrhoyt/SwiftyTextTable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905450,"owners_count":17989770,"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":["carthage","cocoapods","command-line","linux","macos","swift","swift-package-manager","tabular-data"],"created_at":"2024-01-05T20:15:44.163Z","updated_at":"2024-12-09T14:30:46.478Z","avatar_url":"https://github.com/scottrhoyt.png","language":"Swift","readme":"# SwiftyTextTable\n\nA lightweight Swift library for generating text tables.\n\n[![Build Status](https://travis-ci.org/scottrhoyt/SwiftyTextTable.svg?branch=master)](https://travis-ci.org/scottrhoyt/SwiftyTextTable)\n[![codecov.io](https://codecov.io/github/scottrhoyt/SwiftyTextTable/coverage.svg?branch=master)](https://codecov.io/github/scottrhoyt/SwiftyTextTable?branch=master)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyTextTable.svg)]()\n![Platform OS X + Linux](https://img.shields.io/badge/Platform-OS%20X%20%2B%20Linux-blue.svg)\n[![Language Swift 4.0](https://img.shields.io/badge/Language-Swift%204.0-orange.svg)](https://swift.org)\n\n![Example](http://i.imgur.com/utoa6TK.png)\n\n## Swift Language Support\n\nSwiftyTextTable is now Swift 4.0 compatible! The last release to support Swift\n3.1 was [0.7.1](https://github.com/scottrhoyt/SwiftyTextTable/releases/tag/0.7.1).\nThe last release to support Swift 2.3 was [0.3.1](https://github.com/scottrhoyt/SwiftyTextTable/releases/tag/0.3.1).\n\n## Installation\n\n### Carthage (OS X)\nYou can use [Carthage](https://github.com/Carthage/Carthage) to install\nSwiftyTextTable by adding it to your `Cartfile`:\n\n```\ngithub \"scottrhoyt/SwiftyTextTable\"\n```\n\n### Swift Package Manager (OS X + Linux)\nYou can use [The Swift Package Manager](https://swift.org/package-manager) to\ninstall SwiftyTextTable by adding the proper description to your\n`Package.swift` file:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"\u003cYOUR_PROJECT_NAME\u003e\",\n    dependencies: [\n        .package(url: \"https://github.com/scottrhoyt/SwiftyTextTable.git\", from: \"0.5.0\")\n    ]\n)\n```\n\n### CocoaPods (OS X)\n\nYou can use [CocoaPods](https://cocoapods.org) to install SwiftyTextTable by\nadding it to your `Podfile`:\n\n```ruby\npod 'SwiftyTextTable'\n```\n\n### Manual\n\nSimply copy the `*.swift` files from the `Source/SwiftyTextTable` directory into\nyour project.\n\n## Usage\n\n```swift\nimport SwiftyTextTable\n\n// First create some columns\nlet foo = TextTableColumn(header: \"foo\")\nlet bar = TextTableColumn(header: \"bar\")\nlet baz = TextTableColumn(header: \"baz\")\n\n// Then create a table with the columns\nvar table = TextTable(columns: [foo, bar, baz])\n\n// Then add some rows\ntable.addRow([1, 2, 3])\ntable.addRow([11, 22, 33])\n\n// Then render the table and use\nlet tableString = table.render()\nprint(tableString)\n\n/*\n+-----+-----+-----+\n| foo | bar | baz |\n+-----+-----+-----+\n| 1   | 2   | 3   |\n| 11  | 22  | 33  |\n+-----+-----+-----+\n*/\n\n// Put a header on the table if you'd like\ntable.header = \"my foo table\"\nprint(table.render())\n\n/*\n+-----------------+\n| my foo table    |\n+-----------------+\n| foo | bar | baz |\n+-----+-----+-----+\n| 1   | 2   | 3   |\n| 11  | 22  | 33  |\n+-----+-----+-----+\n*/\n```\n\nAny `CustomStringConvertible` can be used for row `values`.\n\n### Creating Tables from Arrays of Objects with `TextTableRepresentable`\n\nLet's say you have an array of objects that looks this:\n\n```swift\nenum AnimalType: String, CustomStringConvertible {\n    case dog = \"Dog\"\n    case cat = \"Cat\"\n    case gorilla = \"Gorilla\"\n\n    var description: String {\n        return self.rawValue\n    }\n}\n\nstruct Pet {\n    let type: AnimalType\n    let name: String\n    let canHazPizza: Bool\n}\n\nlet furball = Pet(type: .cat, name: \"Furball\", canHazPizza: false)\nlet bestFriend = Pet(type: .dog, name: \"Best Friend\", canHazPizza: true)\nlet scary = Pet(type: .gorilla, name: \"Scary\", canHazPizza: true)\nlet pets = [furball, bestFriend, scary]\n```\n\nNow you want to print a table containing your `pets`. You can accomplish this\nby having `Pet` conform to `TextTableRepresentable`:\n\n```swift\nextension Pet: TextTableRepresentable {\n    static var columnHeaders: [String] {\n        return [\"Name\", \"Animal\", \"Can Haz Pizza?\"]\n    }\n\n    var tableValues: [CustomStringConvertible] {\n        return [name, type, canHazPizza ? \"yes\" : \"no\"]\n    }\n\n    // Optional\n    static var tableHeader: String? {\n      return \"My Pets\"\n    }\n}\n```\n\nYou can now print a table of your `pets` simply:\n\n```swift\nprint(pets.renderTextTable())\n\n/*\n+----------------------------------------+\n| My Pets                                |\n+----------------------------------------+\n| Name        | Animal  | Can Haz Pizza? |\n+-------------+---------+----------------+\n| Furball     | Cat     | no             |\n| Best Friend | Dog     | yes            |\n| Scary       | Gorilla | yes            |\n+-------------+---------+----------------+\n*/\n```\n\n### Fence Custimization\n\nYou can also customize the output of `TextTable.render()` by using different\nvalues for `columnFence`, `rowFence`, and `cornerFence`.\n\n```swift\ntable.columnFence = \":\"\ntable.rowFence = \".\"\ntable.cornerFence = \".\"\n\nprint(table.render())\n\n/*\n...................\n: foo : bar : baz :\n...................\n: 1   : 2   :     :\n: 11  : 22  : 33  :\n...................\n*/\n```\n\n### Row Padding/Truncation\n\nWhen adding rows, `TextTable` will automatically pad the rows with empty strings\nwhen there are fewer `values` than columns. `TextTable` will also disregard all\n`values` over the column count.\n\n```swift\nlet foo = TextTableColumn(header: \"foo\")\nlet bar = TextTableColumn(header: \"bar\")\nlet baz = TextTableColumn(header: \"baz\")\n\nvar table = TextTable(columns: [foo, bar, baz])\n\ntable.addRow([1, 2])\ntable.addRow([11, 22, 33])\ntable.addRow([111, 222, 333, 444])\n\nlet tableString = table.render()\nprint(tableString)\n\n/*\n+-----+-----+-----+\n| foo | bar | baz |\n+-----+-----+-----+\n| 1   | 2   |     |\n| 11  | 22  | 33  |\n| 111 | 222 | 333 |\n+-----+-----+-----+\n*/\n```\n\n### Console Formatting Support\n\nSwiftyTextTable will recognize many console escape sequences used to format\noutput (e.g. [Rainbow](https://github.com/onevcat/Rainbow)) and account for them\nin constructing the table.\n\n### API Reference\n\nCheck out the full API reference [here](http://scottrhoyt.github.io/SwiftyTextTable/).\n\n## License\n\nSwiftyTextTable is released under the [MIT License](https://github.com/scottrhoyt/SwiftyTextTable/blob/master/LICENSE).\n","funding_links":[],"categories":["Libs","Command Line","Logging","Swift","Command Line [🔝](#readme)"],"sub_categories":["Command Line","Linter","Other free courses","Other Hardware"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrhoyt%2FSwiftyTextTable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottrhoyt%2FSwiftyTextTable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrhoyt%2FSwiftyTextTable/lists"}