Introduce an open function
And refactor some of the older code to simplify it Co-Authored-By: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
a789476c95
commit
5d23aaacc8
3 changed files with 12 additions and 36 deletions
|
@ -32,17 +32,14 @@ use mappings::mouse::{
|
||||||
|
|
||||||
use procinfo::LocalProcessInfo;
|
use procinfo::LocalProcessInfo;
|
||||||
use settings::{AlternateScroll, Settings, Shell, TerminalBlink};
|
use settings::{AlternateScroll, Settings, Shell, TerminalBlink};
|
||||||
use util::ResultExt;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::min,
|
cmp::min,
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
io,
|
|
||||||
ops::{Deref, Index, RangeInclusive, Sub},
|
ops::{Deref, Index, RangeInclusive, Sub},
|
||||||
os::unix::{prelude::AsRawFd, process::CommandExt},
|
os::unix::prelude::AsRawFd,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::Command,
|
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
@ -734,7 +731,7 @@ impl Terminal {
|
||||||
|
|
||||||
if let Some((url, url_match)) = found_url {
|
if let Some((url, url_match)) = found_url {
|
||||||
if *open {
|
if *open {
|
||||||
open_uri(&url).log_err();
|
util::open(&url);
|
||||||
} else {
|
} else {
|
||||||
self.update_hyperlink(prev_hyperlink, url, url_match);
|
self.update_hyperlink(prev_hyperlink, url, url_match);
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1072,7 @@ impl Terminal {
|
||||||
if self.selection_phase == SelectionPhase::Ended {
|
if self.selection_phase == SelectionPhase::Ended {
|
||||||
let mouse_cell_index = content_index_for_mouse(position, &self.last_content);
|
let mouse_cell_index = content_index_for_mouse(position, &self.last_content);
|
||||||
if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() {
|
if let Some(link) = self.last_content.cells[mouse_cell_index].hyperlink() {
|
||||||
open_uri(link.uri()).log_err();
|
util::open(link.uri());
|
||||||
} else {
|
} else {
|
||||||
self.events
|
self.events
|
||||||
.push_back(InternalEvent::FindHyperlink(position, true));
|
.push_back(InternalEvent::FindHyperlink(position, true));
|
||||||
|
@ -1234,31 +1231,6 @@ fn content_index_for_mouse<'a>(pos: Vector2F, content: &'a TerminalContent) -> u
|
||||||
line * content.size.columns() + col
|
line * content.size.columns() + col
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_uri(uri: &str) -> Result<(), std::io::Error> {
|
|
||||||
let mut command = Command::new("open");
|
|
||||||
command.arg(uri);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
command
|
|
||||||
.pre_exec(|| {
|
|
||||||
match libc::fork() {
|
|
||||||
-1 => return Err(io::Error::last_os_error()),
|
|
||||||
0 => (),
|
|
||||||
_ => libc::_exit(0),
|
|
||||||
}
|
|
||||||
|
|
||||||
if libc::setsid() == -1 {
|
|
||||||
return Err(io::Error::last_os_error());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.spawn()?
|
|
||||||
.wait()
|
|
||||||
.map(|_| ())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::{
|
||||||
|
|
|
@ -54,6 +54,14 @@ pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn open<P: AsRef<Path>>(path: P) {
|
||||||
|
let path_to_open = path.as_ref().to_string_lossy();
|
||||||
|
std::process::Command::new("open")
|
||||||
|
.arg(path_to_open.as_ref())
|
||||||
|
.spawn()
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn reveal_in_finder<P: AsRef<Path>>(path: P) {
|
pub fn reveal_in_finder<P: AsRef<Path>>(path: P) {
|
||||||
let path_to_reveal = path.as_ref().to_string_lossy();
|
let path_to_reveal = path.as_ref().to_string_lossy();
|
||||||
std::process::Command::new("open")
|
std::process::Command::new("open")
|
||||||
|
|
|
@ -121,7 +121,6 @@ impl Workspace {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod simple_message_notification {
|
pub mod simple_message_notification {
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
|
@ -150,10 +149,7 @@ pub mod simple_message_notification {
|
||||||
|_workspace: &mut Workspace, open_action: &OsOpen, _cx: &mut ViewContext<Workspace>| {
|
|_workspace: &mut Workspace, open_action: &OsOpen, _cx: &mut ViewContext<Workspace>| {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
let mut command = Command::new("open");
|
util::open(&open_action.0);
|
||||||
command.arg(open_action.0.clone());
|
|
||||||
|
|
||||||
command.spawn().ok();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue