2019-05-10 18:59:12 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-05-15 23:44:06 +02:00
|
|
|
use crate::object::process::process_dict;
|
2019-05-16 00:23:36 +02:00
|
|
|
use crate::object::Value;
|
2019-05-13 19:30:51 +02:00
|
|
|
use crate::prelude::*;
|
2019-05-10 18:59:12 +02:00
|
|
|
use derive_new::new;
|
|
|
|
use sysinfo::SystemExt;
|
|
|
|
|
|
|
|
#[derive(new)]
|
2019-05-15 18:12:38 +02:00
|
|
|
pub struct Ps;
|
2019-05-10 18:59:12 +02:00
|
|
|
|
|
|
|
impl crate::Command for Ps {
|
2019-05-16 02:21:46 +02:00
|
|
|
fn run(&self, _args: CommandArgs<'caller>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
2019-05-15 18:12:38 +02:00
|
|
|
let mut system = sysinfo::System::new();
|
2019-05-11 10:08:21 +02:00
|
|
|
system.refresh_all();
|
2019-05-10 18:59:12 +02:00
|
|
|
|
2019-05-11 10:08:21 +02:00
|
|
|
let list = system.get_process_list();
|
2019-05-10 18:59:12 +02:00
|
|
|
|
|
|
|
let list = list
|
|
|
|
.into_iter()
|
2019-05-15 23:44:06 +02:00
|
|
|
.map(|(_, process)| ReturnValue::Value(Value::Object(process_dict(process))))
|
2019-05-13 19:30:51 +02:00
|
|
|
.collect::<VecDeque<_>>();
|
2019-05-10 18:59:12 +02:00
|
|
|
|
2019-05-13 19:30:51 +02:00
|
|
|
Ok(list)
|
2019-05-10 18:59:12 +02:00
|
|
|
}
|
|
|
|
}
|