aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-09-05 01:04:16 -0500
committermat <github@matdoes.dev>2022-09-05 01:04:16 -0500
commit9ca95194696f8e9ef3ca84420f5d3b5082ff70ca (patch)
tree4f65aec60b121bbd7ed4fa4b1436b98e301d43ba /azalea-chat/src
parent4f00ddace08bd5ad17500a405f55554dff343be7 (diff)
downloadazalea-drasl-9ca95194696f8e9ef3ca84420f5d3b5082ff70ca.tar.xz
.walk :)
Diffstat (limited to 'azalea-chat/src')
-rwxr-xr-xazalea-chat/src/component.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 9c71b9df..59b1779e 100755
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -1,4 +1,7 @@
-use std::io::{Read, Write};
+use std::{
+ fmt::Display,
+ io::{Read, Write},
+};
use azalea_buf::{BufReadError, McBufReadable, McBufWritable};
use serde::{de, Deserialize, Deserializer};
@@ -293,3 +296,28 @@ impl McBufWritable for Component {
todo!()
}
}
+
+impl From<String> for Component {
+ fn from(s: String) -> Self {
+ Component::Text(TextComponent {
+ text: s,
+ base: BaseComponent::default(),
+ })
+ }
+}
+
+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(())
+ }
+}