diff --git a/src/format.rs b/src/format.rs new file mode 100644 index 0000000..7d65083 --- /dev/null +++ b/src/format.rs @@ -0,0 +1,99 @@ +#[derive(Clone, Copy)] +pub enum Format { + Bold, + Italics, + Underline, + Strikethrough, + Reverse, + Color, + Plain, +} + +impl std::fmt::Display for Format { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Format::Bold => write!(f, "\x02"), + Format::Italics => write!(f, "\x1d"), + Format::Underline => write!(f, "\x1f"), + Format::Strikethrough => write!(f, "\x1e"), + Format::Reverse => write!(f, "\x12"), + Format::Color => write!(f, "\x03"), + Format::Plain => write!(f, "\x0f"), + } + } +} + +#[derive(Clone, Copy)] +pub enum Color { + White, + Black, + Blue, + Green, + Red, + Brown, + Purple, + Orange, + Yellow, + LightGreen, + Teal, + Cyan, + LightBlue, + Magenta, + Gray, + LightGray, +} + +impl std::fmt::Display for Color { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Color::White => write!(f, "00"), + Color::Black => write!(f, "01"), + Color::Blue => write!(f, "02"), + Color::Green => write!(f, "03"), + Color::Red => write!(f, "04"), + Color::Brown => write!(f, "05"), + Color::Purple => write!(f, "06"), + Color::Orange => write!(f, "07"), + Color::Yellow => write!(f, "08"), + Color::LightGreen => write!(f, "09"), + Color::Teal => write!(f, "10"), + Color::Cyan => write!(f, "11"), + Color::LightBlue => write!(f, "12"), + Color::Magenta => write!(f, "13"), + Color::Gray => write!(f, "14"), + Color::LightGray => write!(f, "15"), + } + } +} + +pub struct Msg(String); + +impl std::fmt::Display for Msg { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", &self.0) + } +} + +impl Msg { + pub fn new() -> Self { + Self(String::new()) + } + + pub fn text(mut self, text: impl AsRef) -> Self { + self.0 += text.as_ref(); + self + } + pub fn color(mut self, color: Color) -> Self { + self.0 += &Format::Color.to_string(); + self.0 += &color.to_string(); + self + } + pub fn format(mut self, format: Format) -> Self { + self.0 += &format.to_string(); + self + } + pub fn reset(mut self) -> Self { + self.0 += &Format::Plain.to_string(); + self + } +} diff --git a/src/lib.rs b/src/lib.rs index 9636e48..c927eb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ pub mod events; pub mod factory; +pub mod format; pub mod irc_command; pub mod system; pub mod system_params; diff --git a/src/system.rs b/src/system.rs index c03f246..814280d 100644 --- a/src/system.rs +++ b/src/system.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use crate::{factory::Factory, IrcPrefix}; +use crate::{factory::Factory, format::Msg, IrcPrefix}; pub struct FunctionSystem { f: F, @@ -113,13 +113,13 @@ impl IntoResponse for &str { } } -impl IntoResponse for Vec { +impl IntoResponse for Msg { fn response(self) -> Response { - Response(Some(self)) + Response(Some(vec![self.to_string()])) } } -impl IntoResponse for Vec<&str> { +impl IntoResponse for Vec { fn response(self) -> Response { Response(Some( self.iter().map(|elem| elem.to_string()).collect::>(), diff --git a/src/utils.rs b/src/utils.rs index e69de29..8b13789 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -0,0 +1 @@ +