mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
chore: made text component clickable links clickable in console
This commit is contained in:
@@ -102,6 +102,10 @@ impl TextComponentBase {
|
||||
/// A formatted string ready for console output.
|
||||
#[must_use]
|
||||
pub fn to_pretty_console(self) -> String {
|
||||
fn osc8_link(url: &str, text: &str) -> String {
|
||||
format!("\x1b]8;;{url}\x1b\\{text}\x1b]8;;\x1b\\")
|
||||
}
|
||||
|
||||
let mut text = match *self.content {
|
||||
TextContent::Text { text } => text.into_owned(),
|
||||
TextContent::Translate {
|
||||
@@ -133,6 +137,13 @@ impl TextComponentBase {
|
||||
if style.strikethrough.is_some() {
|
||||
text = text.strikethrough().to_string();
|
||||
}
|
||||
if let Some(ClickEvent::OpenUrl { url }) = style.click_event.as_ref() {
|
||||
text = osc8_link(url, &text);
|
||||
}
|
||||
if let Some(ClickEvent::OpenFile { path }) = style.click_event.as_ref() {
|
||||
text = osc8_link(&format!("file://{path}"), &text);
|
||||
}
|
||||
|
||||
for child in self.extra {
|
||||
text += &*child.to_pretty_console();
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ impl CommandExecutor for Executor {
|
||||
.add_child(
|
||||
TextComponent::text("[Donate]")
|
||||
.click_event(ClickEvent::OpenUrl {
|
||||
url: Cow::from("https://github.com/sponsors/Pumpkin-MC"),
|
||||
url: Cow::from("https://pumpkinmc.org/donate/"),
|
||||
})
|
||||
.hover_event(HoverEvent::show_text(TextComponent::text(
|
||||
"Click to open Donate",
|
||||
|
||||
Reference in New Issue
Block a user