mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 22:33:52 +03:00
Recognize clicks on hyperlinks
There's plumbing for handling these events in the TerminalHost trait, but we don't do anything beyond printing them at the moment.
This commit is contained in:
parent
b6aa2cffea
commit
21f0e3fd98
@ -13,6 +13,7 @@ use std::slice;
|
|||||||
use term::{self, CellAttributes, CursorPosition, KeyCode, KeyModifiers, Line, MouseButton,
|
use term::{self, CellAttributes, CursorPosition, KeyCode, KeyModifiers, Line, MouseButton,
|
||||||
MouseEvent, MouseEventKind, TerminalHost, Underline};
|
MouseEvent, MouseEventKind, TerminalHost, Underline};
|
||||||
use term::color::RgbColor;
|
use term::color::RgbColor;
|
||||||
|
use term::hyperlink::Hyperlink;
|
||||||
use xcb;
|
use xcb;
|
||||||
use xcb_util;
|
use xcb_util;
|
||||||
use xgfx::{self, BitmapImage, Connection, Drawable};
|
use xgfx::{self, BitmapImage, Connection, Drawable};
|
||||||
@ -112,6 +113,10 @@ impl<'a> term::TerminalHost for Host<'a> {
|
|||||||
&mut self.pty
|
&mut self.pty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn click_link(&mut self, link: &Rc<Hyperlink>) {
|
||||||
|
println!("clicked on link: {:?}", link);
|
||||||
|
}
|
||||||
|
|
||||||
// Check out https://tronche.com/gui/x/icccm/sec-2.html for some deep and complex
|
// Check out https://tronche.com/gui/x/icccm/sec-2.html for some deep and complex
|
||||||
// background on what's happening in here.
|
// background on what's happening in here.
|
||||||
fn get_clipboard(&mut self) -> Result<String, Error> {
|
fn get_clipboard(&mut self) -> Result<String, Error> {
|
||||||
|
@ -16,6 +16,9 @@ pub trait TerminalHost {
|
|||||||
|
|
||||||
/// Change the title of the window
|
/// Change the title of the window
|
||||||
fn set_title(&mut self, title: &str);
|
fn set_title(&mut self, title: &str);
|
||||||
|
|
||||||
|
/// Called when a URL is clicked
|
||||||
|
fn click_link(&mut self, link: &Rc<Hyperlink>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Terminal {
|
pub struct Terminal {
|
||||||
|
@ -327,12 +327,20 @@ impl TerminalState {
|
|||||||
// The double/triple click cases are handled above.
|
// The double/triple click cases are handled above.
|
||||||
Some(&LastMouseClick { streak: 1, .. }) => {
|
Some(&LastMouseClick { streak: 1, .. }) => {
|
||||||
let text = self.get_selection_text();
|
let text = self.get_selection_text();
|
||||||
|
if text.len() > 0 {
|
||||||
debug!(
|
debug!(
|
||||||
"finish drag selection {:?} '{}'",
|
"finish drag selection {:?} '{}'",
|
||||||
self.selection_range,
|
self.selection_range,
|
||||||
text
|
text
|
||||||
);
|
);
|
||||||
host.set_clipboard(Some(text))?;
|
host.set_clipboard(Some(text))?;
|
||||||
|
} else {
|
||||||
|
// If the button release wasn't a drag, consider
|
||||||
|
// whether it was a click on a hyperlink
|
||||||
|
if let Some(link) = self.current_highlight() {
|
||||||
|
host.click_link(&link);
|
||||||
|
}
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -33,6 +33,8 @@ impl TerminalHost for TestHost {
|
|||||||
fn writer(&mut self) -> &mut std::io::Write {
|
fn writer(&mut self) -> &mut std::io::Write {
|
||||||
panic!("no writer support in TestHost");
|
panic!("no writer support in TestHost");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn click_link(&mut self, _link: &Rc<Hyperlink>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_cursor_pos {
|
macro_rules! assert_cursor_pos {
|
||||||
|
Loading…
Reference in New Issue
Block a user