mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
have Display implemented for the Components
This commit is contained in:
parent
6924502bc4
commit
3fbbe5e93d
3 changed files with 32 additions and 19 deletions
|
@ -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)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
match self {
|
||||
Component::Text(c) => c.fmt(f),
|
||||
Component::Translatable(c) => c.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue