diff --git a/src/ansi_escape_code.rs b/src/ansi_escape_code.rs new file mode 100644 index 0000000..7dbde5d --- /dev/null +++ b/src/ansi_escape_code.rs @@ -0,0 +1,12 @@ +pub struct ANSIEscapeCode { + parameter: String, +} +impl ANSIEscapeCode { + pub fn new(parameter: String) -> Self { + ANSIEscapeCode { parameter } + } + + pub fn code(&self) -> String { + format!("\\x1b[{}m", self.parameter) + } +} diff --git a/src/lib.rs b/src/lib.rs index c9f2206..94e231c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,29 +1,3 @@ -struct ANSIEscapeCode { - parameter: String, -} -impl ANSIEscapeCode { - fn new(parameter: String) -> Self { - ANSIEscapeCode { parameter } - } +mod ansi_escape_code; - fn code(&self) -> String { - format!("\\x1b[{}m", self.parameter) - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn create_simple_ansi_code() { - let p = ANSIEscapeCode::new(String::from("33")); - assert_eq!(p.code(), "\\x1b[33m") - } - - #[test] - fn create_reset_ansi_code() { - let reset_ansi = ANSIEscapeCode::new(String::from("0")); - assert_eq!("\\x1b[0m", reset_ansi.code()); - } -} +// ======================================================================= diff --git a/src/test.rs b/src/test.rs new file mode 100644 index 0000000..2fc6eaa --- /dev/null +++ b/src/test.rs @@ -0,0 +1,23 @@ +#[cfg(test)] +mod ansi_escape_code_test { + use crate::ansi_escape_code::ANSIEscapeCode; + use super::*; + + #[test] + fn create_simple_ansi_code() { + let p = ANSIEscapeCode::new(String::from("33")); + assert_eq!(p.code(), "\\x1b[33m") + } + + #[test] + fn create_reset_ansi_code() { + let reset_ansi = ANSIEscapeCode::new(String::from("0")); + assert_eq!("\\x1b[0m", reset_ansi.code()); + } + + #[test] + fn create_bright_cyan_ansi_code() { + let reset_ansi = ANSIEscapeCode::new(String::from("96")); + assert_eq!("\\x1b[96m", reset_ansi.code()); + } +}