Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ build = [
]

[dependencies]
colored = "3.1"
rand = { version = "0.10", default-features = false, features = [
"std",
"thread_rng",
] }
serde = { version = "1.0", features = ["derive"], optional = true }
simdnbt = { version = "0.10", optional = true }
uuid = { version = "1.23", features = ["v4", "serde"] }
supports-hyperlinks = "3.2.0"
# Build dependencies
heck = { version = "0.5", optional = true }
proc-macro2 = { version = "1.0", optional = true }
quote = { version = "1.0", optional = true }
rustc-hash = { version = "2.1", optional = true }
serde_json = { version = "1.0", optional = true }
uuid = { version = "1.23", features = ["v4", "serde"] }
supports-hyperlinks = "3.2"
serde_json = { version = "1.0.149", optional = true }
memchr = "2.8"
smallvec = "1.15"
ownable = { version = "1.0", optional = true }
Expand Down
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ component.resolve(resolutor).serialize(serializer);

### Displaying TextComponents

TextComponent implements Display for easy logging, as you can see, a component
TextComponent implements ToString for easy logging, as you can see, a component
needs to be resolved before building it into any format, by default it uses a static
reference to NoResolutor, but can be changed to a custom one with:\
(Resolutor must be static, or made inside the function call)
Expand All @@ -55,12 +55,20 @@ reference to NoResolutor, but can be changed to a custom one with:\
set_display_resolutor(&Resolutor);
```


A text component can be printed like a string like this:

```rs
println!("{}", component);
// With format (pretty):
println!("{:p}", component);
println!("{}", component.to_string());
// With format (colorful):
println!("{}", component.log());
```

If you want the log display format different to be able to parse it later, it can be done through `set_display_builder`,
which will need a function returning the built string, this is an example with the PrettyTextBuilder (the default one):

```rs
set_display_builder(|component, resolutor| component.build(resolutor, PrettyTextBuilder))
```

### Roadmap
Expand Down
4 changes: 2 additions & 2 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ fn main() {
"\nNBT (SNBT):\ntellraw @a {}",
component.build(&EmptyResolutor, NbtBuilder).to_snbt()
);
println!("\nText:\n{}", component);
println!("\nPretty Text:\n{:p}", component);
println!("\nText:\n{}", component.to_string());
println!("\nPretty Text:\n{}", component.log());
}
4 changes: 2 additions & 2 deletions examples/nbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<(), String> {
"tellraw @p {}",
component.build(&NoResolutor, NbtBuilder).to_snbt()
);
println!("{:p}", component);
println!("{}", component.log());

let nbt = "Holly molly I can get TextComponents from NBTs!"
.color(Color::Red)
Expand All @@ -41,6 +41,6 @@ fn main() -> Result<(), String> {
let component = RawTextComponent::from_nbt(&nbt)
.ok_or(String::from("Cannot recompose the TextComponent!"))?;
println!("{:?}", component);
println!("{:p}", component);
println!("{}", component.log());
Ok(())
}
2 changes: 1 addition & 1 deletion examples/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fn main() {
}",
)
.unwrap();
println!("{:p}", component)
println!("{}", component.log())
}
2 changes: 1 addition & 1 deletion examples/snbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
match component {
Ok(component) => {
println!("{:?}", component);
println!("{:p}", component)
println!("{}", component.log())
}
Err(e) => eprintln!("{}", e),
}
Expand Down
1 change: 1 addition & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub fn build_translations(path: &str) -> TokenStream {
let const_name = Ident::new(&const_name_str, Span::call_site());

stream.extend(quote! {
#[doc = #text]
pub static #const_name: Translation<#param_count> = Translation(#key);
});
}
Expand Down
Loading
Loading