pub enum FormattedText {
Text(TextComponent),
Translatable(TranslatableComponent),
Keybind(KeybindComponent),
Score(ScoreComponent),
Selector(SelectorComponent),
Nbt(NbtComponent),
Object(ObjectComponent),
}Expand description
A chat component, basically anything you can see in chat.
Variants§
Text(TextComponent)
Translatable(TranslatableComponent)
Keybind(KeybindComponent)
Score(ScoreComponent)
Selector(SelectorComponent)
Nbt(NbtComponent)
Object(ObjectComponent)
Implementations§
Source§impl FormattedText
A chat component
impl FormattedText
A chat component
pub fn get_base_mut(&mut self) -> &mut BaseComponent
pub fn get_base(&self) -> &BaseComponent
Sourcepub fn append(&mut self, sibling: FormattedText)
pub fn append(&mut self, sibling: FormattedText)
Add a component as a sibling of this one.
pub fn extend(&mut self, siblings: impl IntoIterator<Item = FormattedText>)
Sourcepub fn to_custom_format<F, S, C>(
&self,
style_formatter: F,
text_formatter: S,
cleanup_formatter: C,
default_style: &Style,
) -> String
pub fn to_custom_format<F, S, C>( &self, style_formatter: F, text_formatter: S, cleanup_formatter: C, default_style: &Style, ) -> String
Render all components into a single String, using your custom
closures to drive styling, text transformation, and final cleanup.
§Type parameters
F:(running, component, default) -> (prefix, suffix)for per-component stylingS:&str -> Stringfor text tweaks (escaping, mapping, etc.)C:&final_running_style -> Stringfor any trailing cleanup
§Arguments
style_formatter: how to open/close each component’s styletext_formatter: how to turn raw text into output textcleanup_formatter: emit after all components (e.g. reset codes)default_style: where to reset when a component’sresetis true
§Example
use azalea_chat::{FormattedText, DEFAULT_STYLE};
use serde::de::Deserialize;
let component = FormattedText::deserialize(&serde_json::json!({
"text": "Hello, world!",
"color": "red",
})).unwrap();
let ansi = component.to_custom_format(
|running, new| (running.compare_ansi(new), "".to_owned()),
|text| text.to_string(),
|style| {
if !style.is_empty() {
"\u{1b}[m".to_owned()
} else {
"".to_owned()
}
},
&DEFAULT_STYLE,
);
println!("{ansi}");Sourcepub fn to_ansi_with_custom_style(&self, default_style: &Style) -> String
pub fn to_ansi_with_custom_style(&self, default_style: &Style) -> String
Convert this component into an ANSI string.
This is the same as FormattedText::to_ansi, but you can specify a
default Style to use.
Sourcepub fn to_ansi(&self) -> String
pub fn to_ansi(&self) -> String
Convert this component into an ANSI string, so you can print it to your terminal and get styling.
This is technically a shortcut for
FormattedText::to_ansi_with_custom_style with a default Style
colored white.
If you don’t want the result to be styled at all, use
Self::to_string.
§Examples
use azalea_chat::FormattedText;
use serde::de::Deserialize;
let component = FormattedText::deserialize(&serde_json::json!({
"text": "Hello, world!",
"color": "red",
})).unwrap();
println!("{}", component.to_ansi());Examples found in repository?
225async fn swarm_handle(_swarm: Swarm, event: SwarmEvent, _state: SwarmState) -> eyre::Result<()> {
226 match &event {
227 SwarmEvent::Disconnect(account, _join_opts) => {
228 println!("bot got kicked! {}", account.username());
229 }
230 SwarmEvent::Chat(chat) => {
231 if chat.message().to_string() == "The particle was not visible for anybody" {
232 return Ok(());
233 }
234 println!("{}", chat.message().to_ansi());
235 }
236 _ => {}
237 }
238
239 Ok(())
240}Sourcepub fn to_html(&self) -> String
pub fn to_html(&self) -> String
Similar to Self::to_ansi but renders the result as HTML instead.
Trait Implementations§
Source§impl AzBuf for FormattedText
Available on crate features azalea-buf and simdnbt only.
impl AzBuf for FormattedText
azalea-buf and simdnbt only.fn azalea_read( _ctx: Ctx<'_>, buf: &mut Cursor<&[u8]>, ) -> Result<Self, BufReadError>
fn azalea_write(&self, ctx: Ctx<'_>, buf: &mut impl Write) -> Result<()>
Source§impl Clone for FormattedText
impl Clone for FormattedText
Source§impl<O: Ops> Codec<O> for FormattedText
impl<O: Ops> Codec<O> for FormattedText
type Incomplete = IncompleteFormattedText<O>
Source§fn codec_read(ops: &O) -> ReadResult<Self>
fn codec_read(ops: &O) -> ReadResult<Self>
Source§fn codec_write(&self) -> WriteResult<O>
fn codec_write(&self) -> WriteResult<O>
Source§impl Debug for FormattedText
impl Debug for FormattedText
Source§impl Default for FormattedText
impl Default for FormattedText
Source§impl<O: Ops> Defaultable<O> for FormattedText
impl<O: Ops> Defaultable<O> for FormattedText
fn is_default(&self) -> bool
Source§impl<'de> Deserialize<'de> for FormattedText
impl<'de> Deserialize<'de> for FormattedText
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for FormattedText
impl Display for FormattedText
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Render the text in the component but without any formatting/styling.
If you want the text to be styled, consider using Self::to_ansi or
Self::to_html.
Source§impl From<&str> for FormattedText
impl From<&str> for FormattedText
Source§impl From<String> for FormattedText
impl From<String> for FormattedText
Source§impl From<TextComponent> for FormattedText
impl From<TextComponent> for FormattedText
Source§fn from(c: TextComponent) -> Self
fn from(c: TextComponent) -> Self
Source§impl From<TranslatableComponent> for FormattedText
impl From<TranslatableComponent> for FormattedText
Source§fn from(c: TranslatableComponent) -> Self
fn from(c: TranslatableComponent) -> Self
Source§impl IntoIterator for FormattedText
impl IntoIterator for FormattedText
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Recursively call the function for every component in this component
Source§type Item = FormattedText
type Item = FormattedText
Source§type IntoIter = IntoIter<<FormattedText as IntoIterator>::Item>
type IntoIter = IntoIter<<FormattedText as IntoIterator>::Item>
Source§impl PartialEq for FormattedText
impl PartialEq for FormattedText
Source§impl Serialize for FormattedText
impl Serialize for FormattedText
impl StructuralPartialEq for FormattedText
Auto Trait Implementations§
impl Forget for FormattedText
impl Freeze for FormattedTextwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<FormattedText>: Freeze,
*const Style is !null: Freeze,
PhantomData<Style>: Freeze,
PhantomData<PrimitiveOrComponent>: Freeze,
*const FormattedText is !null: Freeze,
NonZero<usize>: Freeze,
*const str is !null: Freeze,
PhantomData<str>: Freeze,
&'static str: Freeze,
impl Move for FormattedText
impl RefUnwindSafe for FormattedText
impl Send for FormattedText
impl Sync for FormattedText
impl Unpin for FormattedText
impl UnsafeUnpin for FormattedTextwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<FormattedText>: UnsafeUnpin,
*const Style is !null: UnsafeUnpin,
PhantomData<Style>: UnsafeUnpin,
PhantomData<PrimitiveOrComponent>: UnsafeUnpin,
*const FormattedText is !null: UnsafeUnpin,
NonZeroUsizeInner: UnsafeUnpin,
*const str is !null: UnsafeUnpin,
PhantomData<str>: UnsafeUnpin,
&'static str: UnsafeUnpin,
impl UnwindSafe for FormattedTextwhere
RawVecInner: UnwindSafe,
BoxRaw<Style>: UnwindSafe,
BoxRaw<FormattedText>: UnwindSafe,
NonZero<usize>: UnwindSafe,
BoxRaw<str>: UnwindSafe,
&'static str: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> FromTemplate for T
impl<T> FromTemplate for T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<A, B> Interchangeable<A> for B
impl<A, B> Interchangeable<A> for B
fn interchangeable_into(self) -> A
fn interchangeable_from(other: A) -> B
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<T> Template for T
impl<T> Template for T
§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a [Template::Output].§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more§impl<T> TypeData for T
impl<T> TypeData for T
§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
self.