use crate::errors::ShellError; use crate::object::process::Process; use crate::object::{ShellObject, Value}; use crate::prelude::*; use crate::Command; use derive_new::new; use std::cell::RefCell; use std::rc::Rc; use sysinfo::SystemExt; #[derive(new)] pub struct PsBlueprint; impl crate::CommandBlueprint for PsBlueprint { fn create( &self, args: Vec, host: &dyn crate::Host, env: &mut crate::Environment, ) -> Result, ShellError> { Ok(Box::new(Ps::new())) } } #[derive(new)] pub struct Ps; impl crate::Command for Ps { fn run(&mut self, stream: VecDeque) -> Result, ShellError> { let mut system = sysinfo::System::new(); system.refresh_all(); let list = system.get_process_list(); let list = list .into_iter() .map(|(_, process)| { ReturnValue::Value(Value::Object(Box::new(Process::new(process.clone())))) }) .collect::>(); Ok(list) } }