mirror of
https://github.com/nushell/nushell.git
synced 2025-05-25 00:51:18 +00:00
52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::errors::ShellError;
|
|
use crate::object::process::process_dict;
|
|
use crate::prelude::*;
|
|
use sysinfo::SystemExt;
|
|
|
|
pub struct PS;
|
|
|
|
impl WholeStreamCommand for PS {
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
ps(args, registry)
|
|
}
|
|
|
|
fn name(&self) -> &str {
|
|
"ps"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("ps")
|
|
}
|
|
}
|
|
|
|
fn ps(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
let system;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
{
|
|
system = sysinfo::System::new();
|
|
}
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
{
|
|
use sysinfo::RefreshKind;
|
|
let mut sy = sysinfo::System::new_with_specifics(RefreshKind::new().with_processes());
|
|
sy.refresh_processes();
|
|
|
|
system = sy;
|
|
}
|
|
let list = system.get_process_list();
|
|
|
|
let list = list
|
|
.into_iter()
|
|
.map(|(_, process)| process_dict(process, Tag::unknown_origin(args.call_info.name_span)))
|
|
.collect::<VecDeque<_>>();
|
|
|
|
Ok(list.from_input_stream())
|
|
}
|