From 69ecbc5291d8b6d2fd77fdbb19cc3154239bee0a Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 Apr 2025 00:08:09 +0200 Subject: [PATCH] feat: Expose the pid of the running process to the lua api. --- yazi-plugin/src/process/child.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/yazi-plugin/src/process/child.rs b/yazi-plugin/src/process/child.rs index e28432aa..26e14679 100644 --- a/yazi-plugin/src/process/child.rs +++ b/yazi-plugin/src/process/child.rs @@ -2,14 +2,18 @@ use std::{ops::DerefMut, time::Duration}; use futures::future::try_join3; use mlua::{AnyUserData, ExternalError, IntoLua, IntoLuaMulti, Table, UserData, Value}; -use tokio::{io::{self, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}, process::{ChildStderr, ChildStdin, ChildStdout}, select}; +use tokio::{ + io::{self, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}, + process::{ChildStderr, ChildStdin, ChildStdout}, + select, +}; use super::Status; use crate::{Error, process::Output}; pub struct Child { - inner: tokio::process::Child, - stdin: Option>, + inner: tokio::process::Child, + stdin: Option>, stdout: Option>, stderr: Option>, } @@ -149,5 +153,10 @@ impl UserData for Child { Some(stderr) => lua.create_any_userdata(stderr.into_inner())?.into_lua(lua), None => Ok(Value::Nil), }); + + methods.add_method_mut("id", |_, me, ()| match me.inner.id() { + Some(id) => Ok(Value::Integer(id as i64)), + None => Ok(Value::Nil), + }); } }