From 5cd56584b45a534b64ef83776b72d294305c32ee Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 22 Sep 2022 22:40:22 -0700 Subject: [PATCH] Completed terminal hyperlink clicking functionality. Just need to display it now --- Cargo.lock | 1 + crates/terminal/Cargo.toml | 2 ++ crates/terminal/src/terminal.rs | 17 +++++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 141a542bd2..34a1324a41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5386,6 +5386,7 @@ dependencies = [ "futures", "gpui", "itertools", + "lazy_static", "libc", "mio-extras", "ordered-float", diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.toml index eb1bc56017..da59979145 100644 --- a/crates/terminal/Cargo.toml +++ b/crates/terminal/Cargo.toml @@ -29,6 +29,8 @@ shellexpand = "2.1.0" libc = "0.2" anyhow = "1" thiserror = "1.0" +lazy_static = "1.4.0" + [dev-dependencies] diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index bf5c98d03c..ebbfd4fec3 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -64,6 +64,7 @@ use crate::mappings::{ colors::{get_color_at_index, to_alac_rgb}, keys::to_esc_str, }; +use lazy_static::lazy_static; ///Initialize and register all of our action handlers pub fn init(cx: &mut MutableAppContext) { @@ -83,8 +84,11 @@ const DEBUG_TERMINAL_HEIGHT: f32 = 30.; const DEBUG_CELL_WIDTH: f32 = 5.; const DEBUG_LINE_HEIGHT: f32 = 5.; -/// Copied from alacritty's ui_config.rs -static URL_REGEX: RegexSearch = RegexSearch::new("(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>\"\\s{-}\\^⟨⟩`]+").unwrap(); +// Regex Copied from alacritty's ui_config.rs + +lazy_static! { + static ref URL_REGEX: RegexSearch = RegexSearch::new("(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>\"\\s{-}\\^⟨⟩`]+").unwrap(); +} ///Upward flowing events, for changing the title and such #[derive(Clone, Copy, Debug)] @@ -659,6 +663,7 @@ impl Terminal { if let Some(url_match) = regex_match_at(term, point, &URL_REGEX) { let url = term.bounds_to_string(*url_match.start(), *url_match.end()); + dbg!(&url, &url_match, open); if *open { open_uri(&url).log_err(); @@ -956,12 +961,8 @@ impl Terminal { let position = e.position.sub(origin); if !self.mouse_mode(e.shift) { if e.cmd { - if let Some(link) = self.last_content.cells - [content_index_for_mouse(position, &self.last_content)] - .hyperlink() - { - dbg!(&link); - dbg!(&self.last_hovered_hyperlink); + let mouse_cell_index = content_index_for_mouse(position, &self.last_content); + if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() { open_uri(link.uri()).log_err(); } else { self.events