Skip to content

feat: support max width for wide_bar via {wide_bar:N} - #862

Open
amitcoder79 wants to merge 1 commit into
console-rs:mainfrom
amitcoder79:feat/wide-bar-max-width
Open

amitcoder79 wants to merge 1 commit into
console-rs:mainfrom
amitcoder79:feat/wide-bar-max-width

Conversation

@amitcoder79

Copy link
Copy Markdown

The width specifier on wide_bar was applied as padding by the generic placeholder handler, inflating the output instead of capping the bar length. This makes {wide_bar:N} work as a max-width cap: the bar scales down with the terminal but never exceeds N visual columns.

Changes

  • WideElement::Bar gains a max_width: Option<usize> field, populated from the template width specifier
  • expand caps left with min(left, max) when the field is set
  • Skip PaddedStringDisplay for wide_bar and wide_msg since their width semantics are a cap, not padding

Usage

// Scales with terminal width, but never wider than 30 columns
let style = ProgressStyle::with_template("[{elapsed}] {wide_bar:30} {percent}%").unwrap();

Testing

  • New test: wide_bar_max_width_caps_bar_length — verifies unlimited {wide_bar} fills the terminal (50 cols) while {wide_bar:20} caps at exactly 20 visual columns
  • All existing tests pass

Closes #789

The width specifier on wide_bar was applied as padding (via
PaddedStringDisplay), which inflated the bar instead of capping it.
Skip the padding step for wide_bar and wide_msg, and pass the width
to the WideElement as a max_width cap used during expansion.

{wide_bar:20} now scales down with the terminal but never exceeds 20
visual columns.

Closes console-rs#789
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

Successfully merging this pull request may close these issues.

Is it possible to have a wide_bar with limited max length?

1 participant