aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xazalea-chat/src/component.rs13
-rwxr-xr-xazalea-chat/src/text_component.rs18
-rwxr-xr-xazalea-chat/src/translatable_component.rs20
3 files changed, 32 insertions, 19 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 81224d9f..12df03cd 100755
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -267,16 +267,9 @@ impl From<String> for Component {
impl Display for Component {
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 self.clone().into_iter() {
- let component_text = match &component {
- Self::Text(c) => c.text.to_string(),
- Self::Translatable(c) => c.to_string(),
- };
-
- f.write_str(&component_text)?;
+ match self {
+ Component::Text(c) => c.fmt(f),
+ Component::Translatable(c) => c.fmt(f),
}
-
- Ok(())
}
}
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(())
}
}
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index 7cab6903..69f4bfec 100755
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -1,4 +1,4 @@
-use std::fmt::{self, Formatter};
+use std::fmt::{self, Display, Formatter};
use crate::{
base_component::BaseComponent, component::Component, style::Style,
@@ -115,13 +115,23 @@ impl TranslatableComponent {
}
}
-impl fmt::Display for TranslatableComponent {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", Component::Translatable(self.clone()))
+impl Display for TranslatableComponent {
+ 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::Translatable(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(())
}
}
-impl fmt::Display for StringOrComponent {
+impl Display for StringOrComponent {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self {
StringOrComponent::String(s) => write!(f, "{}", s),