aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-chat/src')
-rwxr-xr-xazalea-chat/src/base_component.rs2
-rwxr-xr-xazalea-chat/src/component.rs18
-rwxr-xr-xazalea-chat/src/lib.rs4
-rw-r--r--azalea-chat/src/text_component.rs3
-rw-r--r--azalea-chat/src/translatable_component.rs4
5 files changed, 25 insertions, 6 deletions
diff --git a/azalea-chat/src/base_component.rs b/azalea-chat/src/base_component.rs
index fa39a11c..c2f3513d 100755
--- a/azalea-chat/src/base_component.rs
+++ b/azalea-chat/src/base_component.rs
@@ -1,4 +1,4 @@
-use crate::{component::Component, style::Style};
+use crate::{style::Style, Component};
#[derive(Clone, Debug)]
pub struct BaseComponent {
diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs
index 6dd11084..4df3796f 100755
--- a/azalea-chat/src/component.rs
+++ b/azalea-chat/src/component.rs
@@ -13,6 +13,7 @@ use crate::{
translatable_component::{StringOrComponent, TranslatableComponent},
};
+/// A chat component, basically anything you can see in chat.
#[derive(Clone, Debug)]
pub enum Component {
Text(TextComponent),
@@ -57,7 +58,22 @@ impl Component {
Ok(None)
}
- /// Convert this component into an ansi string
+ /// Convert this component into an
+ /// [ANSI string](https://en.wikipedia.org/wiki/ANSI_escape_code), so you
+ /// can print it to your terminal and get styling.
+ ///
+ /// # Examples
+ ///
+ /// ```rust
+ /// use azalea_chat::Component;
+ ///
+ /// let component = Component::deserialize(&serde_json::json!({
+ /// "text": "Hello, world!",
+ /// "color": "red",
+ /// })).unwrap();
+ ///
+ /// println!("{}", component.to_ansi());
+ /// ```
pub fn to_ansi(&self, default_style: Option<&Style>) -> String {
// default the default_style to white if it's not set
let default_style: &Style = default_style.unwrap_or(&DEFAULT_STYLE);
diff --git a/azalea-chat/src/lib.rs b/azalea-chat/src/lib.rs
index b7035e13..01f718eb 100755
--- a/azalea-chat/src/lib.rs
+++ b/azalea-chat/src/lib.rs
@@ -5,7 +5,9 @@
extern crate lazy_static;
pub mod base_component;
-pub mod component;
+mod component;
pub mod style;
pub mod text_component;
pub mod translatable_component;
+
+pub use component::Component;
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs
index 96eef08e..46cb0951 100644
--- a/azalea-chat/src/text_component.rs
+++ b/azalea-chat/src/text_component.rs
@@ -1,7 +1,8 @@
use std::fmt::Display;
-use crate::{base_component::BaseComponent, component::Component, style::ChatFormatting};
+use crate::{base_component::BaseComponent, style::ChatFormatting, Component};
+/// A component that contains text that's the same in all locales.
#[derive(Clone, Debug)]
pub struct TextComponent {
pub base: BaseComponent,
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index 7c01819b..d187adda 100644
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -1,8 +1,7 @@
use std::fmt::{self, Display, Formatter};
use crate::{
- base_component::BaseComponent, component::Component, style::Style,
- text_component::TextComponent,
+ base_component::BaseComponent, style::Style, text_component::TextComponent, Component,
};
#[derive(Clone, Debug)]
@@ -11,6 +10,7 @@ pub enum StringOrComponent {
Component(Component),
}
+/// A message whose content depends on the client's language.
#[derive(Clone, Debug)]
pub struct TranslatableComponent {
pub base: BaseComponent,