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