From: Ian Jackson Date: Sun, 15 May 2022 01:44:13 +0000 (+0100) Subject: otterlib: Fix column handling in preview X-Git-Tag: otter-1.1.0~145 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=d00126493b5e50392061b36599ee75b3541a00ff;p=otter.git otterlib: Fix column handling in preview This was very confused. Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 120e74a8..92996792 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -88,12 +88,23 @@ fn preview(opts: &Opts, items: Vec) { nwtemplates::init_from_dir(&opts.nwtemplates)?; impl Prep { - fn want_several(&self) -> bool { - self.size[0] < 50.0 + fn large(&self) -> bool { + self.size[0] >= 50.0 } - fn face_cols(&self) -> usize { - usize::from(self.p.nfaces()) - * if self.want_several() { SEVERAL } else { 1 } + fn face_want_span(&self) -> usize { + if self.large() { 4 } else { 1 } + } + fn face_want_several(&self, _face: RawFaceId) -> usize { + if self.large() { 1 } else { SEVERAL } + } + fn face_want_cols(&self, face: RawFaceId) -> usize { + self.face_want_several(face) * + self.face_want_span() + } + fn want_cols(&self) -> usize { + (0 .. self.p.nfaces()) + .map(|face| self.face_want_cols(face)) + .sum() } } @@ -137,7 +148,7 @@ fn preview(opts: &Opts, items: Vec) { // clones as a bodge for https://github.com/rust-lang/rust/issues/34162 pieces.sort_by_key(|(p,_)| (p.spec.item.clone(), p.spec.lib.clone())); - let max_facecols = pieces.iter().map(|s| s.0.face_cols()).max().unwrap_or(1); + let total_cols = pieces.iter().map(|s| s.0.want_cols()).max().unwrap_or(1); let max_uos = pieces.iter().map(|s| s.0.uos.len()).max().unwrap_or(0); println!("{}", &HTML_PRELUDE); @@ -165,27 +176,34 @@ fn preview(opts: &Opts, items: Vec) { println!(r#""#); println!(r#"{}"#, p.describe_html(&GPiece::dummy(), &default())?); - let only1 = s.face_cols() == 1; - - for facecol in 0..(if only1 { 1 } else { max_facecols }) { - let (face, inseveral) = if s.want_several() { - (facecol / SEVERAL, facecol % SEVERAL) - } else { - (facecol, 0) - }; - print!(r#" "eee", - 2 => "555", - _ => panic!(), - }); - println!(r#">"#); - if face < (p.nfaces() as usize) { + if max_uos > 0 { + println!(r#"{}"#, + uos.iter() + .map(|uo| Html::from_txt(uo)) + .collect::>() + .iter() + .hjoin(&Html::lit(" "))); + } + + let mut cols_done = 0; + let face_span = s.face_want_span(); + + for face in 0.. s.p.nfaces() { + for inseveral in 0.. s.face_want_several(face) { + print!(r#" "eee", + 2 => "555", + _ => panic!(), + }); + println!(r#">"#); + let viewport = [bbox[0].clone(), size.clone()] .iter().flatten().cloned() @@ -208,18 +226,13 @@ fn preview(opts: &Opts, items: Vec) { &surround, &dasharray, HELD_SURROUND_COLOUR); } println!(""); - } - println!(""); - - if max_uos > 0 { - println!(r#"{}"#, - uos.iter() - .map(|uo| Html::from_txt(uo)) - .collect::>() - .iter() - .hjoin(&Html::lit(" "))); - } - }; + println!(""); + }} + + if cols_done < total_cols { + print!(r#""#, total_cols - cols_done); + } + println!(""); } println!("");