Skip to content

Commit

Permalink
Fix test failure without docker #41
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Feb 18, 2020
1 parent e43c8f2 commit c80c5ec
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 240 deletions.
38 changes: 38 additions & 0 deletions src/columns/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::process::ProcessInfo;
use crate::{column_default, Column};
use std::cmp;
use std::collections::HashMap;

pub struct Empty {
header: String,
unit: String,
fmt_contents: HashMap<i32, String>,
raw_contents: HashMap<i32, String>,
width: usize,
}

impl Empty {
pub fn new() -> Self {
let header = String::from("");
let unit = String::from("");
Empty {
fmt_contents: HashMap::new(),
raw_contents: HashMap::new(),
width: 0,
header,
unit,
}
}
}

impl Column for Empty {
fn add(&mut self, proc: &ProcessInfo) {
let raw_content = String::from("");
let fmt_content = String::from("");

self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}

column_default!(String);
}
133 changes: 10 additions & 123 deletions src/columns/os_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod cpu_time;
#[cfg(feature = "docker")]
pub mod docker;
pub mod eip;
pub mod empty;
pub mod esp;
pub mod gid;
pub mod gid_fs;
Expand Down Expand Up @@ -71,6 +72,7 @@ pub use self::cpu_time::CpuTime;
#[cfg(feature = "docker")]
pub use self::docker::Docker;
pub use self::eip::Eip;
pub use self::empty::Empty;
pub use self::esp::Esp;
pub use self::gid::Gid;
pub use self::gid_fs::GidFs;
Expand Down Expand Up @@ -146,9 +148,9 @@ pub enum ConfigColumnKind {
Command,
ContextSw,
CpuTime,
#[cfg(feature = "docker")]
Docker,
Eip,
Empty,
Esp,
Gid,
GidFs,
Expand Down Expand Up @@ -229,7 +231,10 @@ pub fn gen_column(
ConfigColumnKind::CpuTime => Box::new(CpuTime::new()),
#[cfg(feature = "docker")]
ConfigColumnKind::Docker => Box::new(Docker::new(_docker_path)),
#[cfg(not(feature = "docker"))]
ConfigColumnKind::Docker => Box::new(Empty::new()),
ConfigColumnKind::Eip => Box::new(Eip::new()),
ConfigColumnKind::Empty => Box::new(Empty::new()),
ConfigColumnKind::Esp => Box::new(Esp::new()),
ConfigColumnKind::Gid => Box::new(Gid::new(abbr_sid)),
ConfigColumnKind::GidFs => Box::new(GidFs::new()),
Expand Down Expand Up @@ -312,12 +317,12 @@ lazy_static! {
ConfigColumnKind::CpuTime,
("CpuTime", "Cumulative CPU time")
),
#[cfg(feature = "docker")]
(
ConfigColumnKind::Docker,
("Docker", "Docker container name")
),
(ConfigColumnKind::Eip, ("Eip", "Instruction pointer")),
(ConfigColumnKind::Empty, ("Empty", "Empty")),
(ConfigColumnKind::Esp, ("Esp", "Stack pointer")),
(ConfigColumnKind::Gid, ("Gid", "Group ID")),
(ConfigColumnKind::GidFs, ("GidFs", "File system group ID")),
Expand Down Expand Up @@ -453,7 +458,6 @@ lazy_static! {
// CONFIG_DEFAULT
// ---------------------------------------------------------------------------------------------------------------------

#[cfg(feature = "docker")]
pub static CONFIG_DEFAULT: &str = r#"
[[columns]]
kind = "Pid"
Expand Down Expand Up @@ -578,126 +582,6 @@ numeric_search = false
nonnumeric_search = true
"#;

#[cfg(not(feature = "docker"))]
pub static CONFIG_DEFAULT: &str = r#"
[[columns]]
kind = "Pid"
style = "BrightYellow"
numeric_search = true
nonnumeric_search = false
[[columns]]
kind = "User"
style = "BrightGreen"
numeric_search = false
nonnumeric_search = true
[[columns]]
kind = "Separator"
style = "White"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "State"
style = "ByState"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "Nice"
style = "BrightMagenta"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "Tty"
style = "BrightWhite"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "UsageCpu"
style = "ByPercentage"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "UsageMem"
style = "ByPercentage"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "VmPeak"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "VmSize"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "VmRss"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "TcpPort"
style = "BrightCyan"
numeric_search = true
nonnumeric_search = false
max_width = 20
[[columns]]
kind = "UdpPort"
style = "BrightCyan"
numeric_search = true
nonnumeric_search = false
max_width = 20
[[columns]]
kind = "ReadBytes"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "WriteBytes"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "Slot"
style = "ByUnit"
numeric_search = false
nonnumeric_search = false
align = "Right"
[[columns]]
kind = "Separator"
style = "White"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "CpuTime"
style = "BrightCyan"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "StartTime"
style = "BrightMagenta"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "Separator"
style = "White"
numeric_search = false
nonnumeric_search = false
[[columns]]
kind = "Command"
style = "BrightWhite"
numeric_search = false
nonnumeric_search = true
"#;

// ---------------------------------------------------------------------------------------------------------------------
// CONFIG_ALL
// ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -723,6 +607,9 @@ style = "BrightMagenta"
kind = "Eip"
style = "BrightYellow"
[[columns]]
kind = "Empty"
style = "BrightYellow"
[[columns]]
kind = "Esp"
style = "BrightBlue"
[[columns]]
Expand Down
Loading

0 comments on commit c80c5ec

Please sign in to comment.