Merge branch 'feat/application_state' into dev
This commit is contained in:
+1
-5
@@ -14,10 +14,8 @@ pub struct AppData {
|
|||||||
args: CliArgs,
|
args: CliArgs,
|
||||||
error: Option<AppError>,
|
error: Option<AppError>,
|
||||||
logs_parsed: bool,
|
logs_parsed: bool,
|
||||||
pub containers: StatefulList<ContainerItem>,
|
|
||||||
pub init: bool,
|
|
||||||
pub show_error: bool,
|
|
||||||
sorted_by: Option<(Header, SortedOrder)>,
|
sorted_by: Option<(Header, SortedOrder)>,
|
||||||
|
pub containers: StatefulList<ContainerItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
@@ -79,9 +77,7 @@ impl AppData {
|
|||||||
args,
|
args,
|
||||||
containers: StatefulList::new(vec![]),
|
containers: StatefulList::new(vec![]),
|
||||||
error: None,
|
error: None,
|
||||||
init: false,
|
|
||||||
logs_parsed: false,
|
logs_parsed: false,
|
||||||
show_error: false,
|
|
||||||
sorted_by: None,
|
sorted_by: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-44
@@ -3,7 +3,7 @@ use bollard::{
|
|||||||
service::ContainerSummary,
|
service::ContainerSummary,
|
||||||
Docker,
|
Docker,
|
||||||
};
|
};
|
||||||
use futures_util::StreamExt;
|
use futures_util::{Future, StreamExt};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@@ -19,7 +19,7 @@ use crate::{
|
|||||||
app_data::{AppData, ContainerId, DockerControls},
|
app_data::{AppData, ContainerId, DockerControls},
|
||||||
app_error::AppError,
|
app_error::AppError,
|
||||||
parse_args::CliArgs,
|
parse_args::CliArgs,
|
||||||
ui::GuiState,
|
ui::{GuiState, Status},
|
||||||
};
|
};
|
||||||
mod message;
|
mod message;
|
||||||
pub use message::DockerMessage;
|
pub use message::DockerMessage;
|
||||||
@@ -318,6 +318,7 @@ impl DockerData {
|
|||||||
|
|
||||||
// Initialize docker container data, before any messages are received
|
// Initialize docker container data, before any messages are received
|
||||||
async fn initialise_container_data(&mut self) {
|
async fn initialise_container_data(&mut self) {
|
||||||
|
self.gui_state.lock().status_push(Status::Init);
|
||||||
let loading_uuid = Uuid::new_v4();
|
let loading_uuid = Uuid::new_v4();
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
let loading_spin = self.loading_spin(loading_uuid).await;
|
||||||
|
|
||||||
@@ -336,65 +337,77 @@ impl DockerData {
|
|||||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
self.initialised = self.app_data.lock().initialised(&all_ids);
|
self.initialised = self.app_data.lock().initialised(&all_ids);
|
||||||
}
|
}
|
||||||
self.app_data.lock().init = true;
|
self.gui_state.lock().status_del(Status::Init);
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
self.stop_loading_spin(&loading_spin, loading_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the global error as the dockererror, and set gui_state to errro
|
||||||
|
fn set_error(&mut self, error: DockerControls) {
|
||||||
|
self.app_data
|
||||||
|
.lock()
|
||||||
|
.set_error(AppError::DockerCommand(error));
|
||||||
|
self.gui_state.lock().status_push(Status::Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Execute docker commands, will start and stop the loading spinner
|
||||||
|
async fn exec_docker(
|
||||||
|
&mut self,
|
||||||
|
docker_fn: impl Future<Output = Result<(), bollard::errors::Error>>,
|
||||||
|
uuid: Uuid,
|
||||||
|
control: DockerControls,
|
||||||
|
) {
|
||||||
|
let loading_spin = self.loading_spin(uuid).await;
|
||||||
|
if docker_fn.await.is_err() {
|
||||||
|
self.set_error(control);
|
||||||
|
};
|
||||||
|
self.stop_loading_spin(&loading_spin, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle incoming messages, container controls & all container information update
|
/// Handle incoming messages, container controls & all container information update
|
||||||
async fn message_handler(&mut self) {
|
async fn message_handler(&mut self) {
|
||||||
while let Some(message) = self.receiver.recv().await {
|
while let Some(message) = self.receiver.recv().await {
|
||||||
let docker = Arc::clone(&self.docker);
|
|
||||||
let app_data = Arc::clone(&self.app_data);
|
|
||||||
let loading_uuid = Uuid::new_v4();
|
let loading_uuid = Uuid::new_v4();
|
||||||
|
let docker = Arc::clone(&self.docker);
|
||||||
match message {
|
match message {
|
||||||
DockerMessage::Pause(id) => {
|
DockerMessage::Pause(id) => {
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
self.exec_docker(
|
||||||
if docker.pause_container(id.get()).await.is_err() {
|
docker.pause_container(id.get()),
|
||||||
app_data
|
loading_uuid,
|
||||||
.lock()
|
DockerControls::Pause,
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Pause));
|
)
|
||||||
};
|
.await;
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
|
||||||
}
|
}
|
||||||
DockerMessage::Restart(id) => {
|
DockerMessage::Restart(id) => {
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
self.exec_docker(
|
||||||
if docker.restart_container(id.get(), None).await.is_err() {
|
docker.restart_container(id.get(), None),
|
||||||
app_data
|
loading_uuid,
|
||||||
.lock()
|
DockerControls::Restart,
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Restart));
|
)
|
||||||
};
|
.await;
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
|
||||||
}
|
}
|
||||||
DockerMessage::Start(id) => {
|
DockerMessage::Start(id) => {
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
self.exec_docker(
|
||||||
if docker
|
docker.start_container(id.get(), None::<StartContainerOptions<String>>),
|
||||||
.start_container(id.get(), None::<StartContainerOptions<String>>)
|
loading_uuid,
|
||||||
.await
|
DockerControls::Start,
|
||||||
.is_err()
|
)
|
||||||
{
|
.await;
|
||||||
app_data
|
|
||||||
.lock()
|
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Start));
|
|
||||||
};
|
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
|
||||||
}
|
}
|
||||||
DockerMessage::Stop(id) => {
|
DockerMessage::Stop(id) => {
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
self.exec_docker(
|
||||||
if docker.stop_container(id.get(), None).await.is_err() {
|
docker.stop_container(id.get(), None),
|
||||||
app_data
|
loading_uuid,
|
||||||
.lock()
|
DockerControls::Stop,
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Stop));
|
)
|
||||||
};
|
.await;
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
|
||||||
}
|
}
|
||||||
DockerMessage::Unpause(id) => {
|
DockerMessage::Unpause(id) => {
|
||||||
let loading_spin = self.loading_spin(loading_uuid).await;
|
self.exec_docker(
|
||||||
if docker.unpause_container(id.get()).await.is_err() {
|
docker.unpause_container(id.get()),
|
||||||
app_data
|
loading_uuid,
|
||||||
.lock()
|
DockerControls::Unpause,
|
||||||
.set_error(AppError::DockerCommand(DockerControls::Unpause));
|
)
|
||||||
};
|
.await;
|
||||||
self.stop_loading_spin(&loading_spin, loading_uuid);
|
|
||||||
self.update_everything().await;
|
self.update_everything().await;
|
||||||
}
|
}
|
||||||
DockerMessage::Update => self.update_everything().await,
|
DockerMessage::Update => self.update_everything().await,
|
||||||
|
|||||||
+29
-19
@@ -21,7 +21,7 @@ use crate::{
|
|||||||
app_data::{AppData, DockerControls, Header, SortedOrder},
|
app_data::{AppData, DockerControls, Header, SortedOrder},
|
||||||
app_error::AppError,
|
app_error::AppError,
|
||||||
docker_data::DockerMessage,
|
docker_data::DockerMessage,
|
||||||
ui::{GuiState, SelectablePanel},
|
ui::{GuiState, SelectablePanel, Status},
|
||||||
};
|
};
|
||||||
pub use message::InputMessages;
|
pub use message::InputMessages;
|
||||||
|
|
||||||
@@ -64,10 +64,12 @@ impl InputHandler {
|
|||||||
match message {
|
match message {
|
||||||
InputMessages::ButtonPress(key_code) => self.button_press(key_code).await,
|
InputMessages::ButtonPress(key_code) => self.button_press(key_code).await,
|
||||||
InputMessages::MouseEvent(mouse_event) => {
|
InputMessages::MouseEvent(mouse_event) => {
|
||||||
let show_error = self.app_data.lock().show_error;
|
let error_or_help = self
|
||||||
let show_info = self.gui_state.lock().show_help;
|
.gui_state
|
||||||
if !show_error && !show_info {
|
.lock()
|
||||||
self.mouse_press(mouse_event);
|
.status_contains(&[Status::Error, Status::Help]);
|
||||||
|
if !error_or_help {
|
||||||
|
self.mouse_press(mouse_event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,10 +87,11 @@ impl InputHandler {
|
|||||||
.gui_state
|
.gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.set_info_box("✖ mouse capture disabled".to_owned()),
|
.set_info_box("✖ mouse capture disabled".to_owned()),
|
||||||
Err(_) => self
|
Err(_) => {
|
||||||
.app_data
|
self.app_data
|
||||||
.lock()
|
.lock()
|
||||||
.set_error(AppError::MouseCapture(false)),
|
.set_error(AppError::MouseCapture(false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match execute!(std::io::stdout(), EnableMouseCapture) {
|
match execute!(std::io::stdout(), EnableMouseCapture) {
|
||||||
@@ -96,7 +99,9 @@ impl InputHandler {
|
|||||||
.gui_state
|
.gui_state
|
||||||
.lock()
|
.lock()
|
||||||
.set_info_box("✓ mouse capture enabled".to_owned()),
|
.set_info_box("✓ mouse capture enabled".to_owned()),
|
||||||
Err(_) => self.app_data.lock().set_error(AppError::MouseCapture(true)),
|
Err(_) => {
|
||||||
|
self.app_data.lock().set_error(AppError::MouseCapture(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,31 +135,36 @@ impl InputHandler {
|
|||||||
|
|
||||||
/// Send a quit message to docker, to abort all spawns, if an error is return, set is_running to false here instead
|
/// Send a quit message to docker, to abort all spawns, if an error is return, set is_running to false here instead
|
||||||
async fn quit(&self) {
|
async fn quit(&self) {
|
||||||
match self.docker_sender.send(DockerMessage::Quit).await {
|
let error_init = self
|
||||||
Ok(_) => (),
|
.gui_state
|
||||||
Err(_) => self.is_running.store(false, Ordering::SeqCst),
|
.lock()
|
||||||
|
.status_contains(&[Status::Error, Status::Init]);
|
||||||
|
if error_init {
|
||||||
|
self.is_running.store(false, Ordering::SeqCst);
|
||||||
|
} else if self.docker_sender.send(DockerMessage::Quit).await.is_err() {
|
||||||
|
self.is_running.store(false, Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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) {
|
async fn button_press(&mut self, key_code: KeyCode) {
|
||||||
let show_error = self.app_data.lock().show_error;
|
let contains_error = self.gui_state.lock().status_contains(&[Status::Error]);
|
||||||
let show_info = self.gui_state.lock().show_help;
|
let contains_help = self.gui_state.lock().status_contains(&[Status::Help]);
|
||||||
|
|
||||||
if show_error {
|
if contains_error {
|
||||||
match key_code {
|
match key_code {
|
||||||
KeyCode::Char('q' | 'Q') => self.quit().await,
|
KeyCode::Char('q' | 'Q') => self.quit().await,
|
||||||
KeyCode::Char('c' | 'C') => {
|
KeyCode::Char('c' | 'C') => {
|
||||||
self.app_data.lock().show_error = false;
|
|
||||||
self.app_data.lock().remove_error();
|
self.app_data.lock().remove_error();
|
||||||
|
self.gui_state.lock().status_del(Status::Error);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if show_info {
|
} else if contains_help {
|
||||||
match key_code {
|
match key_code {
|
||||||
KeyCode::Char('q' | 'Q') => self.quit().await,
|
KeyCode::Char('q' | 'Q') => self.quit().await,
|
||||||
KeyCode::Char('h' | 'H') => self.gui_state.lock().show_help = false,
|
KeyCode::Char('h' | 'H') => self.gui_state.lock().status_del(Status::Help),
|
||||||
KeyCode::Char('m' | 'M') => self.m_key(),
|
KeyCode::Char('m' | 'M') => self.m_key(),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
@@ -171,7 +181,7 @@ impl InputHandler {
|
|||||||
KeyCode::Char('8') => self.sort(Header::Rx),
|
KeyCode::Char('8') => self.sort(Header::Rx),
|
||||||
KeyCode::Char('9') => self.sort(Header::Tx),
|
KeyCode::Char('9') => self.sort(Header::Tx),
|
||||||
KeyCode::Char('q' | 'Q') => self.quit().await,
|
KeyCode::Char('q' | 'Q') => self.quit().await,
|
||||||
KeyCode::Char('h' | 'H') => self.gui_state.lock().show_help = true,
|
KeyCode::Char('h' | 'H') => self.gui_state.lock().status_push(Status::Help),
|
||||||
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
|
||||||
|
|||||||
+9
-3
@@ -24,7 +24,7 @@ mod input_handler;
|
|||||||
mod parse_args;
|
mod parse_args;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
use ui::{create_ui, GuiState};
|
use ui::{create_ui, GuiState, Status};
|
||||||
|
|
||||||
fn setup_tracing() {
|
fn setup_tracing() {
|
||||||
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
||||||
@@ -59,9 +59,15 @@ async fn main() {
|
|||||||
is_running,
|
is_running,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
Err(_) => {
|
||||||
|
app_data.lock().set_error(AppError::DockerConnect);
|
||||||
|
docker_gui_state.lock().status_push(Status::DockerConnect)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(_) => app_data.lock().set_error(AppError::DockerConnect),
|
Err(_) => {
|
||||||
|
app_data.lock().set_error(AppError::DockerConnect);
|
||||||
|
docker_gui_state.lock().status_push(Status::DockerConnect)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let input_app_data = Arc::clone(&app_data);
|
let input_app_data = Arc::clone(&app_data);
|
||||||
|
|
||||||
|
|||||||
+9
-11
@@ -15,6 +15,7 @@ use tui::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::app_data::{Header, SortedOrder};
|
use crate::app_data::{Header, SortedOrder};
|
||||||
|
use crate::ui::Status;
|
||||||
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,
|
||||||
@@ -215,9 +216,8 @@ pub fn logs<B: Backend>(
|
|||||||
loading_icon: &str,
|
loading_icon: &str,
|
||||||
) {
|
) {
|
||||||
let block = generate_block(app_data, area, gui_state, SelectablePanel::Logs);
|
let block = generate_block(app_data, area, gui_state, SelectablePanel::Logs);
|
||||||
|
let contains_init = gui_state.lock().status_contains(&[Status::Init]);
|
||||||
let init = app_data.lock().init;
|
if contains_init {
|
||||||
if !init {
|
|
||||||
let paragraph = Paragraph::new(format!("parsing logs {}", loading_icon))
|
let paragraph = Paragraph::new(format!("parsing logs {}", loading_icon))
|
||||||
.style(Style::default())
|
.style(Style::default())
|
||||||
.block(block)
|
.block(block)
|
||||||
@@ -349,7 +349,7 @@ pub fn heading_bar<B: Backend>(
|
|||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
) {
|
) {
|
||||||
let block = |fg: Color| Block::default().style(Style::default().bg(Color::Magenta).fg(fg));
|
let block = |fg: Color| Block::default().style(Style::default().bg(Color::Magenta).fg(fg));
|
||||||
let info_visible = gui_state.lock().show_help;
|
let help_visible = gui_state.lock().status_contains(&[Status::Help]);
|
||||||
|
|
||||||
f.render_widget(block(Color::Black), area);
|
f.render_widget(block(Color::Black), area);
|
||||||
|
|
||||||
@@ -429,8 +429,8 @@ pub fn heading_bar<B: Backend>(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let suffix = if info_visible { "exit" } else { "show" };
|
let suffix = if help_visible { "exit" } else { "show" };
|
||||||
let info_text = format!("( h ) {} help {}", suffix, MARGIN);
|
let info_text = format!("( h ) {} help {}", suffix, MARGIN,);
|
||||||
let info_width = info_text.chars().count();
|
let info_width = info_text.chars().count();
|
||||||
|
|
||||||
let column_width = usize::from(area.width) - info_width;
|
let column_width = usize::from(area.width) - info_width;
|
||||||
@@ -457,8 +457,6 @@ pub fn heading_bar<B: Backend>(
|
|||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
f.render_widget(loading_paragraph, split_bar[0]);
|
f.render_widget(loading_paragraph, split_bar[0]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let container_splits = header_data.iter().map(|i| i.2).collect::<Vec<_>>();
|
let container_splits = header_data.iter().map(|i| i.2).collect::<Vec<_>>();
|
||||||
let headers_section = Layout::default()
|
let headers_section = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
@@ -474,10 +472,10 @@ pub fn heading_bar<B: Backend>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// show/hide help
|
// show/hide help
|
||||||
let color = if info_visible {
|
let color = if help_visible {
|
||||||
Color::White
|
|
||||||
} else {
|
|
||||||
Color::Black
|
Color::Black
|
||||||
|
} else {
|
||||||
|
Color::White
|
||||||
};
|
};
|
||||||
let help_paragraph = Paragraph::new(info_text)
|
let help_paragraph = Paragraph::new(info_text)
|
||||||
.block(block(color))
|
.block(block(color))
|
||||||
|
|||||||
+24
-2
@@ -173,6 +173,16 @@ impl fmt::Display for Loading {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The application can be in these four states
|
||||||
|
/// Various functions (e.g input handler), operate differently depending upon current Status
|
||||||
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
|
pub enum Status {
|
||||||
|
Init,
|
||||||
|
Help,
|
||||||
|
DockerConnect,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
|
||||||
/// Global gui_state, stored in an Arc<Mutex>
|
/// Global gui_state, stored in an Arc<Mutex>
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GuiState {
|
pub struct GuiState {
|
||||||
@@ -180,8 +190,8 @@ pub struct GuiState {
|
|||||||
heading_map: HashMap<Header, Rect>,
|
heading_map: HashMap<Header, Rect>,
|
||||||
loading_icon: Loading,
|
loading_icon: Loading,
|
||||||
is_loading: HashSet<Uuid>,
|
is_loading: HashSet<Uuid>,
|
||||||
|
status: HashSet<Status>,
|
||||||
pub selected_panel: SelectablePanel,
|
pub selected_panel: SelectablePanel,
|
||||||
pub show_help: bool,
|
|
||||||
pub info_box_text: Option<String>,
|
pub info_box_text: Option<String>,
|
||||||
}
|
}
|
||||||
impl GuiState {
|
impl GuiState {
|
||||||
@@ -192,9 +202,9 @@ impl GuiState {
|
|||||||
heading_map: HashMap::new(),
|
heading_map: HashMap::new(),
|
||||||
loading_icon: Loading::One,
|
loading_icon: Loading::One,
|
||||||
selected_panel: SelectablePanel::Containers,
|
selected_panel: SelectablePanel::Containers,
|
||||||
show_help: false,
|
|
||||||
is_loading: HashSet::new(),
|
is_loading: HashSet::new(),
|
||||||
info_box_text: None,
|
info_box_text: None,
|
||||||
|
status: HashSet::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +252,18 @@ impl GuiState {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn status_push(&mut self, status: Status) {
|
||||||
|
self.status.insert(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn status_del(&mut self, status: Status) {
|
||||||
|
self.status.remove(&status);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn status_contains(&self, status: &[Status]) -> bool {
|
||||||
|
status.iter().any(|i| self.status.contains(i))
|
||||||
|
}
|
||||||
|
|
||||||
/// Change to next selectable panel
|
/// Change to next selectable panel
|
||||||
pub fn next_panel(&mut self) {
|
pub fn next_panel(&mut self) {
|
||||||
self.selected_panel = self.selected_panel.next();
|
self.selected_panel = self.selected_panel.next();
|
||||||
|
|||||||
+6
-5
@@ -25,7 +25,7 @@ mod draw_blocks;
|
|||||||
mod gui_state;
|
mod gui_state;
|
||||||
|
|
||||||
pub use self::color_match::*;
|
pub use self::color_match::*;
|
||||||
pub use self::gui_state::{GuiState, SelectablePanel};
|
pub use self::gui_state::{GuiState, SelectablePanel, Status};
|
||||||
use crate::{
|
use crate::{
|
||||||
app_data::AppData, app_error::AppError, docker_data::DockerMessage,
|
app_data::AppData, app_error::AppError, docker_data::DockerMessage,
|
||||||
input_handler::InputMessages,
|
input_handler::InputMessages,
|
||||||
@@ -85,8 +85,9 @@ async fn run_app<B: Backend + Send>(
|
|||||||
let input_poll_rate = std::time::Duration::from_millis(75);
|
let input_poll_rate = std::time::Duration::from_millis(75);
|
||||||
|
|
||||||
// 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 status_dockerconnect = gui_state.lock().status_contains(&[Status::DockerConnect]);
|
||||||
if let Some(AppError::DockerConnect) = e {
|
|
||||||
|
if status_dockerconnect {
|
||||||
let mut seconds = 5;
|
let mut seconds = 5;
|
||||||
loop {
|
loop {
|
||||||
if seconds < 1 {
|
if seconds < 1 {
|
||||||
@@ -138,6 +139,7 @@ async fn run_app<B: Backend + Send>(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -157,7 +159,7 @@ fn ui<B: Backend>(
|
|||||||
let log_index = app_data.lock().get_selected_log_index();
|
let log_index = app_data.lock().get_selected_log_index();
|
||||||
let sorted_by = app_data.lock().get_sorted();
|
let sorted_by = app_data.lock().get_sorted();
|
||||||
|
|
||||||
let show_help = gui_state.lock().show_help;
|
let show_help = gui_state.lock().status_contains(&[Status::Help]);
|
||||||
let info_text = gui_state.lock().info_box_text.clone();
|
let info_text = gui_state.lock().info_box_text.clone();
|
||||||
let loading_icon = gui_state.lock().get_loading();
|
let loading_icon = gui_state.lock().get_loading();
|
||||||
|
|
||||||
@@ -241,7 +243,6 @@ fn ui<B: Backend>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(error) = has_error {
|
if let Some(error) = has_error {
|
||||||
app_data.lock().show_error = true;
|
|
||||||
draw_blocks::error(f, error, None);
|
draw_blocks::error(f, error, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user