feat: Clippy mem drop,
re-arrange .lock() ordering, and use `value_capture!`, to satisfy has_significant_drop rule
This commit is contained in:
@@ -323,8 +323,8 @@ impl DockerData {
|
|||||||
while !self.app_data.lock().initialised(&all_ids) {
|
while !self.app_data.lock().initialised(&all_ids) {
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
}
|
}
|
||||||
self.gui_state.lock().status_del(Status::Init);
|
|
||||||
Self::stop_loading_spin(&self.gui_state, &loading_spin, loading_uuid);
|
Self::stop_loading_spin(&self.gui_state, &loading_spin, loading_uuid);
|
||||||
|
self.gui_state.lock().status_del(Status::Init);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the global error as the docker error, and set gui_state to error
|
/// Set the global error as the docker error, and set gui_state to error
|
||||||
|
|||||||
+27
-17
@@ -20,6 +20,7 @@ use crate::{
|
|||||||
app_error::AppError,
|
app_error::AppError,
|
||||||
docker_data::DockerMessage,
|
docker_data::DockerMessage,
|
||||||
ui::{DeleteButton, GuiState, SelectablePanel, Status, Ui},
|
ui::{DeleteButton, GuiState, SelectablePanel, Status, Ui},
|
||||||
|
value_capture,
|
||||||
};
|
};
|
||||||
pub use message::InputMessages;
|
pub use message::InputMessages;
|
||||||
|
|
||||||
@@ -62,12 +63,11 @@ impl InputHandler {
|
|||||||
match message {
|
match message {
|
||||||
InputMessages::ButtonPress(key) => self.button_press(key.0, key.1).await,
|
InputMessages::ButtonPress(key) => self.button_press(key.0, key.1).await,
|
||||||
InputMessages::MouseEvent(mouse_event) => {
|
InputMessages::MouseEvent(mouse_event) => {
|
||||||
let error_or_help = self.gui_state.lock().status_contains(&[
|
if !self.gui_state.lock().status_contains(&[
|
||||||
Status::Error,
|
Status::Error,
|
||||||
Status::Help,
|
Status::Help,
|
||||||
Status::DeleteConfirm,
|
Status::DeleteConfirm,
|
||||||
]);
|
]) {
|
||||||
if !error_or_help {
|
|
||||||
self.mouse_press(mouse_event);
|
self.mouse_press(mouse_event);
|
||||||
}
|
}
|
||||||
let delete_confirm = self
|
let delete_confirm = self
|
||||||
@@ -160,13 +160,21 @@ impl InputHandler {
|
|||||||
/// Handle any keyboard button events
|
/// Handle any keyboard button events
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
async fn button_press(&mut self, key_code: KeyCode, key_modififer: KeyModifiers) {
|
async fn button_press(&mut self, key_code: KeyCode, key_modififer: KeyModifiers) {
|
||||||
// TODO - refactor this to a single call, maybe return Error, Help or Normal
|
value_capture!(
|
||||||
let contains_error = self.gui_state.lock().status_contains(&[Status::Error]);
|
contains_delete,
|
||||||
let contains_help = self.gui_state.lock().status_contains(&[Status::Help]);
|
self.gui_state
|
||||||
let contains_delete = self
|
|
||||||
.gui_state
|
|
||||||
.lock()
|
.lock()
|
||||||
.status_contains(&[Status::DeleteConfirm]);
|
.status_contains(&[Status::DeleteConfirm])
|
||||||
|
);
|
||||||
|
|
||||||
|
value_capture!(
|
||||||
|
contains_error,
|
||||||
|
self.gui_state.lock().status_contains(&[Status::Error])
|
||||||
|
);
|
||||||
|
value_capture!(
|
||||||
|
contains_help,
|
||||||
|
self.gui_state.lock().status_contains(&[Status::Help])
|
||||||
|
);
|
||||||
|
|
||||||
// Always just quit on Ctrl + c/C or q/Q
|
// Always just quit on Ctrl + c/C or q/Q
|
||||||
let is_c = || key_code == KeyCode::Char('c') || key_code == KeyCode::Char('C');
|
let is_c = || key_code == KeyCode::Char('c') || key_code == KeyCode::Char('C');
|
||||||
@@ -208,10 +216,9 @@ impl InputHandler {
|
|||||||
KeyCode::Char('m' | 'M') => self.m_key(),
|
KeyCode::Char('m' | 'M') => self.m_key(),
|
||||||
KeyCode::Tab => {
|
KeyCode::Tab => {
|
||||||
// Skip control panel if no containers, could be refactored
|
// Skip control panel if no containers, could be refactored
|
||||||
let has_containers = self.app_data.lock().get_container_len() == 0;
|
|
||||||
let is_containers =
|
let is_containers =
|
||||||
self.gui_state.lock().selected_panel == SelectablePanel::Containers;
|
self.gui_state.lock().selected_panel == SelectablePanel::Containers;
|
||||||
let count = if has_containers && is_containers {
|
let count = if self.app_data.lock().get_container_len() == 0 && is_containers {
|
||||||
2
|
2
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
@@ -222,10 +229,9 @@ impl InputHandler {
|
|||||||
}
|
}
|
||||||
KeyCode::BackTab => {
|
KeyCode::BackTab => {
|
||||||
// Skip control panel if no containers, could be refactored
|
// Skip control panel if no containers, could be refactored
|
||||||
let has_containers = self.app_data.lock().get_container_len() == 0;
|
|
||||||
let is_containers =
|
let is_containers =
|
||||||
self.gui_state.lock().selected_panel == SelectablePanel::Logs;
|
self.gui_state.lock().selected_panel == SelectablePanel::Logs;
|
||||||
let count = if has_containers && is_containers {
|
let count = if self.app_data.lock().get_container_len() == 0 && is_containers {
|
||||||
2
|
2
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
@@ -236,7 +242,8 @@ impl InputHandler {
|
|||||||
}
|
}
|
||||||
KeyCode::Home => {
|
KeyCode::Home => {
|
||||||
let mut locked_data = self.app_data.lock();
|
let mut locked_data = self.app_data.lock();
|
||||||
match self.gui_state.lock().selected_panel {
|
let selected_panel = self.gui_state.lock().selected_panel;
|
||||||
|
match selected_panel {
|
||||||
SelectablePanel::Containers => locked_data.containers_start(),
|
SelectablePanel::Containers => locked_data.containers_start(),
|
||||||
SelectablePanel::Logs => locked_data.log_start(),
|
SelectablePanel::Logs => locked_data.log_start(),
|
||||||
SelectablePanel::Commands => locked_data.docker_command_start(),
|
SelectablePanel::Commands => locked_data.docker_command_start(),
|
||||||
@@ -244,7 +251,8 @@ impl InputHandler {
|
|||||||
}
|
}
|
||||||
KeyCode::End => {
|
KeyCode::End => {
|
||||||
let mut locked_data = self.app_data.lock();
|
let mut locked_data = self.app_data.lock();
|
||||||
match self.gui_state.lock().selected_panel {
|
let selected_panel = self.gui_state.lock().selected_panel;
|
||||||
|
match selected_panel {
|
||||||
SelectablePanel::Containers => locked_data.containers_end(),
|
SelectablePanel::Containers => locked_data.containers_end(),
|
||||||
SelectablePanel::Logs => locked_data.log_end(),
|
SelectablePanel::Logs => locked_data.log_end(),
|
||||||
SelectablePanel::Commands => locked_data.docker_command_end(),
|
SelectablePanel::Commands => locked_data.docker_command_end(),
|
||||||
@@ -358,7 +366,8 @@ impl InputHandler {
|
|||||||
/// Change state to next, depending which panel is currently in focus
|
/// Change state to next, depending which panel is currently in focus
|
||||||
fn next(&mut self) {
|
fn next(&mut self) {
|
||||||
let mut locked_data = self.app_data.lock();
|
let mut locked_data = self.app_data.lock();
|
||||||
match self.gui_state.lock().selected_panel {
|
let selected_panel = self.gui_state.lock().selected_panel;
|
||||||
|
match selected_panel {
|
||||||
SelectablePanel::Containers => locked_data.containers_next(),
|
SelectablePanel::Containers => locked_data.containers_next(),
|
||||||
SelectablePanel::Logs => locked_data.log_next(),
|
SelectablePanel::Logs => locked_data.log_next(),
|
||||||
SelectablePanel::Commands => locked_data.docker_command_next(),
|
SelectablePanel::Commands => locked_data.docker_command_next(),
|
||||||
@@ -368,7 +377,8 @@ impl InputHandler {
|
|||||||
/// Change state to previous, depending which panel is currently in focus
|
/// Change state to previous, depending which panel is currently in focus
|
||||||
fn previous(&mut self) {
|
fn previous(&mut self) {
|
||||||
let mut locked_data = self.app_data.lock();
|
let mut locked_data = self.app_data.lock();
|
||||||
match self.gui_state.lock().selected_panel {
|
let selected_panel = self.gui_state.lock().selected_panel;
|
||||||
|
match selected_panel {
|
||||||
SelectablePanel::Containers => locked_data.containers_previous(),
|
SelectablePanel::Containers => locked_data.containers_previous(),
|
||||||
SelectablePanel::Logs => locked_data.log_previous(),
|
SelectablePanel::Logs => locked_data.log_previous(),
|
||||||
SelectablePanel::Commands => locked_data.docker_command_previous(),
|
SelectablePanel::Commands => locked_data.docker_command_previous(),
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ fn generate_block<'a>(
|
|||||||
gui_state
|
gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.update_region_map(Region::Panel(panel), area);
|
.update_region_map(Region::Panel(panel), area);
|
||||||
let current_selected_panel = gui_state.lock().selected_panel;
|
|
||||||
let mut title = match panel {
|
let mut title = match panel {
|
||||||
SelectablePanel::Containers => {
|
SelectablePanel::Containers => {
|
||||||
format!("{} {}", panel.title(), app_data.lock().container_title())
|
format!("{} {}", panel.title(), app_data.lock().container_title())
|
||||||
@@ -79,7 +78,7 @@ fn generate_block<'a>(
|
|||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.title(title);
|
.title(title);
|
||||||
if current_selected_panel == panel {
|
if gui_state.lock().selected_panel == panel {
|
||||||
block = block.border_style(Style::default().fg(Color::LightCyan));
|
block = block.border_style(Style::default().fg(Color::LightCyan));
|
||||||
}
|
}
|
||||||
block
|
block
|
||||||
@@ -819,6 +818,11 @@ pub fn delete_confirm<B: Backend>(
|
|||||||
let no_area = split_buttons[1];
|
let no_area = split_buttons[1];
|
||||||
let yes_area = split_buttons[3];
|
let yes_area = split_buttons[3];
|
||||||
|
|
||||||
|
f.render_widget(Clear, area);
|
||||||
|
f.render_widget(block, area);
|
||||||
|
f.render_widget(confirm_para, split_popup[1]);
|
||||||
|
f.render_widget(no_para, no_area);
|
||||||
|
f.render_widget(yes_para, yes_area);
|
||||||
// Insert button areas into region map, so can interact with them on click
|
// Insert button areas into region map, so can interact with them on click
|
||||||
gui_state
|
gui_state
|
||||||
.lock()
|
.lock()
|
||||||
@@ -827,12 +831,6 @@ pub fn delete_confirm<B: Backend>(
|
|||||||
gui_state
|
gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.update_region_map(Region::Delete(DeleteButton::Yes), yes_area);
|
.update_region_map(Region::Delete(DeleteButton::Yes), yes_area);
|
||||||
|
|
||||||
f.render_widget(Clear, area);
|
|
||||||
f.render_widget(block, area);
|
|
||||||
f.render_widget(confirm_para, split_popup[1]);
|
|
||||||
f.render_widget(no_para, no_area);
|
|
||||||
f.render_widget(yes_para, yes_area);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw an error popup over whole screen
|
/// Draw an error popup over whole screen
|
||||||
|
|||||||
+2
-1
@@ -197,7 +197,8 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This macro simplifies the definition and evaluation of variables by capturing and immediately evaluating an expression.
|
#[macro_export]
|
||||||
|
/// This macro simplifies the definition and evaluation of variables by capturing and immediately evaluating an expression.
|
||||||
macro_rules! value_capture {
|
macro_rules! value_capture {
|
||||||
($name:ident, $lock_expr:expr) => {
|
($name:ident, $lock_expr:expr) => {
|
||||||
let $name = || $lock_expr;
|
let $name = || $lock_expr;
|
||||||
|
|||||||
Reference in New Issue
Block a user