diff --git a/docs/overview.md b/docs/overview.md index e9914b3..5a95765 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -69,7 +69,7 @@ Use Nexus Terminal when you need to: - Find in terminal output, with case-sensitive and regular-expression options and a match counter. - Copy with Ctrl/Cmd+C when text is selected (otherwise it sends an interrupt), paste with Ctrl/Cmd+V. - Double-click selects a word, triple-click selects a line, Shift-click extends a selection. -- Ctrl/Cmd-click a web link to open it in your browser. +- Ctrl/Cmd-click a web link to open it in your browser, including OSC 8 hyperlinks (from `ls --hyperlink`, `git`, compilers…), which are underlined with a dotted line and show their real target on hover. Only http(s) links open. - Shift+PageUp/PageDown/Home/End and the mouse wheel scroll the scrollback; on the alternate screen the wheel sends arrow keys, so `tmux`, `screen` and `byobu` scroll naturally. - Context menu with Copy, Paste, Select All, Find, Send Snippet, Port Forwards, Split Right, Split Down, Export Output, Clear and Reset. - Export the whole scrollback as plain text. diff --git a/docs/user-manual.md b/docs/user-manual.md index a9b8b8c..04adf39 100644 --- a/docs/user-manual.md +++ b/docs/user-manual.md @@ -249,7 +249,7 @@ Shells that also report their working directory (OSC 7; fish, and zsh/bash with - **Copy**: select text and press **Cmd+C** / **Ctrl+C**. With nothing selected, **Ctrl+C** sends an interrupt as usual. - **Paste**: **Cmd+V** / **Ctrl+V**. Pastes are bracketed when the remote application asks for it. - **Select**: drag to select, double-click for a word, triple-click for a line, Shift-click to extend. -- **Links**: hold **Cmd** / **Ctrl** and click a web link to open it in your browser. +- **Links**: hold **Cmd** / **Ctrl** and click a web link to open it in your browser. Programs can also print real hyperlinks (OSC 8, as `ls --hyperlink` and many build tools do); these have a dotted underline, and hovering one shows where it really points. Only http(s) links are opened. - **Scroll**: the mouse wheel, or **Shift+PageUp**, **Shift+PageDown**, **Shift+Home** and **Shift+End**. On the alternate screen (for example in `tmux`, `screen`, `byobu` or `less`) the wheel sends arrow keys instead. - Applications that use the mouse (such as `htop`, `vim` or `tmux` with mouse mode) receive mouse clicks and the wheel directly. diff --git a/rust/app/src/terminal.rs b/rust/app/src/terminal.rs index 007f932..5b4236c 100644 --- a/rust/app/src/terminal.rs +++ b/rust/app/src/terminal.rs @@ -684,7 +684,8 @@ impl TermView { if modifiers.command && let Some(url) = self.url_at(origin, cw, ch, *pos) { - ui.ctx().open_url(egui::OpenUrl::new_tab(url)); + // Only web links: text from a remote host must not launch file: or custom-scheme handlers. + crate::widgets::open_web_url(ui.ctx(), &url); continue; } let now = ui.input(|i| i.time); @@ -738,9 +739,20 @@ impl TermView { _ => {} } } + // An OSC 8 link's text can say anything, so its real target is always shown on hover. + if let Some(p) = hover + && let Some(link) = self.hyperlink_at(self.point_at(origin, cw, ch, p).0) + { + egui::Tooltip::always_open(ui.ctx().clone(), ui.layer_id(), egui::Id::new("term-link"), egui::PopupAnchor::Pointer).show(|ui| { + ui.label(&link); + if !crate::widgets::is_web_url(&link) { + ui.label(egui::RichText::new("Not a web link — won't be opened").weak()); + } + }); + } if let Some(p) = hover && ui.input(|i| i.modifiers.command) - && self.url_at(origin, cw, ch, p).is_some() + && self.url_at(origin, cw, ch, p).is_some_and(|u| crate::widgets::is_web_url(&u)) { ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand); } else if hover.is_some() { @@ -748,8 +760,12 @@ impl TermView { } } + /// The link under `p`: an OSC 8 hyperlink on the cell, else a URL in the text. fn url_at(&self, origin: Pos2, cw: f32, ch: f32, p: Pos2) -> Option { let (point, _) = self.point_at(origin, cw, ch, p); + if let Some(link) = self.hyperlink_at(point) { + return Some(link); + } let (text, cols) = self.line_text(point.line); let re = regex::Regex::new(URL_RE).ok()?; re.find_iter(&text).find_map(|m| { @@ -759,6 +775,13 @@ impl TermView { }) } + fn hyperlink_at(&self, point: Point) -> Option { + let g = self.term.grid(); + (point.line >= g.topmost_line() && point.line <= g.bottommost_line() && point.column.0 < self.term.columns()) + .then(|| g[point].hyperlink().map(|h| h.uri().to_string())) + .flatten() + } + #[allow(clippy::too_many_arguments)] fn paint(&mut self, ui: &mut Ui, rect: Rect, origin: Pos2, font: &FontId, cw: f32, ch: f32, theme: &TermTheme, focused: bool) { let painter = ui.painter_at(rect); @@ -818,6 +841,13 @@ impl TermView { } if cell.flags.intersects(Flags::ALL_UNDERLINES) { painter.hline(cell_rect.x_range(), y + ch - 1.5, Stroke::new(1.0, fg)); + } else if cell.hyperlink().is_some() { + // OSC 8 links: a dotted underline. + let mut x0 = cell_rect.left(); + while x0 < cell_rect.right() { + painter.hline(x0..=(x0 + 1.5).min(cell_rect.right()), y + ch - 1.5, Stroke::new(1.0, fg.gamma_multiply(0.8))); + x0 += 3.0; + } } if cell.flags.contains(Flags::STRIKEOUT) { painter.hline(cell_rect.x_range(), y + ch * 0.55, Stroke::new(1.0, fg)); @@ -1136,6 +1166,17 @@ mod tests { assert!(t.prompts.len() <= 1); } + #[test] + fn osc8_links_are_found_on_their_cells() { + let mut t = TermView::new(100, 14.0, CursorStyle::Block); + t.feed(b"see \x1b]8;;https://example.com/docs\x1b\\the docs\x1b]8;;\x1b\\ now"); + let at = |c| t.hyperlink_at(Point::new(Line(0), Column(c))); + assert_eq!(at(4).as_deref(), Some("https://example.com/docs")); + assert_eq!(at(11).as_deref(), Some("https://example.com/docs")); + assert_eq!(at(12), None, "the link ends with its text"); + assert_eq!(at(0), None); + } + #[test] fn feeds_text_and_finds_it() { let mut t = TermView::new(1000, 14.0, CursorStyle::Block);