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/src/component.rs | |
| parent | c65e1fc6604baf308b8c2b20b94bf527a6721ade (diff) | |
| download | azalea-drasl-329f8b1784b26e2149f6edb4e969e10bd419a190.tar.xz | |
more docs
Diffstat (limited to 'azalea-chat/src/component.rs')
| -rwxr-xr-x | azalea-chat/src/component.rs | 18 |
1 files changed, 17 insertions, 1 deletions
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); |
