Skip to content

Commit 0646850

Browse files
committed
feat(macos): support env column
1 parent ff43b7a commit 0646850

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/columns/env.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,21 @@ impl Column for Env {
6868

6969
column_default!(String, false);
7070
}
71+
72+
#[cfg(target_os = "macos")]
73+
impl Column for Env {
74+
fn add(&mut self, proc: &ProcessInfo) {
75+
let mut fmt_content = String::new();
76+
if let Some(path) = &proc.curr_path {
77+
for env in &path.env {
78+
fmt_content.push_str(&format!("{} ", env.replace('\"', "\\\"")));
79+
}
80+
};
81+
let raw_content = fmt_content.clone();
82+
83+
self.fmt_contents.insert(proc.pid, fmt_content);
84+
self.raw_contents.insert(proc.pid, raw_content);
85+
}
86+
87+
column_default!(String, false);
88+
}

src/columns/os_macos.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod cpu_time;
66
pub mod docker;
77
pub mod elapsed_time;
88
pub mod empty;
9+
pub mod env;
910
pub mod gid;
1011
pub mod gid_real;
1112
pub mod gid_saved;
@@ -54,6 +55,7 @@ pub use self::cpu_time::CpuTime;
5455
pub use self::docker::Docker;
5556
pub use self::elapsed_time::ElapsedTime;
5657
pub use self::empty::Empty;
58+
pub use self::env::Env;
5759
pub use self::gid::Gid;
5860
pub use self::gid_real::GidReal;
5961
pub use self::gid_saved::GidSaved;
@@ -113,6 +115,7 @@ pub enum ConfigColumnKind {
113115
Docker,
114116
ElapsedTime,
115117
Empty,
118+
Env,
116119
Gid,
117120
GidReal,
118121
GidSaved,
@@ -166,7 +169,7 @@ pub fn gen_column(
166169
separator: &str,
167170
abbr_sid: bool,
168171
tree_symbols: &[String; 5],
169-
_procfs: Option<PathBuf>,
172+
procfs: Option<PathBuf>,
170173
) -> Box<dyn Column> {
171174
match kind {
172175
ConfigColumnKind::Arch => Box::new(Arch::new(header)),
@@ -179,6 +182,7 @@ pub fn gen_column(
179182
ConfigColumnKind::Docker => Box::new(Empty::new()),
180183
ConfigColumnKind::ElapsedTime => Box::new(ElapsedTime::new(header)),
181184
ConfigColumnKind::Empty => Box::new(Empty::new()),
185+
ConfigColumnKind::Env => Box::new(Env::new(header, procfs)),
182186
ConfigColumnKind::Gid => Box::new(Gid::new(header, abbr_sid)),
183187
ConfigColumnKind::GidReal => Box::new(GidReal::new(header)),
184188
ConfigColumnKind::GidSaved => Box::new(GidSaved::new(header)),
@@ -250,6 +254,7 @@ pub static KIND_LIST: Lazy<BTreeMap<ConfigColumnKind, (&'static str, &'static st
250254
("ElapsedTime", "Elapsed time"),
251255
),
252256
(ConfigColumnKind::Empty, ("Empty", "Empty")),
257+
(ConfigColumnKind::Env, ("Env", "Environment variables")),
253258
(ConfigColumnKind::Gid, ("Gid", "Group ID")),
254259
(ConfigColumnKind::GidReal, ("GidReal", "Real group ID")),
255260
(ConfigColumnKind::GidSaved, ("GidSaved", "Saved group ID")),

0 commit comments

Comments
 (0)