diff options
| author | mat <github@matdoes.dev> | 2022-12-04 20:58:14 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-12-04 20:58:14 -0600 |
| commit | e99a822995c80e1f95c5f7a69e0d8c5d131af20f (patch) | |
| tree | fd0e2e4079a1afd0ba6278d32169511defc97d08 /azalea-chat/src | |
| parent | a5aa8ea0c0c3ad38b6e3a1ada74ea3ce87f6edcf (diff) | |
| download | azalea-drasl-e99a822995c80e1f95c5f7a69e0d8c5d131af20f.tar.xz | |
change to_ansi to not take args
Diffstat (limited to 'azalea-chat/src')
| -rwxr-xr-x | azalea-chat/src/component.rs | 16 | ||||
| -rwxr-xr-x | azalea-chat/src/text_component.rs | 4 |
2 files changed, 15 insertions, 5 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index 95387248..b60beaf5 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -60,6 +60,9 @@ impl Component { /// [ANSI string](https://en.wikipedia.org/wiki/ANSI_escape_code), so you /// can print it to your terminal and get styling. /// + /// This is technically a shortcut for [`Component::to_ansi_custom_style`] with a + /// default [`Style`] colored white. + /// /// # Examples /// /// ```rust @@ -71,12 +74,19 @@ impl Component { /// "color": "red", /// })).unwrap(); /// - /// println!("{}", component.to_ansi(None)); + /// println!("{}", component.to_ansi()); /// ``` - pub fn to_ansi(&self, default_style: Option<&Style>) -> String { + pub fn to_ansi(&self) -> String { // default the default_style to white if it's not set - let default_style: &Style = default_style.unwrap_or(&DEFAULT_STYLE); + self.to_ansi_custom_style(&DEFAULT_STYLE) + } + /// Convert this component into an + /// [ANSI string](https://en.wikipedia.org/wiki/ANSI_escape_code). + /// + /// This is the same as [`Component::to_ansi`], but you can specify a + /// default [`Style`] to use. + pub fn to_ansi_custom_style(&self, default_style: &Style) -> String { // this contains the final string will all the ansi escape codes let mut built_string = String::new(); // this style will update as we visit components diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs index 6715c93e..e5cc054e 100755 --- a/azalea-chat/src/text_component.rs +++ b/azalea-chat/src/text_component.rs @@ -127,7 +127,7 @@ mod tests { TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_string()) .get(); assert_eq!( - component.to_ansi(None), + component.to_ansi(), format!( "{GREEN}Hypixel Network {RED}[1.8-1.18]\n{BOLD}{AQUA}HAPPY HOLIDAYS{RESET}", GREEN = Ansi::rgb(ChatFormatting::Green.color().unwrap()), @@ -143,7 +143,7 @@ mod tests { fn test_legacy_color_code_to_component() { let component = TextComponent::new("§lHello §r§1w§2o§3r§4l§5d".to_string()).get(); assert_eq!( - component.to_ansi(None), + component.to_ansi(), format!( "{BOLD}Hello {RESET}{DARK_BLUE}w{DARK_GREEN}o{DARK_AQUA}r{DARK_RED}l{DARK_PURPLE}d{RESET}", BOLD = Ansi::BOLD, |
