console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.22k stars 238 forks source link

Add some documentation on what the alignment characters do #509

Closed hasezoey closed 1 year ago

hasezoey commented 1 year ago

Currently the documentation lists [<^>] for an optional alignment specification but does not specify what each character does and where it aligns to.

I would expect there to only be 2 characters, plus maybe a center character but am not sure which are which and what the others do.

djc commented 1 year ago

It's left, center and right. Would you be able to submit a PR?

hasezoey commented 1 year ago

It's left, center and right

this is what i expected, i assume you mean <^> as left, center and right respectively, but what do the other 2 characters, namely [ and ] do in this case? if the do nothing, why are they included? (the other mentions in the text-box dont have extra characters or make clear what is meant)

also as a side note, how does alignment interact with wide_* elements?

djc commented 1 year ago

The [ and ] are likely a reference to how regular expressions usually define character classes, they are not actual alignment characters. See parser code: https://github.com/console-rs/indicatif/blob/main/src/style.rs#L505. The documentation might be inconsistent because different parts were written by different people at different times, again feel free to submit a PR to improve on the current situation.

The interaction between padding (what wide_* does) and alignment can be reviewed here: https://github.com/console-rs/indicatif/blob/main/src/style.rs#L691.