mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
2174f3d536
commit
5443aac767
2 changed files with 21 additions and 4 deletions
7
core/src/external/shell.rs
vendored
7
core/src/external/shell.rs
vendored
|
|
@ -10,6 +10,13 @@ pub struct ShellOpt {
|
||||||
pub orphan: bool,
|
pub orphan: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ShellOpt {
|
||||||
|
pub fn with_piped(mut self) -> Self {
|
||||||
|
self.piped = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn shell(opt: ShellOpt) -> Result<Child> {
|
pub fn shell(opt: ShellOpt) -> Result<Child> {
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use std::ffi::OsString;
|
use std::{ffi::OsString, mem};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::{mpsc, oneshot}};
|
use tokio::{io::{AsyncBufReadExt, BufReader}, select, sync::{mpsc, oneshot}};
|
||||||
|
|
@ -20,6 +20,17 @@ pub(crate) struct ProcessOpOpen {
|
||||||
pub cancel: oneshot::Sender<()>,
|
pub cancel: oneshot::Sender<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&mut ProcessOpOpen> for ShellOpt {
|
||||||
|
fn from(value: &mut ProcessOpOpen) -> Self {
|
||||||
|
Self {
|
||||||
|
cmd: mem::take(&mut value.cmd),
|
||||||
|
args: mem::take(&mut value.args),
|
||||||
|
piped: false,
|
||||||
|
orphan: value.orphan,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Process {
|
impl Process {
|
||||||
pub(crate) fn new(sch: mpsc::UnboundedSender<TaskOp>) -> Self { Self { sch } }
|
pub(crate) fn new(sch: mpsc::UnboundedSender<TaskOp>) -> Self { Self { sch } }
|
||||||
|
|
||||||
|
|
@ -30,12 +41,11 @@ impl Process {
|
||||||
fn done(&self, id: usize) -> Result<()> { Ok(self.sch.send(TaskOp::Done(id))?) }
|
fn done(&self, id: usize) -> Result<()> { Ok(self.sch.send(TaskOp::Done(id))?) }
|
||||||
|
|
||||||
pub(crate) async fn open(&self, mut task: ProcessOpOpen) -> Result<()> {
|
pub(crate) async fn open(&self, mut task: ProcessOpOpen) -> Result<()> {
|
||||||
let opt = ShellOpt { cmd: task.cmd, args: task.args, piped: true, orphan: task.orphan };
|
|
||||||
if task.block {
|
if task.block {
|
||||||
let _guard = BLOCKER.acquire().await.unwrap();
|
let _guard = BLOCKER.acquire().await.unwrap();
|
||||||
emit!(Stop(true)).await;
|
emit!(Stop(true)).await;
|
||||||
|
|
||||||
match external::shell(ShellOpt { piped: false, ..opt }) {
|
match external::shell(ShellOpt::from(&mut task)) {
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
child.wait().await.ok();
|
child.wait().await.ok();
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +60,7 @@ impl Process {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.sch.send(TaskOp::New(task.id, 0))?;
|
self.sch.send(TaskOp::New(task.id, 0))?;
|
||||||
let mut child = external::shell(opt)?;
|
let mut child = external::shell(ShellOpt::from(&mut task).with_piped())?;
|
||||||
|
|
||||||
let mut stdout = BufReader::new(child.stdout.take().unwrap()).lines();
|
let mut stdout = BufReader::new(child.stdout.take().unwrap()).lines();
|
||||||
let mut stderr = BufReader::new(child.stderr.take().unwrap()).lines();
|
let mut stderr = BufReader::new(child.stderr.take().unwrap()).lines();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue