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-06-23 19:21:09 +02:00
|
|
|
use sysinfo::{RefreshKind, SystemExt};
|
2019-05-10 18:59:12 +02:00
|
|
|
|
2019-07-08 18:44:53 +02:00
|
|
|
pub fn ps(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
2019-06-23 19:21:09 +02:00
|
|
|
let mut system = sysinfo::System::new_with_specifics(RefreshKind::new().with_processes());
|
|
|
|
system.refresh_processes();
|
2019-05-22 09:12:03 +02:00
|
|
|
let list = system.get_process_list();
|
2019-05-10 18:59:12 +02:00
|
|
|
|
2019-05-22 09:12:03 +02:00
|
|
|
let list = list
|
|
|
|
.into_iter()
|
2019-07-09 06:31:26 +02:00
|
|
|
.map(|(item, process)| process_dict(process, args.name_span))
|
2019-05-22 09:12:03 +02:00
|
|
|
.collect::<VecDeque<_>>();
|
2019-05-10 18:59:12 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
Ok(list.from_input_stream())
|
2019-05-10 18:59:12 +02:00
|
|
|
}
|