tabled icon indicating copy to clipboard operation
tabled copied to clipboard

Support title cased field names

Open casey opened this issue 10 months ago • 3 comments

Great library! It would be nice to support title case for table headers, i.e., Upper Title Case and lower title case. If a table is primarily intended for a human reader, I think these are the easiest formats to read.

casey avatar Feb 25 '25 17:02 casey

Hi @casey

I do agree with your proposal.

I hope you have noticed, we already have support for it we just don't support Upper Tittle Case and lower tittle case.

#[derive(Tabled)]
#[tabled(rename_all = "UPPERCASE")]
struct Country {
    name: String,
    #[tabled(rename_all = "kebab-case")]
    area_km2: f32,
}

But I guess it would be also good to provide same functionality dynamically. Like the following.

table.modify(Rows::first(), Format::upper_title_case())

zhiburt avatar Feb 26 '25 09:02 zhiburt

OK I've committed a derive update. You can use it on master until it not released.

#[derive(Tabled)]
#[tabled(rename_all = "camelCase")]
struct Country {
    name: String,
    #[tabled(rename_all = "Upper Title Case")]
    capital_city: String,
    #[tabled(rename_all = "lower title case")]
    area_km2: f32,
}

zhiburt avatar Feb 27 '25 21:02 zhiburt

Awesome, just tried out the master branch and it looks great. (It's a tool to enumerate audio devices.)

Image

casey avatar Feb 28 '25 06:02 casey