All Projects → Nukesor → Comfy Table

Nukesor / Comfy Table

Licence: mit
🔶 Build beautiful terminal tables with automatic content wrapping

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Comfy Table

Pxltrm
🖌️ pxltrm - [WIP] A pixel art editor inside the terminal
Stars: ✭ 459 (+194.23%)
Mutual labels:  commandline, commandline-interface, terminal
Socli
Stack overflow command line client. Search and browse stack overflow without leaving the terminal 💻
Stars: ✭ 911 (+483.97%)
Mutual labels:  commandline, commandline-interface, hacktoberfest
Clifx
Declarative framework for building command line interfaces
Stars: ✭ 900 (+476.92%)
Mutual labels:  terminal, hacktoberfest
Tabulate
Table Maker for Modern C++
Stars: ✭ 862 (+452.56%)
Mutual labels:  terminal, table
Gitviper
Enhanced git experience using the command line
Stars: ✭ 35 (-77.56%)
Mutual labels:  commandline, commandline-interface
Rich
Rich is a Python library for rich text and beautiful formatting in the terminal.
Stars: ✭ 31,664 (+20197.44%)
Mutual labels:  terminal, hacktoberfest
Bat
A cat(1) clone with wings.
Stars: ✭ 30,833 (+19664.74%)
Mutual labels:  terminal, hacktoberfest
Tldr
📚 Collaborative cheatsheets for console commands
Stars: ✭ 36,408 (+23238.46%)
Mutual labels:  terminal, hacktoberfest
Tio
tio - A simple TTY terminal I/O application
Stars: ✭ 489 (+213.46%)
Mutual labels:  commandline, terminal
Cordless
The Discord terminal client you never knew you wanted.
Stars: ✭ 1,391 (+791.67%)
Mutual labels:  commandline, terminal
Navi
An interactive cheatsheet tool for the command-line
Stars: ✭ 10,055 (+6345.51%)
Mutual labels:  terminal, hacktoberfest
Beautifultable
Python package for printing visually appealing tables on a terminal.
Stars: ✭ 110 (-29.49%)
Mutual labels:  terminal, table
Terminaltables
Generate simple tables in terminals from a nested list of strings.
Stars: ✭ 685 (+339.1%)
Mutual labels:  terminal, table
Ruby jard
Just Another Ruby Debugger. Provide a rich Terminal UI that visualizes everything your need, navigates your program with pleasure, stops at matter places only, reduces manual and mental efforts. You can now focus on real debugging.
Stars: ✭ 669 (+328.85%)
Mutual labels:  terminal, hacktoberfest
Rows
A common, beautiful interface to tabular data, no matter the format
Stars: ✭ 739 (+373.72%)
Mutual labels:  hacktoberfest, table
Imgcat
It's like cat, but for images.
Stars: ✭ 577 (+269.87%)
Mutual labels:  terminal, hacktoberfest
Progressbar
A really basic thread-safe progress bar for Golang applications
Stars: ✭ 2,212 (+1317.95%)
Mutual labels:  terminal, hacktoberfest
Bubbles
TUI components for Bubble Tea 🍡
Stars: ✭ 467 (+199.36%)
Mutual labels:  terminal, hacktoberfest
Blightmud
A terminal mud client written in Rust
Stars: ✭ 61 (-60.9%)
Mutual labels:  terminal, hacktoberfest
Manage
Command Line Manager + Interactive Shell for Python Projects
Stars: ✭ 111 (-28.85%)
Mutual labels:  commandline, commandline-interface

Comfy-table

GitHub Actions Workflow docs license Crates.io codecov

comfy-table

Comfy-table tries to provide utility for building beautiful tables, while being easy to use.

Features:

  • Dynamic arrangement of content to a specific width.
  • Content styling for terminals (Colors, Bold, Blinking, etc.).
  • Presets and preset modifiers to get you started.
  • Pretty much every part of the table is customizable (borders, lines, padding, alignment).
  • Constraints on columns that allow some additional control over how to arrange content.
  • Cross plattform (Linux, macOS, Windows).

Comfy-table is written for the current stable Rust version. Older Rust versions may work, but aren't officially supported.

Examples

use comfy_table::Table;

fn main() {
    let mut table = Table::new();
    table
        .set_header(vec!["Header1", "Header2", "Header3"])
        .add_row(vec![
                 "This is a text",
                 "This is another text",
                 "This is the third text",
        ])
        .add_row(vec![
                 "This is another text",
                 "Now\nadd some\nmulti line stuff",
                 "This is awesome",
        ]);

    println!("{}", table);
}

Create a very basic table.
This table will become as wide as your content, nothing fancy happening here.

+----------------------+----------------------+------------------------+
| Header1              | Header2              | Header3                |
+======================================================================+
| This is a text       | This is another text | This is the third text |
|----------------------+----------------------+------------------------|
| This is another text | Now                  | This is awesome        |
|                      | add some             |                        |
|                      | multi line stuff     |                        |
+----------------------+----------------------+------------------------+

More Features

use comfy_table::*;
use comfy_table::presets::UTF8_FULL;
use comfy_table::modifiers::UTF8_ROUND_CORNERS;

fn main() {
    let mut table = Table::new();
    table
        .load_preset(UTF8_FULL)
        .apply_modifier(UTF8_ROUND_CORNERS)
        .set_content_arrangement(ContentArrangement::Dynamic)
        .set_table_width(40)
        .set_header(vec!["Header1", "Header2", "Header3"])
        .add_row(vec![
                 Cell::new("Center aligned").set_alignment(CellAlignment::Center),
                 Cell::new("This is another text"),
                 Cell::new("This is the third text"),
        ])
        .add_row(vec![
                 "This is another text",
                 "Now\nadd some\nmulti line stuff",
                 "This is awesome",
        ]);

    // Set the default alignment for the third column to right
    let column = table.get_column_mut(2).expect("Our table has three columns");
    column.set_cell_alignment(CellAlignment::Right);

    println!("{}", table);
}

Create a table with UTF8 styling, and apply a modifier, which gives the table round corners.
Additionall the content will dynamically wrap to maintain a given table width.
If the table width isn't explicitely set, the terminal size will be used, if this is executed in a terminal.

On top of this, we set the default alignment for the right column to Right and the Alignment of the left top cell to Center.

╭────────────┬────────────┬────────────╮
│ Header1    ┆ Header2    ┆    Header3 │
╞════════════╪════════════╪════════════╡
│  This is a ┆ This is    ┆    This is │
│    text    ┆ another    ┆  the third │
│            ┆ text       ┆       text │
├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ This is    ┆ Now        ┆    This is │
│ another    ┆ add some   ┆    awesome │
│ text       ┆ multi line ┆            │
│            ┆ stuff      ┆            │
╰────────────┴────────────┴────────────╯

Styling

use comfy_table::*;
use comfy_table::presets::UTF8_FULL;

fn main() {
    let mut table = Table::new();
    table.load_preset(UTF8_FULL)
        .set_content_arrangement(ContentArrangement::Dynamic)
        .set_table_width(80)
        .set_header(vec![
                    Cell::new("Header1").add_attribute(Attribute::Bold),
                    Cell::new("Header2").fg(Color::Green),
                    Cell::new("Header3"),
        ])
        .add_row(vec![
                 Cell::new("This is a bold text").add_attribute(Attribute::Bold),
                 Cell::new("This is a green text").fg(Color::Green),
                 Cell::new("This one has black background").bg(Color::Black),
        ])
        .add_row(vec![
                 Cell::new("Blinky boi").add_attribute(Attribute::SlowBlink),
                 Cell::new("This table's content is dynamically arranged. The table is exactly 80 characters wide.\nHere comes a reallylongwordthatshoulddynamicallywrap"),
                 Cell::new("COMBINE ALL THE THINGS")
                 .fg(Color::Green)
                 .bg(Color::Black)
                 .add_attributes(vec![
                                 Attribute::Bold,
                                 Attribute::SlowBlink,
                 ])
        ]);

    println!("{}", table);
}

This code generates the table that can be seen at the top of this Readme.

Code Examples

There is an example folder containing a few examples. To run an example, run it with run --example. E.g.:

cargo run --example readme_table

If you're looking for more information, take a look at the tests folder.
There is a test for almost every feature including a visual view for each resulting table.

Contribution Guidelines

Comfy-table is supposed to be minimalistic. A fixed set of features that just work, for a simple use-case:

  • Normal tables (columns, rows, one cell per column/row).
  • Dynamic arrangement of content to a given width.
  • Some kind of manual intervention in the arrangement process.

If you come up with an idea or an improvement, that fits into the current scope of the project, feel free to create an issue :)!

Some 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.

Such features are:

  • Nested tables
  • Cells that span over multiple columns/rows
  • CSV to table conversion and vice versa
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].