Skip to content

Commit

Permalink
refactor: extract the Stylify trait to traits.rs module and update th…
Browse files Browse the repository at this point in the history
…e rest of the code
  • Loading branch information
Syaw0 committed Nov 4, 2024
1 parent 874e156 commit fb1a1c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
pub trait Stylify {
fn make_styles(&self, paint_type: Option<&PaintType>) -> String;
}
use crate::traits::Stylify;

#[derive(Debug, Clone)]
pub enum PaintType {
FG,
BG,
}

#[derive(Debug, Clone)]
struct Formatter {
pub struct Formatter {
n: u8,
}

Expand Down
4 changes: 1 addition & 3 deletions src/styled_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
PaletteColor,
Rgb,
Styles,
Stylify,
BLACK,
BLUE,
BOLD,
Expand Down Expand Up @@ -88,7 +87,6 @@ pub fn styled(text: &str) -> StyledText {
pub struct StyledText {
text: String,
start_styles: Vec<Styles>,
end_styles: Vec<Box<dyn Stylify>>,
}

impl StyledText {
Expand All @@ -98,7 +96,6 @@ impl StyledText {
StyledText {
text,
start_styles: vec![],
end_styles: vec![],
}
}

Expand Down Expand Up @@ -282,6 +279,7 @@ mod test {
assert_eq!(styled_text, "\x1b[47m\x1b[30mI'm So Happy\x1b[0m");
}

#[test]
fn blue_fg_bright_cyan_bg() {
let raw_text = "Silence is power";
let styled_text = styled(raw_text).blue().fg().bright_cyan().bg().paint();
Expand Down
5 changes: 5 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::colors::PaintType;

pub trait Stylify {
fn make_styles(&self, paint_type: Option<&PaintType>) -> String;
}

0 comments on commit fb1a1c0

Please sign in to comment.