X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/eb893cd11452f8101ad16abcb4371285cdff8f1d..9321d710d6048b57691ff08a62c93c1c8e30a721:/src/lib.rs?ds=inline diff --git a/src/lib.rs b/src/lib.rs index 4deceff..ac52b1f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,6 +50,16 @@ impl Config { .substitute_labels .insert(col.to_owned(), label.to_owned()), }; + } else if let Some(directive) = cmd.strip_prefix("mark ") { + match directive.split_once(':') { + None => { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + format!("line {line_num}: Mark missing ':'"), + )) + } + Some((col, label)) => self.mark.insert(col.to_owned(), label.to_owned()), + }; } else { return Err(std::io::Error::new( std::io::ErrorKind::InvalidInput, @@ -197,9 +207,7 @@ impl<'cfg, Input: Iterator>> Reader<'cfg, } } } -impl<'cfg, Input: Iterator>> Iterator - for Reader<'cfg, Input> -{ +impl>> Iterator for Reader<'_, Input> { type Item = Result; fn next(&mut self) -> Option { loop { @@ -413,7 +421,7 @@ fn column_header_labels<'a>( let dynamic_columns = columns.iter().map(Some); static_columns .chain(dynamic_columns) - .filter(|ocol| ocol.map_or(true, |col| !config.hidden_columns.contains(col))) + .filter(|ocol| ocol.is_none_or(|col| !config.hidden_columns.contains(col))) .map(|ocol| { ocol.map(|col| match config.substitute_labels.get(col) { None => col, @@ -449,7 +457,7 @@ fn render_column_headers(config: &Config, columns: &[String]) -> HTML { /// * there's an i/o error while reading `input` /// * the log has invalid syntax: /// * an indented line with no preceding non-indented line -pub fn tablify(input: impl std::io::Read) -> Result { +pub fn tablify(input: R) -> Result { let (rows, config) = read_input(input)?; let columns = column_order(&config, &rows); Ok(HTML(format!( @@ -641,6 +649,7 @@ mod tests { .substitute_labels["foo"], "bar" ); + assert_eq!(read_config(&b"!mark foo:*"[..]).unwrap().mark["foo"], "*"); let bad_command = read_config(&b"!no such command"[..]); assert!(bad_command.is_err()); @@ -653,6 +662,10 @@ mod tests { let bad_sub = read_config(&b"!label foo"[..]); assert!(bad_sub.is_err()); assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'")); + + let bad_mark = read_config(&b"!mark foo"[..]); + assert!(bad_mark.is_err()); + assert!(format!("{bad_mark:?}").contains("line 1: Mark missing ':'")); } #[test]