chiark / gitweb /
UNFINISHED: ColouredString class.
authorSimon Tatham <anakin@pobox.com>
Sun, 24 Dec 2023 13:37:48 +0000 (13:37 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 24 Dec 2023 13:37:48 +0000 (13:37 +0000)
src/coloured_string.rs [new file with mode: 0644]
src/lib.rs

diff --git a/src/coloured_string.rs b/src/coloured_string.rs
new file mode 100644 (file)
index 0000000..6306d91
--- /dev/null
@@ -0,0 +1,21 @@
+pub struct ColouredString {
+    text: String,
+    colour: String,
+}
+
+impl ColouredString {
+    pub fn plain(text: &str) -> Self {
+        ColouredString { text: text.to_string(),
+                         colour: " ".repeat(text.len()) }
+    }
+    pub fn uniform(text: &str, colour: char) -> Self {
+        ColouredString { text: text.to_string(),
+                         colour: colour.to_string().repeat(text.len()) }
+    }
+    pub fn general(text: &str, colour: &str) -> Self {
+        assert!(text.len() == colour.len(),
+                "Mismatched lengths in ColouredString::general");
+        ColouredString { text: text.to_string(),
+                         colour: colour.to_string() }
+    }
+}
index 4a6c115c2abe8603ce5105f4c7f6a2a56f80ad6c..24a0489f5cb8318b5c3725eff75c7fb15f6e0dcb 100644 (file)
@@ -2,6 +2,7 @@ pub mod types;
 pub mod auth;
 pub mod html;
 pub mod scan_re;
+pub mod coloured_string;
 
 #[derive(Debug)]
 pub enum OurError {