From 7d2252f56d3bd22452db968325c67bd324e1ceb0 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 24 Dec 2023 13:37:48 +0000 Subject: [PATCH] UNFINISHED: ColouredString class. --- src/coloured_string.rs | 21 +++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 22 insertions(+) create mode 100644 src/coloured_string.rs diff --git a/src/coloured_string.rs b/src/coloured_string.rs new file mode 100644 index 0000000..6306d91 --- /dev/null +++ b/src/coloured_string.rs @@ -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() } + } +} diff --git a/src/lib.rs b/src/lib.rs index 4a6c115..24a0489 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { -- 2.30.2