From 7335d7451de7f09bdb5b3d41a499061c7eba19f9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 15 May 2021 22:21:37 +0100 Subject: [PATCH] ItemEnquiryData: Put the lib name in it Signed-off-by: Ian Jackson --- apitest/at-otter.rs | 2 +- src/bin/otterlib.rs | 12 ++++++------ src/shapelib.rs | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apitest/at-otter.rs b/apitest/at-otter.rs index ca7af1b8..646ae347 100644 --- a/apitest/at-otter.rs +++ b/apitest/at-otter.rs @@ -546,7 +546,7 @@ impl Ctx { "library-list @table@ wikimedia chess-yellow-?" )?; let output: String = self.otter(&command)?.into(); - assert!( Regex::new("(?m)^chess-yellow-K *the yellow king$")? + assert!( Regex::new("(?m)^wikimedia *chess-yellow-K *the yellow king$")? .find(&output) .is_some(), "got: {}", &output); diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index c790fedd..73f0bd1f 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -62,7 +62,7 @@ pub enum OutputKind { Preview, } -pub type ItemForOutput = (String, ItemEnquiryData); +pub type ItemForOutput = ItemEnquiryData; pub const VIS: ShowUnocculted = ShowUnocculted::new_visible(); @@ -93,8 +93,8 @@ fn preview(items: Vec) { } let mut pieces: Vec = items.into_iter().map(|it| { - let spec = ItemSpec { lib: it.0, item: it.1.itemname.into() }; - let sortkey = it.1.sortkey; + let spec = ItemSpec { lib: it.libname.into(), item: it.itemname.into() }; + let sortkey = it.sortkey; (||{ let (p, _occultable) = spec.clone() .find_load(&ig_dummy, SpecDepth::zero()) @@ -239,7 +239,7 @@ fn main() { for contents in all_registries.lib_name_lookup(&lib)? { for pat in opts.items.split(SPLIT) { for item in contents.list_glob(pat)? { - items.push((lib.clone(), item)) + items.push(item) } } } @@ -247,8 +247,8 @@ fn main() { items.sort(); match opts.outkind { - OutputKind::List => for item in &items { - println!("{:<10} {}", &item.0, &item.1); + OutputKind::List => for item in items { + println!("{}", item); } OutputKind::Preview => { preview(items)? diff --git a/src/shapelib.rs b/src/shapelib.rs index 28c362fc..b0ef0898 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -221,6 +221,7 @@ impl OccultedPieceTrait for ItemOccultable { #[derive(Debug,Clone,Serialize,Deserialize,Eq,PartialEq,Ord,PartialOrd)] pub struct ItemEnquiryData { + pub libname: String, pub itemname: GoodItemName, pub sortkey: Option, pub f0desc: Html, @@ -230,7 +231,8 @@ pub struct ItemEnquiryData { impl Display for ItemEnquiryData { #[throws(fmt::Error)] fn fmt(&self, f: &mut Formatter) { - write!(f, "{:20} {}", self.itemname, self.f0desc.as_html_str())?; + write!(f, "{:<10} {:20} {}", &self.libname, &self.itemname, + self.f0desc.as_html_str())?; } } @@ -566,6 +568,7 @@ impl Contents { }; let f0bbox = loaded.bbox_approx()?; let ier = ItemEnquiryData { + libname: self.libname.clone(), itemname: (**k).to_owned(), sortkey: v.sort.to_owned(), f0bbox, -- 2.30.2