mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 14:22:37 +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,
|
||||
MouseEvent, MouseEventKind, TerminalHost, Underline};
|
||||
use term::color::RgbColor;
|
||||
use term::hyperlink::Hyperlink;
|
||||
use xcb;
|
||||
use xcb_util;
|
||||
use xgfx::{self, BitmapImage, Connection, Drawable};
|
||||
@ -112,6 +113,10 @@ impl<'a> term::TerminalHost for Host<'a> {
|
||||
&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
|
||||
// background on what's happening in here.
|
||||
fn get_clipboard(&mut self) -> Result<String, Error> {
|
||||
|
@ -16,6 +16,9 @@ pub trait TerminalHost {
|
||||
|
||||
/// Change the title of the window
|
||||
fn set_title(&mut self, title: &str);
|
||||
|
||||
/// Called when a URL is clicked
|
||||
fn click_link(&mut self, link: &Rc<Hyperlink>);
|
||||
}
|
||||
|
||||
pub struct Terminal {
|
||||
|
@ -327,12 +327,20 @@ impl TerminalState {
|
||||
// The double/triple click cases are handled above.
|
||||
Some(&LastMouseClick { streak: 1, .. }) => {
|
||||
let text = self.get_selection_text();
|
||||
if text.len() > 0 {
|
||||
debug!(
|
||||
"finish drag selection {:?} '{}'",
|
||||
self.selection_range,
|
||||
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(());
|
||||
}
|
||||
_ => {}
|
||||
|
@ -33,6 +33,8 @@ impl TerminalHost for TestHost {
|
||||
fn writer(&mut self) -> &mut std::io::Write {
|
||||
panic!("no writer support in TestHost");
|
||||
}
|
||||
|
||||
fn click_link(&mut self, _link: &Rc<Hyperlink>) {}
|
||||
}
|
||||
|
||||
macro_rules! assert_cursor_pos {
|
||||
|
Loading…
Reference in New Issue
Block a user