multiverse/widgets/
mod.rs1use itertools::Itertools;
2use ratatui::{prelude::*, widgets::WidgetRef};
3
4pub mod button;
5pub mod create_room;
6pub mod help;
7pub mod popup_input;
8pub mod recovery;
9pub mod room_list;
10pub mod room_view;
11pub mod search;
12pub mod settings;
13pub mod status;
14
15struct Hyperlink<'content> {
19 text: Text<'content>,
20 url: String,
21}
22
23impl<'content> Hyperlink<'content> {
24 fn new(text: impl Into<Text<'content>>, url: impl Into<String>) -> Self {
25 Self { text: text.into(), url: url.into() }
26 }
27}
28
29impl WidgetRef for Hyperlink<'_> {
30 fn render_ref(&self, area: Rect, buffer: &mut Buffer) {
31 (&self.text).render_ref(area, buffer);
32
33 for (i, two_chars) in self.text.to_string().chars().chunks(2).into_iter().enumerate() {
39 let text = two_chars.collect::<String>();
40 let hyperlink = format!("\x1B]8;;{}\x07{}\x1B]8;;\x07", self.url, text);
41 buffer[(area.x + i as u16 * 2, area.y)].set_symbol(hyperlink.as_str());
42 }
43 }
44}