diff options
| author | mat <github@matdoes.dev> | 2022-10-21 22:30:19 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-10-21 22:30:19 -0500 |
| commit | 3fbbe5e93d0f7dbd828e8f071d7bfd092d4b2896 (patch) | |
| tree | 16901a63abd8eb6a34d6ee880178102778ae6ac3 /azalea-chat/src/text_component.rs | |
| parent | 6924502bc43e707008d156e892b2fd15b56cbb1b (diff) | |
| download | azalea-drasl-3fbbe5e93d0f7dbd828e8f071d7bfd092d4b2896.tar.xz | |
have Display implemented for the Components
Diffstat (limited to 'azalea-chat/src/text_component.rs')
| -rwxr-xr-x | azalea-chat/src/text_component.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs index 799877f5..91af28e7 100755 --- a/azalea-chat/src/text_component.rs +++ b/azalea-chat/src/text_component.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::fmt::Display; use crate::{base_component::BaseComponent, component::Component, style::ChatFormatting}; @@ -83,9 +83,19 @@ impl TextComponent { } } -impl fmt::Display for TextComponent { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", Component::Text(self.clone())) +impl Display for TextComponent { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // this contains the final string will all the ansi escape codes + for component in Component::Text(self.clone()).into_iter() { + let component_text = match &component { + Component::Text(c) => c.text.to_string(), + Component::Translatable(c) => c.to_string(), + }; + + f.write_str(&component_text)?; + } + + Ok(()) } } |
