diff options
| author | mat <github@matdoes.dev> | 2022-10-30 15:28:19 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-10-30 15:28:19 -0500 |
| commit | 329f8b1784b26e2149f6edb4e969e10bd419a190 (patch) | |
| tree | 89c641aa1c26bb8da9e1f23337ff3114ad52b8f2 /azalea-chat | |
| parent | c65e1fc6604baf308b8c2b20b94bf527a6721ade (diff) | |
| download | azalea-drasl-329f8b1784b26e2149f6edb4e969e10bd419a190.tar.xz | |
more docs
Diffstat (limited to 'azalea-chat')
| -rwxr-xr-x | azalea-chat/src/base_component.rs | 2 | ||||
| -rwxr-xr-x | azalea-chat/src/component.rs | 18 | ||||
| -rwxr-xr-x | azalea-chat/src/lib.rs | 4 | ||||
| -rw-r--r-- | azalea-chat/src/text_component.rs | 3 | ||||
| -rw-r--r-- | azalea-chat/src/translatable_component.rs | 4 | ||||
| -rwxr-xr-x | azalea-chat/tests/integration_test.rs | 2 |
6 files changed, 26 insertions, 7 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, diff --git a/azalea-chat/tests/integration_test.rs b/azalea-chat/tests/integration_test.rs index c2be960e..cc976888 100755 --- a/azalea-chat/tests/integration_test.rs +++ b/azalea-chat/tests/integration_test.rs @@ -1,6 +1,6 @@ use azalea_chat::{ - component::Component, style::{Ansi, ChatFormatting, TextColor}, + Component, }; use serde::Deserialize; use serde_json::Value; |
