From 9cb0c414afc284947fc2b8494504387e4e7edd87 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sun, 16 Oct 2022 01:22:04 +0000 Subject: [PATCH 1/3] feat: log title show container name, closes #16 --- src/app_data/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 3821f99..cf7887a 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -253,11 +253,20 @@ impl AppData { } /// Get the title for log panel for selected container - /// will be "logs x/x" + /// will be either + /// 1) "logs x/x - container_name" where container_name is 32 chars max + /// 2) "logs - container_name" when no logs found, again 32 chars max pub fn get_log_title(&self) -> String { self.get_selected_log_index() .map_or("".to_owned(), |index| { - self.containers.items[index].logs.get_state_title() + let logs_len = self.containers.items[index].logs.get_state_title(); + let mut name = self.containers.items[index].name.clone(); + name.truncate(32); + if logs_len.is_empty() { + format!("- {} ", name) + } else { + format!("{} - {}", logs_len, name) + } }) } From a060d032586a0707ac91cb13d922aae0850449c5 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sun, 16 Oct 2022 01:23:02 +0000 Subject: [PATCH 2/3] refactor: Cpu+Mem stats use tuple struct --- src/app_data/container_state.rs | 41 +++++++++++++++------------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index b8b32b9..eebceb4 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -107,6 +107,7 @@ impl StatefulList { } } + /// Return the current status of the select list, e.g. 2/5, pub fn get_state_title(&self) -> String { if self.items.is_empty() { String::new() @@ -254,13 +255,11 @@ pub trait Stats { /// So can use custom display formatter /// Use trait Stats for use as generic in draw_chart function #[derive(Debug, Default, Clone, Copy)] -pub struct CpuStats { - value: f64, -} +pub struct CpuStats(f64); impl CpuStats { pub const fn new(value: f64) -> Self { - Self { value } + Self(value) } } @@ -268,21 +267,21 @@ impl Eq for CpuStats {} impl PartialEq for CpuStats { fn eq(&self, other: &Self) -> bool { - self.value == other.value + self.0 == other.0 } } impl PartialOrd for CpuStats { fn partial_cmp(&self, other: &Self) -> Option { - self.value.partial_cmp(&other.value) + self.0.partial_cmp(&other.0) } } impl Ord for CpuStats { fn cmp(&self, other: &Self) -> Ordering { - if self.value > other.value { + if self.0 > other.0 { Ordering::Greater - } else if (self.value - other.value).abs() < 0.01 { + } else if (self.0 - other.0).abs() < 0.01 { Ordering::Equal } else { Ordering::Less @@ -292,13 +291,13 @@ impl Ord for CpuStats { impl Stats for CpuStats { fn get_value(&self) -> f64 { - self.value + self.0 } } impl fmt::Display for CpuStats { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let disp = format!("{:05.2}%", self.value); + let disp = format!("{:05.2}%", self.0); write!(f, "{:>x$}", disp, x = f.width().unwrap_or(1)) } } @@ -307,41 +306,39 @@ impl fmt::Display for CpuStats { /// So can use custom display formatter /// Use trait Stats for use as generic in draw_chart function #[derive(Debug, Default, Clone, Copy, Eq)] -pub struct ByteStats { - value: u64, -} +pub struct ByteStats(u64); impl PartialEq for ByteStats { fn eq(&self, other: &Self) -> bool { - self.value == other.value + self.0 == other.0 } } impl PartialOrd for ByteStats { fn partial_cmp(&self, other: &Self) -> Option { - self.value.partial_cmp(&other.value) + self.0.partial_cmp(&other.0) } } impl Ord for ByteStats { fn cmp(&self, other: &Self) -> Ordering { - self.value.cmp(&other.value) + self.0.cmp(&other.0) } } impl ByteStats { pub const fn new(value: u64) -> Self { - Self { value } + Self(value) } pub fn update(&mut self, value: u64) { - self.value = value; + self.0 = value; } } #[allow(clippy::cast_precision_loss)] impl Stats for ByteStats { fn get_value(&self) -> f64 { - self.value as f64 + self.0 as f64 } } @@ -353,7 +350,7 @@ impl fmt::Display for ByteStats { 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.value), + _ => format!("{} B", self.0), }; write!(f, "{:>x$}", p, x = f.width().unwrap_or(1)) } @@ -426,7 +423,7 @@ impl ContainerItem { self.cpu_stats .iter() .enumerate() - .map(|i| (i.0 as f64, i.1.value as f64)) + .map(|i| (i.0 as f64, i.1.0 as f64)) .collect::>() } @@ -436,7 +433,7 @@ impl ContainerItem { self.mem_stats .iter() .enumerate() - .map(|i| (i.0 as f64, i.1.value as f64)) + .map(|i| (i.0 as f64, i.1.0 as f64)) .collect::>() } From c3e72ae7369a25d903f39e55a4349cb005671dd4 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sun, 16 Oct 2022 01:23:09 +0000 Subject: [PATCH 3/3] chore: cargo update --- Cargo.lock | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da58232..d183171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,9 +101,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.0.10" +version = "4.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1a0a4208c6c483b952ad35c6eed505fc13b46f08f631b81e828084a9318d74" +checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f" dependencies = [ "atty", "bitflags", @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.0.10" +version = "4.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db342ce9fda24fb191e2ed4e102055a4d381c1086a06630174cd8da8d5d917ce" +checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad" dependencies = [ "heck", "proc-macro-error", @@ -433,9 +433,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.134" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "lock_api" @@ -623,9 +623,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -712,9 +712,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" dependencies = [ "itoa", "ryu", @@ -1034,9 +1034,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" @@ -1072,9 +1072,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.1.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" dependencies = [ "getrandom", "rand",