feat: align memory columns correctly, closes #20
use kB as minimum bytestats unit, screenshot updated
This commit is contained in:
@@ -343,8 +343,7 @@ impl fmt::Display for ByteStats {
|
||||
let p = match as_f64 {
|
||||
x if x >= ONE_GB => format!("{y:.2} GB", y = as_f64 / ONE_GB),
|
||||
x if x >= ONE_MB => format!("{y:.2} MB", y = as_f64 / ONE_MB),
|
||||
x if x >= ONE_KB => format!("{y:.2} kB", y = as_f64 / ONE_KB),
|
||||
_ => format!("{} B", self.0),
|
||||
_ => format!("{y:.2} kB", y = as_f64 / ONE_KB),
|
||||
};
|
||||
write!(f, "{p:>x$}", x = f.width().unwrap_or(1))
|
||||
}
|
||||
@@ -463,15 +462,15 @@ impl ContainerItem {
|
||||
/// Container information panel headings + widths, for nice pretty formatting
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Columns {
|
||||
pub state: (Header, usize),
|
||||
pub status: (Header, usize),
|
||||
pub cpu: (Header, usize),
|
||||
pub mem: (Header, usize),
|
||||
pub id: (Header, usize),
|
||||
pub name: (Header, usize),
|
||||
pub image: (Header, usize),
|
||||
pub net_rx: (Header, usize),
|
||||
pub net_tx: (Header, usize),
|
||||
pub state: (Header, u8),
|
||||
pub status: (Header, u8),
|
||||
pub cpu: (Header, u8),
|
||||
pub mem: (Header, u8, u8),
|
||||
pub id: (Header, u8),
|
||||
pub name: (Header, u8),
|
||||
pub image: (Header, u8),
|
||||
pub net_rx: (Header, u8),
|
||||
pub net_tx: (Header, u8),
|
||||
}
|
||||
|
||||
impl Columns {
|
||||
@@ -482,7 +481,7 @@ impl Columns {
|
||||
status: (Header::Status, 16),
|
||||
// 7 to allow for "100.00%"
|
||||
cpu: (Header::Cpu, 7),
|
||||
mem: (Header::Memory, 12),
|
||||
mem: (Header::Memory, 6, 6),
|
||||
id: (Header::Id, 8),
|
||||
name: (Header::Name, 4),
|
||||
image: (Header::Image, 5),
|
||||
|
||||
+8
-8
@@ -364,7 +364,7 @@ impl AppData {
|
||||
/// So can display nicely and evenly
|
||||
pub fn get_width(&self) -> Columns {
|
||||
let mut output = Columns::new();
|
||||
let count = |x: &String| x.chars().count();
|
||||
let count = |x: &String| u8::try_from(x.chars().count()).unwrap_or(12);
|
||||
|
||||
// Should probably find a refactor here somewhere
|
||||
for container in &self.containers.items {
|
||||
@@ -375,11 +375,6 @@ impl AppData {
|
||||
.unwrap_or(&CpuStats::default())
|
||||
.to_string(),
|
||||
);
|
||||
let mem_count = count(&format!(
|
||||
"{} / {}",
|
||||
container.mem_stats.back().unwrap_or(&ByteStats::default()),
|
||||
container.mem_limit
|
||||
));
|
||||
|
||||
let rx_count = count(&container.rx.to_string());
|
||||
let tx_count = count(&container.tx.to_string());
|
||||
@@ -387,6 +382,8 @@ impl AppData {
|
||||
let name_count = count(&container.name);
|
||||
let state_count = count(&container.state.to_string());
|
||||
let status_count = count(&container.status);
|
||||
let mem_current_count = count(&container.mem_stats.back().unwrap_or(&ByteStats::default()).to_string());
|
||||
let mem_limit_count= count(&container.mem_limit.to_string());
|
||||
|
||||
if cpu_count > output.cpu.1 {
|
||||
output.cpu.1 = cpu_count;
|
||||
@@ -394,8 +391,11 @@ impl AppData {
|
||||
if image_count > output.image.1 {
|
||||
output.image.1 = image_count;
|
||||
};
|
||||
if mem_count > output.mem.1 {
|
||||
output.mem.1 = mem_count;
|
||||
if mem_current_count > output.mem.1 {
|
||||
output.mem.1 = mem_current_count;
|
||||
};
|
||||
if mem_limit_count > output.mem.2 {
|
||||
output.mem.2 = mem_limit_count;
|
||||
};
|
||||
if name_count > output.name.1 {
|
||||
output.name.1 = name_count;
|
||||
|
||||
Reference in New Issue
Block a user