{"id":13621503,"url":"https://github.com/nukesor/comfy-table","last_synced_at":"2025-05-14T08:07:26.470Z","repository":{"id":38003040,"uuid":"230310173","full_name":"Nukesor/comfy-table","owner":"Nukesor","description":":large_orange_diamond: Build beautiful terminal tables with automatic content wrapping","archived":false,"fork":false,"pushed_at":"2025-04-07T12:23:16.000Z","size":606,"stargazers_count":1117,"open_issues_count":2,"forks_count":35,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-09T15:43:47.549Z","etag":null,"topics":["commandline","commandline-interface","hacktoberfest","styling","table","terminal"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/Nukesor.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-26T18:29:21.000Z","updated_at":"2025-05-09T15:06:02.000Z","dependencies_parsed_at":"2024-02-01T16:25:45.650Z","dependency_job_id":"c607e4f8-519a-46ba-b49f-05b26db69ee1","html_url":"https://github.com/Nukesor/comfy-table","commit_stats":{"total_commits":367,"total_committers":15,"mean_commits":"24.466666666666665","dds":0.114441416893733,"last_synced_commit":"3fe54c66a3498cb511776ca9f8d31aa2b1a81578"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nukesor%2Fcomfy-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nukesor%2Fcomfy-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nukesor%2Fcomfy-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nukesor%2Fcomfy-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nukesor","download_url":"https://codeload.github.com/Nukesor/comfy-table/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101556,"owners_count":22014908,"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":["commandline","commandline-interface","hacktoberfest","styling","table","terminal"],"created_at":"2024-08-01T21:01:07.166Z","updated_at":"2025-05-14T08:07:21.456Z","avatar_url":"https://github.com/Nukesor.png","language":"Rust","readme":"# Comfy-table\n\n[![GitHub Actions Workflow](https://github.com/Nukesor/comfy-table/actions/workflows/test.yml/badge.svg)](https://github.com/Nukesor/comfy-table/actions/workflows/test.yml)\n[![docs](https://docs.rs/comfy-table/badge.svg)](https://docs.rs/comfy-table/)\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nukesor/comfy-table/blob/main/LICENSE)\n[![Crates.io](https://img.shields.io/crates/v/comfy-table.svg)](https://crates.io/crates/comfy-table)\n[![codecov](https://codecov.io/gh/nukesor/comfy-table/branch/main/graph/badge.svg)](https://codecov.io/gh/nukesor/comfy-table)\n\n![comfy-table](https://raw.githubusercontent.com/Nukesor/images/main/comfy_table.gif)\n\n\u003c!--- [![dependency status](https://deps.rs/repo/github/nukesor/comfy-table/status.svg)](https://deps.rs/repo/github/nukesor/comfy-table) --\u003e\n\nComfy-table is designed as a library for building beautiful terminal tables, while being easy to use.\n\n## Table of Contents\n\n- [Features](#features)\n- [Examples](#examples)\n- [Feature Flags](#feature-flags)\n- [Contributing](#contributing)\n- [Usage of unsafe](#unsafe)\n- [Comparison with other libraries](#comparison-with-other-libraries)\n\n## Features\n\n- Dynamic arrangement of content depending on a given width.\n- ANSI content styling for terminals (Colors, Bold, Blinking, etc.).\n- Styling Presets and preset modifiers to get you started.\n- Pretty much every part of the table is customizable (borders, lines, padding, alignment).\n- Constraints on columns that allow some additional control over how to arrange content.\n- Cross plattform (Linux, macOS, Windows).\n- It's fast enough.\n  - Benchmarks show that a pretty big table with complex constraints is build in `470μs` or `~0.5ms`.\n  - The table seen at the top of the readme takes `~30μs`.\n  - These numbers are from a overclocked `i7-8700K` with a max single-core performance of 4.9GHz.\n  - To run the benchmarks yourselves, install criterion via `cargo install cargo-criterion` and run `cargo criterion` afterwards.\n\nComfy-table is written for the current `stable` Rust version.\nOlder Rust versions may work but aren't officially supported.\n\n## Examples\n\n```rust\nuse comfy_table::Table;\n\nfn main() {\n    let mut table = Table::new();\n    table\n        .set_header(vec![\"Header1\", \"Header2\", \"Header3\"])\n        .add_row(vec![\n            \"This is a text\",\n            \"This is another text\",\n            \"This is the third text\",\n        ])\n        .add_row(vec![\n            \"This is another text\",\n            \"Now\\nadd some\\nmulti line stuff\",\n            \"This is awesome\",\n        ]);\n\n    println!(\"{table}\");\n}\n```\n\nCreate a very basic table.\\\nThis table will become as wide as your content. Nothing fancy happening here.\n\n```text,ignore\n+----------------------+----------------------+------------------------+\n| Header1              | Header2              | Header3                |\n+======================================================================+\n| This is a text       | This is another text | This is the third text |\n|----------------------+----------------------+------------------------|\n| This is another text | Now                  | This is awesome        |\n|                      | add some             |                        |\n|                      | multi line stuff     |                        |\n+----------------------+----------------------+------------------------+\n```\n\n### More Features\n\n```rust\nuse comfy_table::modifiers::UTF8_ROUND_CORNERS;\nuse comfy_table::presets::UTF8_FULL;\nuse comfy_table::*;\n\nfn main() {\n    let mut table = Table::new();\n    table\n        .load_preset(UTF8_FULL)\n        .apply_modifier(UTF8_ROUND_CORNERS)\n        .set_content_arrangement(ContentArrangement::Dynamic)\n        .set_width(40)\n        .set_header(vec![\"Header1\", \"Header2\", \"Header3\"])\n        .add_row(vec![\n            Cell::new(\"Center aligned\").set_alignment(CellAlignment::Center),\n            Cell::new(\"This is another text\"),\n            Cell::new(\"This is the third text\"),\n        ])\n        .add_row(vec![\n            \"This is another text\",\n            \"Now\\nadd some\\nmulti line stuff\",\n            \"This is awesome\",\n        ]);\n\n    // Set the default alignment for the third column to right\n    let column = table.column_mut(2).expect(\"Our table has three columns\");\n    column.set_cell_alignment(CellAlignment::Right);\n\n    println!(\"{table}\");\n}\n```\n\nCreate a table with UTF8 styling, and apply a modifier that gives the table round corners.\\\nAdditionally, the content will dynamically wrap to maintain a given table width.\\\nIf the table width isn't explicitely set and the program runs in a terminal, the terminal size will be used.\n\nOn top of this, we set the default alignment for the right column to `Right` and the alignment of the left top cell to `Center`.\n\n```text,ignore\n╭────────────┬────────────┬────────────╮\n│ Header1    ┆ Header2    ┆    Header3 │\n╞════════════╪════════════╪════════════╡\n│  This is a ┆ This is    ┆    This is │\n│    text    ┆ another    ┆  the third │\n│            ┆ text       ┆       text │\n├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤\n│ This is    ┆ Now        ┆    This is │\n│ another    ┆ add some   ┆    awesome │\n│ text       ┆ multi line ┆            │\n│            ┆ stuff      ┆            │\n╰────────────┴────────────┴────────────╯\n```\n\n### Styling\n\n```rust\nuse comfy_table::presets::UTF8_FULL;\nuse comfy_table::*;\n\nfn main() {\n    let mut table = Table::new();\n    table.load_preset(UTF8_FULL)\n        .set_content_arrangement(ContentArrangement::Dynamic)\n        .set_width(80)\n        .set_header(vec![\n            Cell::new(\"Header1\").add_attribute(Attribute::Bold),\n            Cell::new(\"Header2\").fg(Color::Green),\n            Cell::new(\"Header3\"),\n        ])\n        .add_row(vec![\n             Cell::new(\"This is a bold text\").add_attribute(Attribute::Bold),\n             Cell::new(\"This is a green text\").fg(Color::Green),\n             Cell::new(\"This one has black background\").bg(Color::Black),\n        ])\n        .add_row(vec![\n            Cell::new(\"Blinky boi\").add_attribute(Attribute::SlowBlink),\n            Cell::new(\"This table's content is dynamically arranged. The table is exactly 80 characters wide.\\nHere comes a reallylongwordthatshoulddynamicallywrap\"),\n            Cell::new(\"COMBINE ALL THE THINGS\")\n                .fg(Color::Green)\n                .bg(Color::Black)\n                .add_attributes(vec![\n                    Attribute::Bold,\n                    Attribute::SlowBlink,\n                ])\n        ]);\n\n    println!(\"{table}\");\n}\n```\n\nThis code generates the table that can be seen at the top of this document.\n\n### Code Examples\n\nA few examples can be found in the `example` folder.\nTo test an example, run `cargo run --example $name`. E.g.:\n\n```bash\ncargo run --example readme_table\n```\n\nIf you're looking for more information, take a look at the [tests folder](https://github.com/Nukesor/comfy-table/tree/main/tests).\nThere are tests for almost every feature including a visual view for each resulting table.\n\n## Feature Flags\n\n### `tty` (enabled)\n\nThis flag enables support for terminals. In detail this means:\n\n- Automatic detection whether we're in a terminal environment.\n  Only used when no explicit `Table::set_width` is provided.\n- Support for ANSI Escape Code styling for terminals.\n\n### `custom_styling` (disabled)\n\nThis flag enables support for custom styling of text inside of cells.\n\n- Text formatting still works, even if you roll your own ANSI escape sequences.\n- Rainbow text\n- Makes comfy-table 30-50% slower\n\n### `reexport_crossterm` (disabled)\n\nWith this flag, comfy-table re-exposes crossterm's [`Attribute`](https://docs.rs/crossterm/latest/crossterm/style/enum.Attribute.html) and [`Color`](https://docs.rs/crossterm/latest/crossterm/style/enum.Color.html) enum.\nBy default, a mirrored type is exposed, which internally maps to the crossterm type.\n\nThis feature is very convenient if you use both comfy-table and crossterm in your code and want to use crossterm's types for everything interchangeably.\n\n**BUT** if you enable this feature, you opt-in for breaking changes on minor/patch versions.\nMeaning, you have to update crossterm whenever you update comfy-table and you **cannot** update crossterm until comfy-table released a new version with that crossterm version.\n\n## Contributing\n\nComfy-table's main focus is on being minimalistic and reliable.\nA fixed set of features that just work for \"normal\" use-cases:\n\n- Normal tables (columns, rows, one cell per column/row).\n- Dynamic arrangement of content to a given width.\n- Some kind of manual intervention in the arrangement process.\n\nIf you come up with an idea or an improvement that fits into the current scope of the project, feel free to create an issue :)!\n\nSome things however will most likely not be added to the project since they drastically increase the complexity of the library or cover very specific edge-cases.\n\nSuch features are:\n\n- Nested tables\n- Cells that span over multiple columns/rows\n- CSV to table conversion and vice versa\n\n## Unsafe\n\nComfy-table doesn't allow `unsafe` code in its code-base.\nAs it's a \"simple\" formatting library it also shouldn't be needed in the future.\n\nIf one disables the `tty` feature flag, this is also true for all of its dependencies.\n\nHowever, when enabling `tty`, Comfy-table uses one unsafe function call in its dependencies. \\\nIt can be circumvented by explicitely calling [Table::force_no_tty](https://docs.rs/comfy-table/latest/comfy_table/struct.Table.html#method.force_no_tty).\n\n1. `crossterm::terminal::size`. This function is necessary to detect the current terminal width if we're on a tty.\n   This is only called if no explicit width is provided via `Table::set_width`.\n\n   \u003chttp://rosettacode.org/wiki/Terminal_control/Dimensions#Library:_BSD_libc\u003e\n   This is another libc call which is used to communicate with `/dev/tty` via a file descriptor.\n\n   ```rust,ignore\n   ...\n   if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), \u0026mut size) }).is_ok() {\n       Ok((size.ws_col, size.ws_row))\n   } else {\n       tput_size().ok_or_else(|| std::io::Error::last_os_error().into())\n   }\n   ...\n   ```\n\n## Comparison with other libraries\n\nThe following are official statements of the other crate authors.\n[This ticket](https://github.com/Nukesor/comfy-table/issues/76) can be used as an entry to find all other sibling tickets in the other projects.\n\n### Cli-table\n\nThe main focus of [`cli-table`](https://crates.io/crates/cli-table) is to support all platforms and at the same time limit the dependencies to keep the compile times and crate size low.\n\nCurrently, this crate only pulls two external dependencies (other than cli-table-derive):\n\n- termcolor\n- unicode-width\n\nWith csv feature enabled, it also pulls csv crate as dependency.\n\n### Term-table\n\n[`term-table`](https://crates.io/crates/term-table) is pretty basic in terms of features.\nMy goal with the project is to provide a good set of tools for rendering CLI tables, while also allowing users to bring their own tools for things like colours.\nOne thing that is unique to `term-table` (as far as I'm aware) is the ability to have different number of columns in each row of the table.\n\n### Prettytables-rs\n\n[`prettytables-rs`](https://crates.io/crates/prettytable-rs) provides functionality for formatting and aligning tables.\nIt his however abandoned since over three years and a [rustsec/advisory-db](https://github.com/rustsec/advisory-db/issues/1173) entry has been requested.\n\n### Comfy-table\n\nOne of [`comfy-table`](https://crates.io/crates/comfy-table)'s big foci is on providing a minimalistic, but rock-solid library for building text-based tables.\nThis means that the code is very well tested, no usage of `unsafe` and `unwrap` is only used if we can be absolutely sure that it's safe.\nThere're only one occurrence of `unsafe` in all of comfy-table's dependencies, to be exact inside the `tty` communication code, which can be explicitly disabled.\n\nThe other focus is on dynamic-length content arrangement.\nThis means that a lot of work went into building an algorithm that finds a (near) optimal table layout for any given text and terminal width.\n","funding_links":[],"categories":["Libraries","库 Libraries"],"sub_categories":["Command-line","命令行 Command-line"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnukesor%2Fcomfy-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnukesor%2Fcomfy-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnukesor%2Fcomfy-table/lists"}