1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

Merge branch 'main' into options

This commit is contained in:
mat 2022-10-21 22:31:23 -05:00
commit daf5b5c271
3 changed files with 32 additions and 19 deletions

View file

@ -267,16 +267,9 @@ impl From<String> for Component {
impl Display for Component { impl Display for Component {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// this contains the final string will all the ansi escape codes match self {
for component in self.clone().into_iter() { Component::Text(c) => c.fmt(f),
let component_text = match &component { Component::Translatable(c) => c.fmt(f),
Self::Text(c) => c.text.to_string(),
Self::Translatable(c) => c.to_string(),
};
f.write_str(&component_text)?;
} }
Ok(())
} }
} }

18
azalea-chat/src/text_component.rs Executable file → Normal file
View file

@ -1,4 +1,4 @@
use std::fmt; use std::fmt::Display;
use crate::{base_component::BaseComponent, component::Component, style::ChatFormatting}; use crate::{base_component::BaseComponent, component::Component, style::ChatFormatting};
@ -83,9 +83,19 @@ impl TextComponent {
} }
} }
impl fmt::Display for TextComponent { impl Display for TextComponent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", Component::Text(self.clone())) // 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(())
} }
} }

20
azalea-chat/src/translatable_component.rs Executable file → Normal file
View file

@ -1,4 +1,4 @@
use std::fmt::{self, Formatter}; use std::fmt::{self, Display, Formatter};
use crate::{ use crate::{
base_component::BaseComponent, component::Component, style::Style, base_component::BaseComponent, component::Component, style::Style,
@ -115,13 +115,23 @@ impl TranslatableComponent {
} }
} }
impl fmt::Display for TranslatableComponent { impl Display for TranslatableComponent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", Component::Translatable(self.clone())) // 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> { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
match self { match self {
StringOrComponent::String(s) => write!(f, "{}", s), StringOrComponent::String(s) => write!(f, "{}", s),