From: Scott Worley Date: Thu, 24 Oct 2024 18:17:21 +0000 (-0700) Subject: `!mark col:X` to override the tally mark character for a column X-Git-Tag: v0.6.0~1 X-Git-Url: http://git.scottworley.com/tablify/commitdiff_plain/156f8d37e7451b5f31f02f32b0f0eb07df8c3954?ds=inline `!mark col:X` to override the tally mark character for a column --- diff --git a/Changelog b/Changelog index ba419d9..9729182 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,6 @@ ## [Unreleased] - Lighten background shading +- `!mark col:X` to override the tally mark character for a column ## [0.5.1] - 2024-10-04 - Fix hover highlight for relabeled columns diff --git a/README.md b/README.md index fe19e7b..e93375d 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Several bang-commands are available to control output formatting: * `!col_threshold ` to set the threshold at which entries get columns rather than being left as notes on the right. Default: 2 * `!hide ` to omit a column * `!label :` to change a column's label without needing to change all the input occurrences. +* `!mark :` to change the character that is used as the tally-mark for that column (For the other `tablify` that makes ascii-art tables, see [Text-RecordParser][].) diff --git a/src/lib.rs b/src/lib.rs index 4deceff..e199470 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, @@ -641,6 +651,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 +664,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]