aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/translatable_component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-chat/src/translatable_component.rs')
-rwxr-xr-xazalea-chat/src/translatable_component.rs20
1 files changed, 15 insertions, 5 deletions
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),