chore: made text component clickable links clickable in console
This commit is contained in:
parent
3303bb7b97
commit
f19d84efef
@ -102,6 +102,10 @@ impl TextComponentBase {
|
|||||||
/// A formatted string ready for console output.
|
/// A formatted string ready for console output.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn to_pretty_console(self) -> String {
|
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 {
|
let mut text = match *self.content {
|
||||||
TextContent::Text { text } => text.into_owned(),
|
TextContent::Text { text } => text.into_owned(),
|
||||||
TextContent::Translate {
|
TextContent::Translate {
|
||||||
@ -133,6 +137,13 @@ impl TextComponentBase {
|
|||||||
if style.strikethrough.is_some() {
|
if style.strikethrough.is_some() {
|
||||||
text = text.strikethrough().to_string();
|
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 {
|
for child in self.extra {
|
||||||
text += &*child.to_pretty_console();
|
text += &*child.to_pretty_console();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -203,7 +203,7 @@ impl CommandExecutor for Executor {
|
|||||||
.add_child(
|
.add_child(
|
||||||
TextComponent::text("[Donate]")
|
TextComponent::text("[Donate]")
|
||||||
.click_event(ClickEvent::OpenUrl {
|
.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(
|
.hover_event(HoverEvent::show_text(TextComponent::text(
|
||||||
"Click to open Donate",
|
"Click to open Donate",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user