refactor: Multiple UI improvements;
Use FrameData struct to store commonly accessed data, in order to reduce mutex locks. rename unpause to resume use get_selected_panel() function instead of directly gui_state.selected_panel debug mode now shows some usefull information
This commit is contained in:
@@ -28,6 +28,11 @@ impl ContainerId {
|
||||
pub fn get(&self) -> &str {
|
||||
self.0.as_str()
|
||||
}
|
||||
|
||||
/// Only return first 8 chars of id, is usually more than enough for uniqueness
|
||||
pub fn get_short(&self) -> String {
|
||||
self.0.chars().take(8).collect::<String>()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for ContainerId {
|
||||
@@ -443,6 +448,20 @@ pub struct ContainerItem {
|
||||
pub is_oxker: bool,
|
||||
}
|
||||
|
||||
/// Basic display information, for when running in debug mode
|
||||
impl fmt::Display for ContainerItem {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}, {}, {}, {}",
|
||||
self.id.get_short(),
|
||||
self.name,
|
||||
self.cpu_stats.back().unwrap_or(&CpuStats::new(0.0)),
|
||||
self.mem_stats.back().unwrap_or(&ByteStats::new(0))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ContainerItem {
|
||||
/// Create a new container item
|
||||
pub fn new(
|
||||
|
||||
+36
-12
@@ -17,6 +17,7 @@ use crate::{
|
||||
};
|
||||
pub use container_state::*;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
/// Global app_state, stored in an Arc<Mutex>
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppData {
|
||||
@@ -26,6 +27,17 @@ pub struct AppData {
|
||||
pub args: CliArgs,
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
/// Global app_state, stored in an Arc<Mutex>
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppData {
|
||||
containers: StatefulList<ContainerItem>,
|
||||
error: Option<AppError>,
|
||||
sorted_by: Option<(Header, SortedOrder)>,
|
||||
debug_string: String,
|
||||
pub args: CliArgs,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub enum SortedOrder {
|
||||
Asc,
|
||||
@@ -64,6 +76,17 @@ impl fmt::Display for Header {
|
||||
}
|
||||
|
||||
impl AppData {
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn get_debug_string(&self) -> &str {
|
||||
&self.debug_string
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
#[allow(unused)]
|
||||
pub fn set_debug_string(&mut self, x: &str) {
|
||||
self.debug_string.push_str(x);
|
||||
}
|
||||
|
||||
/// Change the sorted order, also set the selected container state to match new order
|
||||
fn set_sorted(&mut self, x: Option<(Header, SortedOrder)>) {
|
||||
self.sorted_by = x;
|
||||
@@ -86,6 +109,7 @@ impl AppData {
|
||||
}
|
||||
|
||||
/// Generate a default app_state
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub fn default(args: CliArgs) -> Self {
|
||||
Self {
|
||||
args,
|
||||
@@ -95,6 +119,18 @@ impl AppData {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate a default app_state
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn default(args: CliArgs) -> Self {
|
||||
Self {
|
||||
args,
|
||||
containers: StatefulList::new(vec![]),
|
||||
error: None,
|
||||
sorted_by: None,
|
||||
debug_string: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Container sort related methods
|
||||
|
||||
/// Remove the sorted header & order, and sort by default - created datetime
|
||||
@@ -410,18 +446,6 @@ impl AppData {
|
||||
self.get_selected_container().map_or(false, |i| i.is_oxker)
|
||||
}
|
||||
|
||||
/// Check if the initial parsing has been completed, by making sure that all ids given (which are running) have a non empty cpu_stats vecdec
|
||||
pub fn initialised(&mut self, all_ids: &[(bool, ContainerId)]) -> bool {
|
||||
let count_is_running = all_ids.iter().filter(|i| i.0).count();
|
||||
let number_with_cpu_status = self
|
||||
.containers
|
||||
.items
|
||||
.iter()
|
||||
.filter(|i| !i.cpu_stats.is_empty())
|
||||
.count();
|
||||
count_is_running == number_with_cpu_status
|
||||
}
|
||||
|
||||
/// Find the widths for the strings in the containers panel.
|
||||
/// So can display nicely and evenly
|
||||
pub fn get_width(&self) -> Columns {
|
||||
|
||||
Reference in New Issue
Block a user