diff --git a/Cargo.toml b/Cargo.toml index 2ffce2e..f1e77ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,6 +105,12 @@ dev = '''set -e cargo watch -i .cargo -s 'cargo run --features dev' ''' +dev-install = '''set -e + cargo build + sudo rm /usr/local/bin/oatmeal + sudo mv ./target/debug/oatmeal /usr/local/bin/ +''' + goreleaser = '''set -e export OM_VERSION=$(cat Cargo.toml | grep version | head -n1 | awk -F '"' '{print $2}') diff --git a/src/domain/models/message.rs b/src/domain/models/message.rs index 9ff7c11..108c435 100644 --- a/src/domain/models/message.rs +++ b/src/domain/models/message.rs @@ -39,7 +39,7 @@ impl Message { return Message { author: author.clone(), author_formatted: formatted_author(author), - text: text.to_string(), + text: text.to_string().replace('\t', " "), mtype: MessageType::Normal, }; } @@ -48,7 +48,7 @@ impl Message { return Message { author: author.clone(), author_formatted: formatted_author(author), - text: text.to_string(), + text: text.to_string().replace('\t', " "), mtype, }; } @@ -58,7 +58,7 @@ impl Message { } pub fn append(&mut self, text: &str) { - self.text += text; + self.text += &text.replace('\t', " "); } pub fn as_string_lines(&self, line_max_width: u16) -> Vec { diff --git a/src/domain/models/message_test.rs b/src/domain/models/message_test.rs index 2ae5b1c..5bb993e 100644 --- a/src/domain/models/message_test.rs +++ b/src/domain/models/message_test.rs @@ -13,6 +13,15 @@ fn it_executes_new() { assert_eq!(msg.mtype, MessageType::Normal); } +#[test] +fn it_executes_new_replacing_tabs() { + let msg = Message::new(Author::Oatmeal, "\t\tHi there!"); + assert_eq!(msg.author, Author::Oatmeal); + assert_eq!(msg.author_formatted, "Oatmeal"); + assert_eq!(msg.text, " Hi there!".to_string()); + assert_eq!(msg.mtype, MessageType::Normal); +} + #[test] fn it_executes_new_with_type() { let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "It broke!"); @@ -22,6 +31,15 @@ fn it_executes_new_with_type() { assert_eq!(msg.mtype, MessageType::Error); } +#[test] +fn it_executes_new_with_type_replacing_tabs() { + let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "\t\tIt broke!"); + assert_eq!(msg.author, Author::Oatmeal); + assert_eq!(msg.author_formatted, "Oatmeal"); + assert_eq!(msg.text, " It broke!".to_string()); + assert_eq!(msg.mtype, MessageType::Error); +} + #[test] fn it_executes_message_type() { let msg = Message::new_with_type(Author::Oatmeal, MessageType::Error, "It broke!"); @@ -35,6 +53,13 @@ fn it_executes_append() { assert_eq!(msg.text, "Hi there! It's me!"); } +#[test] +fn it_executes_append_with_tabs() { + let mut msg = Message::new(Author::Oatmeal, "Hi there!"); + msg.append("\tIt's me!"); + assert_eq!(msg.text, "Hi there! It's me!"); +} + #[test] fn it_executes_as_string_lines() { let msg = Message::new(Author::Oatmeal, "Hi there! This is a really long line that pushes the boundaries of 50 characters across the screen, resulting in the line being wrapped. Cool right?");