Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display column names longer than its content #448

Open
rvnkcode opened this issue Nov 14, 2024 · 3 comments
Open

Display column names longer than its content #448

rvnkcode opened this issue Nov 14, 2024 · 3 comments

Comments

@rvnkcode
Copy link

rvnkcode commented Nov 14, 2024

Hi,
Can you fix the issue where ColumnNames are truncated if they are longer than the contents of the cell?
(The column name was 'description')

스크린샷 2024-11-14 20 33 44

@zhiburt
Copy link
Owner

zhiburt commented Nov 15, 2024

Can you fix the issue where ColumnNames are truncated if they are longer than the contents of the cell?
(The column name was 'description')

It's actually supposed to work this way by default.
Could you provide an example?

use tabled::{settings::{object::Rows, themes::ColumnNames, Disable}, Table};

fn main() {
    let data = vec![
        ("Id", "Age", "Description"),
        ("1", "10min", "Test"),
        ("2", "10min", "1"),
        ("3", "10min", "2"),
    ];

    let mut table = Table::new(data);
    table.with(Disable::row(Rows::first()));
    table.with(ColumnNames::default());

    println!("{table}");
}
+Id-+Age----+Description+
| 1 | 10min | Test      |
+---+-------+-----------+
| 2 | 10min | 1         |
+---+-------+-----------+
| 3 | 10min | 2         |
+---+-------+-----------+

@rvnkcode
Copy link
Author

rvnkcode commented Nov 25, 2024

Here is the code to reproduce.

use tabled::{settings::{themes::ColumnNames}, Table, Tabled};
use tabled::settings::object::Rows;
use tabled::settings::{Border, Color, Style};
use tabled::settings::themes::Colorization;

#[derive(Tabled)]
#[tabled(rename_all = "PascalCase")]
pub struct TestRow {
    #[tabled(rename = "ID")]
    id: usize,
    age: String,
    description: String,
}

fn main() {
    let data = vec![
        TestRow {
            id: 1,
            age: "10min".to_string(),
            description: "1".to_string(),
        },
        TestRow {
            id: 2,
            age: "20min".to_string(),
            description: "2".to_string(),
        },
    ];

    let mut table = Table::new(data);
    let primary = Color::default();
    let secondary = Color::new("\u{1b}[48;2;38;38;38m", "\u{1b}[49m");

    table.with(Style::empty())
        .modify(Rows::first(), Border::new().top('─'))
        .with(ColumnNames::default())
        .with(Colorization::rows([primary, secondary]));

    println!("{table}");
}
ID─Age────Des
 1  10min  1 
 2  20min  2 

But eventually I noticed if I change the order, the problem has solved.

// This works as I expected
table.with(Style::empty())
        .modify(Rows::first(), Border::new().top('─'))
        .with(Colorization::rows([primary, secondary]))
        .with(ColumnNames::default());
ID─Age────Description
 1  10min  1         
 2  20min  2         

@zhiburt
Copy link
Owner

zhiburt commented Nov 25, 2024

I think maybe we shall put some comment in the documentation about such behavior trick.

But was this solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants