fixed progress flag misbehaving at certain sizes

This commit is contained in:
Valerie Wolfe 2024-07-05 14:07:36 -04:00
parent 0c1c1148c2
commit 6f320b65fb
3 changed files with 11 additions and 20 deletions

View file

@ -58,7 +58,7 @@ pub fn progress(state: &State) -> Flag {
// set up constraints // set up constraints
let linecount = height - (height % 6); // largest multiple of 6 smaller than height let linecount = height - (height % 6); // largest multiple of 6 smaller than height
let full_depth = width / 3; let full_depth = width / 3;
let chevron_width = (full_depth / 6) - 1; let chevron_width = if full_depth > 6 { (full_depth / 6) - 1 } else { 0 };
let direction_thresh = linecount / 2; let direction_thresh = linecount / 2;
let corner = linecount % 2 == 1; let corner = linecount % 2 == 1;
@ -99,17 +99,14 @@ pub fn progress(state: &State) -> Flag {
// grab our substring constraints // grab our substring constraints
let start = (direction_thresh - n) as usize - 1; let start = (direction_thresh - n) as usize - 1;
let diff = display_length - start; let diff = if display_length >= start { display_length - start } else { 0 };
// take substring of chevron line... // take substring of chevron line...
let mut line = ansi_substr(&base, start as usize, base_length); let mut line = ansi_substr(&base, start as usize, base_length);
line += &stripes[index].to_string();
if diff > 0 { line.push(TRIANGLE_21[0]); }
// ... and add the colored stripe // ... and add the colored stripe
line += &format!( line += &" ".repeat(width as usize - diff);
"{stripe}{separator}{line}",
stripe = stripes[index],
separator = TRIANGLE_21[0],
line = " ".repeat(width as usize - diff)
);
lines.push(line); lines.push(line);
line_no += 1; line_no += 1;
@ -135,15 +132,12 @@ pub fn progress(state: &State) -> Flag {
if index > 5 { break; } if index > 5 { break; }
let start = n as usize; let start = n as usize;
let diff = display_length - start; let diff = if display_length >= start { display_length - start } else { 0 };
let mut line = ansi_substr(&base, start, base_length); let mut line = ansi_substr(&base, start, base_length);
line += &format!( line += &stripes[index].to_string();
"{stripe}{separator}{line}", if diff > 0 { line.push(TRIANGLE_21[2]); }
stripe = stripes[index], line += &" ".repeat(width as usize - diff);
separator = TRIANGLE_21[2],
line = " ".repeat(width as usize - diff)
);
lines.push(line); lines.push(line);
line_no += 1; line_no += 1;

View file

@ -60,10 +60,7 @@ pub fn draw_full(lines: Vec<String>) {
pub fn draw_lines(lines: Vec<String>, state: &State) { pub fn draw_lines(lines: Vec<String>, state: &State) {
match state.size { match state.size {
Size::Full => draw_full(lines), Size::Full => draw_full(lines),
_ => { _ => for line in lines { println!("{line}{RESET}{RESET_BG}") }
for line in lines { println!("{line}"); }
println!("{RESET}{RESET_BG}");
}
} }
} }

View file

@ -27,7 +27,7 @@ pub fn philadelphia() -> Flag {
Flag::Stripes(inner) Flag::Stripes(inner)
=> inner, => inner,
_ _
=> { panic!("impossible enum variant"); } => panic!("impossible enum variant")
}; };
colors.insert(0, BLACK); colors.insert(0, BLACK);
colors.insert(1, brown); colors.insert(1, brown);