]> git.scottworley.com Git - tablify/commitdiff
`!mark col:X` to override the tally mark character for a column
authorScott Worley <scottworley@scottworley.com>
Thu, 24 Oct 2024 18:17:21 +0000 (11:17 -0700)
committerScott Worley <scottworley@scottworley.com>
Thu, 24 Oct 2024 18:17:21 +0000 (11:17 -0700)
Changelog
README.md
src/lib.rs

index ba419d9770932a82d4182f24773cc2bf43e761a9..9729182915083553108a2c41a4ff736244b11721 100644 (file)
--- 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
index fe19e7bde3c648aa361c83e6cc6f4724fffe20e8..e93375d30f6670da6a4dce2a3f23951c04477a3f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ Several bang-commands are available to control output formatting:
 * `!col_threshold <N>` to set the threshold at which entries get columns rather than being left as notes on the right.  Default: 2
 * `!hide <column>` to omit a column
 * `!label <column>:<new label>` to change a column's label without needing to change all the input occurrences.
+* `!mark <column>:<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][].)
 
index 4deceffb5ff53677903e6f4e2a46a93d7390a462..e199470146730fd89cfea466878f926d0c42e488 100644 (file)
@@ -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]