refactor: gui const fn's take self
This commit is contained in:
+4
-1
@@ -457,7 +457,10 @@ impl AppData {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or("".to_owned(), |f| f.trim().to_owned());
|
.map_or("".to_owned(), |f| f.trim().to_owned());
|
||||||
|
|
||||||
let image = i.image.as_ref().map_or("".to_owned(), std::clone::Clone::clone);
|
let image = i
|
||||||
|
.image
|
||||||
|
.as_ref()
|
||||||
|
.map_or("".to_owned(), std::clone::Clone::clone);
|
||||||
|
|
||||||
if let Some(current_container) = self.get_container_by_id(id) {
|
if let Some(current_container) = self.get_container_by_id(id) {
|
||||||
if current_container.name != name {
|
if current_container.name != name {
|
||||||
|
|||||||
+10
-8
@@ -33,18 +33,18 @@ enum SpawnId {
|
|||||||
/// Cpu & Mem stats take twice as long as the update interval to get a value, so will have two being executed at the same time
|
/// Cpu & Mem stats take twice as long as the update interval to get a value, so will have two being executed at the same time
|
||||||
/// SpawnId::Stats takes container_id and binate value to enable both cycles of the same container_id to be inserted into the hashmap
|
/// SpawnId::Stats takes container_id and binate value to enable both cycles of the same container_id to be inserted into the hashmap
|
||||||
/// Binate value is toggled when all join handles have been spawned off
|
/// Binate value is toggled when all join handles have been spawned off
|
||||||
#[derive(Debug, Hash, Clone, PartialEq, Eq)]
|
#[derive(Debug, Hash, Clone, PartialEq, Eq, Copy)]
|
||||||
enum Binate {
|
enum Binate {
|
||||||
One,
|
One,
|
||||||
Two
|
Two
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Binate {
|
impl Binate {
|
||||||
fn toggle(&mut self) {
|
const fn toggle(self) -> Self {
|
||||||
*self = match self {
|
match self {
|
||||||
Self::One => Self::Two,
|
Self::One => Self::Two,
|
||||||
Self::Two => Self::One,
|
Self::Two => Self::One,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,10 +155,9 @@ impl DockerData {
|
|||||||
let docker = Arc::clone(&self.docker);
|
let docker = Arc::clone(&self.docker);
|
||||||
let app_data = Arc::clone(&self.app_data);
|
let app_data = Arc::clone(&self.app_data);
|
||||||
let spawns = Arc::clone(&self.spawns);
|
let spawns = Arc::clone(&self.spawns);
|
||||||
let is_running = *is_running;
|
|
||||||
let id = id.clone();
|
let id = id.clone();
|
||||||
|
|
||||||
let key = SpawnId::Stats((id.clone(), self.binate.clone()));
|
let key = SpawnId::Stats((id.clone(), self.binate));
|
||||||
|
|
||||||
let spawn_key = key.clone();
|
let spawn_key = key.clone();
|
||||||
self.spawns.lock().entry(key).or_insert_with(|| {
|
self.spawns.lock().entry(key).or_insert_with(|| {
|
||||||
@@ -166,13 +165,13 @@ impl DockerData {
|
|||||||
docker,
|
docker,
|
||||||
id.clone(),
|
id.clone(),
|
||||||
app_data,
|
app_data,
|
||||||
is_running,
|
*is_running,
|
||||||
spawns,
|
spawns,
|
||||||
spawn_key
|
spawn_key
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.binate.toggle();
|
self.binate = self.binate.toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all current containers, handle into ContainerItem in the app_data struct rather than here
|
/// Get all current containers, handle into ContainerItem in the app_data struct rather than here
|
||||||
@@ -382,12 +381,15 @@ impl DockerData {
|
|||||||
self.stop_loading_spin(&loading_spin);
|
self.stop_loading_spin(&loading_spin);
|
||||||
}
|
}
|
||||||
DockerMessage::Unpause(id) => {
|
DockerMessage::Unpause(id) => {
|
||||||
|
// gen uuid, leading_spin(uuid)
|
||||||
let loading_spin = self.loading_spin().await;
|
let loading_spin = self.loading_spin().await;
|
||||||
if docker.unpause_container(&id).await.is_err() {
|
if docker.unpause_container(&id).await.is_err() {
|
||||||
app_data
|
app_data
|
||||||
.lock()
|
.lock()
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Unpause));
|
.set_error(AppError::DockerCommand(DockerControls::Unpause));
|
||||||
};
|
};
|
||||||
|
// loading sping take uuid to remove
|
||||||
|
// stop_loading_sping(uuid)
|
||||||
self.stop_loading_spin(&loading_spin);
|
self.stop_loading_spin(&loading_spin);
|
||||||
self.update_everything().await;
|
self.update_everything().await;
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-35
@@ -10,6 +10,30 @@ pub enum SelectablePanel {
|
|||||||
Logs,
|
Logs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SelectablePanel {
|
||||||
|
pub const fn title(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::Containers => "Containers",
|
||||||
|
Self::Logs => "Logs",
|
||||||
|
Self::Commands => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn next(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Containers => Self::Commands,
|
||||||
|
Self::Commands => Self::Logs,
|
||||||
|
Self::Logs => Self::Containers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn prev(self) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Containers => Self::Logs,
|
||||||
|
Self::Commands => Self::Containers,
|
||||||
|
Self::Logs => Self::Commands,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum Region {
|
pub enum Region {
|
||||||
Panel(SelectablePanel),
|
Panel(SelectablePanel),
|
||||||
Header(Header),
|
Header(Header),
|
||||||
@@ -93,7 +117,8 @@ impl BoxLocation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
/// State for the loading animation
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Loading {
|
pub enum Loading {
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
@@ -108,7 +133,7 @@ pub enum Loading {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Loading {
|
impl Loading {
|
||||||
pub const fn next(&self) -> Self {
|
pub const fn next(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Self::One => Self::Two,
|
Self::One => Self::Two,
|
||||||
Self::Two => Self::Three,
|
Self::Two => Self::Three,
|
||||||
@@ -127,44 +152,21 @@ impl Loading {
|
|||||||
impl fmt::Display for Loading {
|
impl fmt::Display for Loading {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let disp = match self {
|
let disp = match self {
|
||||||
Self::One => "⠋",
|
Self::One => '⠋',
|
||||||
Self::Two => "⠙",
|
Self::Two => '⠙',
|
||||||
Self::Three => "⠹",
|
Self::Three => '⠹',
|
||||||
Self::Four => "⠸",
|
Self::Four => '⠸',
|
||||||
Self::Five => "⠼",
|
Self::Five => '⠼',
|
||||||
Self::Six => "⠴",
|
Self::Six => '⠴',
|
||||||
Self::Seven => "⠦",
|
Self::Seven => '⠦',
|
||||||
Self::Eight => "⠧",
|
Self::Eight => '⠧',
|
||||||
Self::Nine => "⠇",
|
Self::Nine => '⠇',
|
||||||
Self::Ten => "⠏",
|
Self::Ten => '⠏',
|
||||||
};
|
};
|
||||||
write!(f, "{}", disp)
|
write!(f, "{}", disp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SelectablePanel {
|
|
||||||
pub const fn title(self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Self::Containers => "Containers",
|
|
||||||
Self::Logs => "Logs",
|
|
||||||
Self::Commands => "",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub const fn next(self) -> Self {
|
|
||||||
match self {
|
|
||||||
Self::Containers => Self::Commands,
|
|
||||||
Self::Commands => Self::Logs,
|
|
||||||
Self::Logs => Self::Containers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub const fn prev(self) -> Self {
|
|
||||||
match self {
|
|
||||||
Self::Containers => Self::Logs,
|
|
||||||
Self::Commands => Self::Containers,
|
|
||||||
Self::Logs => Self::Commands,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Global gui_state, stored in an Arc<Mutex>
|
/// Global gui_state, stored in an Arc<Mutex>
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
+2
-5
@@ -57,7 +57,7 @@ pub async fn create_ui(
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
disable_raw_mode().unwrap_or(());
|
disable_raw_mode()?;
|
||||||
execute!(
|
execute!(
|
||||||
terminal.backend_mut(),
|
terminal.backend_mut(),
|
||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen,
|
||||||
@@ -85,8 +85,7 @@ async fn run_app<B: Backend + Send>(
|
|||||||
|
|
||||||
// Check for docker connect errors before attempting to draw the gui
|
// Check for docker connect errors before attempting to draw the gui
|
||||||
let e = app_data.lock().get_error();
|
let e = app_data.lock().get_error();
|
||||||
if let Some(error) = e {
|
if let Some(AppError::DockerConnect) = e {
|
||||||
if let AppError::DockerConnect = error {
|
|
||||||
let mut seconds = 5;
|
let mut seconds = 5;
|
||||||
loop {
|
loop {
|
||||||
if seconds < 1 {
|
if seconds < 1 {
|
||||||
@@ -102,11 +101,9 @@ async fn run_app<B: Backend + Send>(
|
|||||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
seconds -= 1;
|
seconds -= 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let mut now = Instant::now();
|
let mut now = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
|
|
||||||
if terminal.draw(|f| ui(f, &app_data, &gui_state)).is_err() {
|
if terminal.draw(|f| ui(f, &app_data, &gui_state)).is_err() {
|
||||||
return Err(AppError::Terminal);
|
return Err(AppError::Terminal);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user