refactor: string_wrapper .get() return &str
This commit is contained in:
@@ -47,6 +47,52 @@ impl PartialOrd for ContainerId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO - use string_wrapper for ContainerId?
|
||||||
|
/// ContainerName and ContainerImage are simple structs, used so can implement custom fmt functions to them
|
||||||
|
macro_rules! string_wrapper {
|
||||||
|
($name:ident) => {
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub struct $name(String);
|
||||||
|
|
||||||
|
impl From<String> for $name {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
Self(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl$name {
|
||||||
|
pub fn get(&self) -> &str {
|
||||||
|
self.0.as_str()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&mut self, value: String) {
|
||||||
|
self.0 = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for $name {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
if self.0.chars().count() >= 30 {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}…",
|
||||||
|
self.0.chars().take(29).collect::<String>()
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}",
|
||||||
|
self.0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
string_wrapper!(ContainerName);
|
||||||
|
string_wrapper!(ContainerImage);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct StatefulList<T> {
|
pub struct StatefulList<T> {
|
||||||
pub state: ListState,
|
pub state: ListState,
|
||||||
@@ -428,51 +474,6 @@ impl Logs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ContainerName and ContainerImage are simple structs, used so can implement custom fmt functions to them
|
|
||||||
macro_rules! string_wrapper {
|
|
||||||
($name:ident) => {
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct $name(String);
|
|
||||||
|
|
||||||
impl From<String> for $name {
|
|
||||||
fn from(value: String) -> Self {
|
|
||||||
Self(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl$name {
|
|
||||||
pub fn get(&self) -> String {
|
|
||||||
self.0.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set(&mut self, value: String) {
|
|
||||||
self.0 = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for $name {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
if self.0.chars().count() >= 30 {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}…",
|
|
||||||
self.0.chars().take(29).collect::<String>()
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}",
|
|
||||||
self.0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
string_wrapper!(ContainerName);
|
|
||||||
string_wrapper!(ContainerImage);
|
|
||||||
|
|
||||||
/// Info for each container
|
/// Info for each container
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ContainerItem {
|
pub struct ContainerItem {
|
||||||
|
|||||||
+12
-12
@@ -171,52 +171,52 @@ impl AppData {
|
|||||||
.state
|
.state
|
||||||
.order()
|
.order()
|
||||||
.cmp(&item_ord.1.state.order())
|
.cmp(&item_ord.1.state.order())
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Status => item_ord
|
Header::Status => item_ord
|
||||||
.0
|
.0
|
||||||
.status
|
.status
|
||||||
.cmp(&item_ord.1.status)
|
.cmp(&item_ord.1.status)
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Cpu => item_ord
|
Header::Cpu => item_ord
|
||||||
.0
|
.0
|
||||||
.cpu_stats
|
.cpu_stats
|
||||||
.back()
|
.back()
|
||||||
.cmp(&item_ord.1.cpu_stats.back())
|
.cmp(&item_ord.1.cpu_stats.back())
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Memory => item_ord
|
Header::Memory => item_ord
|
||||||
.0
|
.0
|
||||||
.mem_stats
|
.mem_stats
|
||||||
.back()
|
.back()
|
||||||
.cmp(&item_ord.1.mem_stats.back())
|
.cmp(&item_ord.1.mem_stats.back())
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
|
|
||||||
Header::Id => item_ord
|
Header::Id => item_ord
|
||||||
.0
|
.0
|
||||||
.id
|
.id
|
||||||
.cmp(&item_ord.1.id)
|
.cmp(&item_ord.1.id)
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Image => item_ord
|
Header::Image => item_ord
|
||||||
.0
|
.0
|
||||||
.image
|
.image
|
||||||
.get()
|
.get()
|
||||||
.cmp(&item_ord.1.image.get())
|
.cmp(item_ord.1.image.get())
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Rx => item_ord
|
Header::Rx => item_ord
|
||||||
.0
|
.0
|
||||||
.rx
|
.rx
|
||||||
.cmp(&item_ord.1.rx)
|
.cmp(&item_ord.1.rx)
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
Header::Tx => item_ord
|
Header::Tx => item_ord
|
||||||
.0
|
.0
|
||||||
.tx
|
.tx
|
||||||
.cmp(&item_ord.1.tx)
|
.cmp(&item_ord.1.tx)
|
||||||
.then_with(|| item_ord.0.name.get().cmp(&item_ord.1.name.get())),
|
.then_with(|| item_ord.0.name.get().cmp(item_ord.1.name.get())),
|
||||||
|
|
||||||
Header::Name => item_ord
|
Header::Name => item_ord
|
||||||
.0
|
.0
|
||||||
.name
|
.name
|
||||||
.get()
|
.get()
|
||||||
.cmp(&item_ord.1.name.get())
|
.cmp(item_ord.1.name.get())
|
||||||
.then_with(|| item_ord.0.id.cmp(&item_ord.1.id)),
|
.then_with(|| item_ord.0.id.cmp(&item_ord.1.id)),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -225,7 +225,7 @@ impl AppData {
|
|||||||
self.containers.items.sort_by(|a, b| {
|
self.containers.items.sort_by(|a, b| {
|
||||||
a.created
|
a.created
|
||||||
.cmp(&b.created)
|
.cmp(&b.created)
|
||||||
.then_with(|| a.name.get().cmp(&b.name.get()))
|
.then_with(|| a.name.get().cmp(b.name.get()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -509,7 +509,7 @@ impl AppData {
|
|||||||
/// Get the Id and State for the currently selected container - used by the exec check method
|
/// Get the Id and State for the currently selected container - used by the exec check method
|
||||||
pub fn get_selected_container_id_state_name(&self) -> Option<(ContainerId, State, String)> {
|
pub fn get_selected_container_id_state_name(&self) -> Option<(ContainerId, State, String)> {
|
||||||
self.get_selected_container()
|
self.get_selected_container()
|
||||||
.map(|i| (i.id.clone(), i.state, i.name.get()))
|
.map(|i| (i.id.clone(), i.state, i.name.get().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update container mem, cpu, & network stats, in single function so only need to call .lock() once
|
/// Update container mem, cpu, & network stats, in single function so only need to call .lock() once
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use ratatui::{
|
|||||||
use std::{default::Default, time::Instant};
|
use std::{default::Default, time::Instant};
|
||||||
use std::{fmt::Display, sync::Arc};
|
use std::{fmt::Display, sync::Arc};
|
||||||
|
|
||||||
use crate::app_data::{ContainerItem, Header, SortedOrder, ContainerName};
|
use crate::app_data::{ContainerItem, ContainerName, Header, SortedOrder};
|
||||||
use crate::{
|
use crate::{
|
||||||
app_data::{AppData, ByteStats, Columns, CpuStats, State, Stats},
|
app_data::{AppData, ByteStats, Columns, CpuStats, State, Stats},
|
||||||
app_error::AppError,
|
app_error::AppError,
|
||||||
|
|||||||
Reference in New Issue
Block a user