From 80fb4bd1d9564db6fc44857833bdfce36547c4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 2 Jan 2021 14:50:36 +0100 Subject: [PATCH] init table system --- src/table.rs | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 src/table.rs diff --git a/src/table.rs b/src/table.rs new file mode 100644 index 0000000..b1788d8 --- /dev/null +++ b/src/table.rs @@ -0,0 +1,228 @@ +use std::fmt; + +#[derive(Clone, Debug)] +pub struct Style(u8, u8, u8); + +impl fmt::Display for Style { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Style(color, bright, shade) = self; + + let bright_str: String = if *bright > 0 { + String::from(";") + &bright.to_string() + } else { + String::from("") + }; + + let shade_str: String = if *shade > 0 { + String::from(";") + &shade.to_string() + } else { + String::from("") + }; + + let mut style = String::from("\x1b["); + style.push_str(&color.to_string()); + style.push_str(&bright_str); + style.push_str(&shade_str); + style.push_str("m"); + + write!(f, "{}", style) + } +} + +#[derive(Debug)] +pub struct Cell { + styles: Vec