Merge branch 'feat/log_container_name' into dev

This commit is contained in:
Jack Wills
2022-10-16 01:26:04 +00:00
3 changed files with 44 additions and 38 deletions
Generated
+14 -14
View File
@@ -101,9 +101,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.0.10" version = "4.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1a0a4208c6c483b952ad35c6eed505fc13b46f08f631b81e828084a9318d74" checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
@@ -118,9 +118,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.0.10" version = "4.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db342ce9fda24fb191e2ed4e102055a4d381c1086a06630174cd8da8d5d917ce" checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",
@@ -433,9 +433,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.134" version = "0.2.135"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
@@ -623,9 +623,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.46" version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -712,9 +712,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.85" version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@@ -1034,9 +1034,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.4" version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
@@ -1072,9 +1072,9 @@ dependencies = [
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.1.2" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"rand", "rand",
+19 -22
View File
@@ -107,6 +107,7 @@ impl<T> StatefulList<T> {
} }
} }
/// Return the current status of the select list, e.g. 2/5,
pub fn get_state_title(&self) -> String { pub fn get_state_title(&self) -> String {
if self.items.is_empty() { if self.items.is_empty() {
String::new() String::new()
@@ -254,13 +255,11 @@ pub trait Stats {
/// So can use custom display formatter /// So can use custom display formatter
/// Use trait Stats for use as generic in draw_chart function /// Use trait Stats for use as generic in draw_chart function
#[derive(Debug, Default, Clone, Copy)] #[derive(Debug, Default, Clone, Copy)]
pub struct CpuStats { pub struct CpuStats(f64);
value: f64,
}
impl CpuStats { impl CpuStats {
pub const fn new(value: f64) -> Self { pub const fn new(value: f64) -> Self {
Self { value } Self(value)
} }
} }
@@ -268,21 +267,21 @@ impl Eq for CpuStats {}
impl PartialEq for CpuStats { impl PartialEq for CpuStats {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.value == other.value self.0 == other.0
} }
} }
impl PartialOrd for CpuStats { impl PartialOrd for CpuStats {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.value.partial_cmp(&other.value) self.0.partial_cmp(&other.0)
} }
} }
impl Ord for CpuStats { impl Ord for CpuStats {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
if self.value > other.value { if self.0 > other.0 {
Ordering::Greater Ordering::Greater
} else if (self.value - other.value).abs() < 0.01 { } else if (self.0 - other.0).abs() < 0.01 {
Ordering::Equal Ordering::Equal
} else { } else {
Ordering::Less Ordering::Less
@@ -292,13 +291,13 @@ impl Ord for CpuStats {
impl Stats for CpuStats { impl Stats for CpuStats {
fn get_value(&self) -> f64 { fn get_value(&self) -> f64 {
self.value self.0
} }
} }
impl fmt::Display for CpuStats { impl fmt::Display for CpuStats {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 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)) 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 /// So can use custom display formatter
/// Use trait Stats for use as generic in draw_chart function /// Use trait Stats for use as generic in draw_chart function
#[derive(Debug, Default, Clone, Copy, Eq)] #[derive(Debug, Default, Clone, Copy, Eq)]
pub struct ByteStats { pub struct ByteStats(u64);
value: u64,
}
impl PartialEq for ByteStats { impl PartialEq for ByteStats {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.value == other.value self.0 == other.0
} }
} }
impl PartialOrd for ByteStats { impl PartialOrd for ByteStats {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.value.partial_cmp(&other.value) self.0.partial_cmp(&other.0)
} }
} }
impl Ord for ByteStats { impl Ord for ByteStats {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
self.value.cmp(&other.value) self.0.cmp(&other.0)
} }
} }
impl ByteStats { impl ByteStats {
pub const fn new(value: u64) -> Self { pub const fn new(value: u64) -> Self {
Self { value } Self(value)
} }
pub fn update(&mut self, value: u64) { pub fn update(&mut self, value: u64) {
self.value = value; self.0 = value;
} }
} }
#[allow(clippy::cast_precision_loss)] #[allow(clippy::cast_precision_loss)]
impl Stats for ByteStats { impl Stats for ByteStats {
fn get_value(&self) -> f64 { 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_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_MB => format!("{y:.2} MB", y = as_f64 / ONE_MB),
x if x >= ONE_KB => format!("{y:.2} kB", y = as_f64 / ONE_KB), 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)) write!(f, "{:>x$}", p, x = f.width().unwrap_or(1))
} }
@@ -426,7 +423,7 @@ impl ContainerItem {
self.cpu_stats self.cpu_stats
.iter() .iter()
.enumerate() .enumerate()
.map(|i| (i.0 as f64, i.1.value as f64)) .map(|i| (i.0 as f64, i.1.0 as f64))
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }
@@ -436,7 +433,7 @@ impl ContainerItem {
self.mem_stats self.mem_stats
.iter() .iter()
.enumerate() .enumerate()
.map(|i| (i.0 as f64, i.1.value as f64)) .map(|i| (i.0 as f64, i.1.0 as f64))
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }
+11 -2
View File
@@ -253,11 +253,20 @@ impl AppData {
} }
/// Get the title for log panel for selected container /// 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 { pub fn get_log_title(&self) -> String {
self.get_selected_log_index() self.get_selected_log_index()
.map_or("".to_owned(), |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)
}
}) })
} }