Skip to content

Commit

Permalink
only remove leading newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ-Laser committed Dec 25, 2024
1 parent 2d068c6 commit 0b5b411
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion djlaser_catsay/src/cats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ pub struct Cat<'a> {
impl<'a> Cat<'a> {
pub const CATS: &'static [Cat<'static>; 6] = &CATS;
pub fn get_art(&self) -> &str {
return &self.art[1..];
if matches!(self.art.chars().next(), Some('\n')) {
&self.art[1..]
} else {
&self.art
}
}

pub fn get_cat(name: &str) -> Option<&'static Cat<'static>> {
Expand Down
4 changes: 1 addition & 3 deletions djlaser_catsay/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ where
_ => CliError::CatFileNotFound(file.to_string(), error),
})?;

// get_art removes a leading newline
let simple_text = " ".to_string() + &text;
// TODO: Do parsing of complex catfiles else return simple_text
Ok(simple_text)
Ok(text)
}

fn catsay<I, O, E, F>(
Expand Down

0 comments on commit 0b5b411

Please sign in to comment.