Skip to content

Commit de9862b

Browse files
LussacZhengdjc
authored andcommitted
fix: first style of wide elements was ignored
ref: #431, 5038ba8
1 parent 9cb25a7 commit de9862b

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/style.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,6 @@ impl ProgressStyle {
321321
}
322322
};
323323

324-
if buf == "\x00" {
325-
// Don't expand for wide elements
326-
cur.push_str(&buf);
327-
continue;
328-
}
329-
330324
match width {
331325
Some(width) => {
332326
let padded = PaddedStringDisplay {
@@ -759,4 +753,37 @@ mod tests {
759753
style.format_state(&state, &mut buf, WIDTH);
760754
assert_eq!(&buf[0], "fghijklmno");
761755
}
756+
757+
#[test]
758+
fn wide_element_style() {
759+
const CHARS: &str = "=>-";
760+
const WIDTH: u16 = 8;
761+
let pos = Arc::new(AtomicPosition::new());
762+
// half finished
763+
pos.set(2);
764+
let state = ProgressState::new(Some(4), pos);
765+
let mut buf = Vec::new();
766+
767+
let style = ProgressStyle::with_template("{wide_bar}")
768+
.unwrap()
769+
.progress_chars(CHARS);
770+
style.format_state(&state, &mut buf, WIDTH);
771+
assert_eq!(&buf[0], "====>---");
772+
773+
buf.clear();
774+
let style = ProgressStyle::with_template("{wide_bar:.red.on_blue/green.on_cyan}")
775+
.unwrap()
776+
.progress_chars(CHARS);
777+
style.format_state(&state, &mut buf, WIDTH);
778+
assert_eq!(
779+
&buf[0],
780+
"\u{1b}[31m\u{1b}[44m====>\u{1b}[32m\u{1b}[46m---\u{1b}[0m\u{1b}[0m"
781+
);
782+
783+
buf.clear();
784+
let mut style = ProgressStyle::with_template("{wide_msg:^.red.on_blue}").unwrap();
785+
style.message = "foobar".into();
786+
style.format_state(&state, &mut buf, WIDTH);
787+
assert_eq!(&buf[0], "\u{1b}[31m\u{1b}[44m foobar \u{1b}[0m");
788+
}
762789
}

0 commit comments

Comments
 (0)