Skip to content

Fix display width of wide padding characters - #309

Open
myukitty wants to merge 1 commit into
console-rs:mainfrom
myukitty:fix/wide-padding-width
Open

myukitty wants to merge 1 commit into
console-rs:mainfrom
myukitty:fix/wide-padding-width

Conversation

@myukitty

@myukitty myukitty commented Nov 6, 2026

Copy link
Copy Markdown

pad_str_with("a", 5, Alignment::Right, None, '\u{754c}') returns four wide padding characters, producing nine columns instead of five.

Count complete padding characters by their display width before applying the existing alignment split. Leave any indivisible remainder unused and document the resulting narrower field. Zero-width padding and builds without unicode-width keep their previous repetition behavior.

Regression tests cover each alignment, non-divisible widths, empty and wide input, emoji padding, ANSI input, zero-width/control padding, feature-disabled behavior, and the unchanged borrowing/truncation paths.

Fixes #305.

Validation from the repository root on Linux (Rust 1.94.1):

  • make test (all seven feature combinations), make check, and make doc
  • cargo fmt --all -- --check
  • cargo clippy --examples --tests --all-features -- --deny warnings
  • cargo +1.71.0 check --lib --all-features --locked --offline

The new wide-padding and ANSI regression tests fail on unmodified main. Windows/macOS, WASM/WASI, and minimal-dependency-version CI were not run locally.

Comment thread src/utils.rs
}

let diff = width - cols;
let diff = (width - cols) / char_width(pad).max(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I prefer to use a symmetric max() like Ord::max().

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.

pad_str_with exceeds the requested width with a wide padding character

2 participants