refactor: dead code removed
This commit is contained in:
@@ -3,15 +3,11 @@ use bollard::{
|
|||||||
service::ContainerSummary,
|
service::ContainerSummary,
|
||||||
Docker,
|
Docker,
|
||||||
};
|
};
|
||||||
use crossterm::{event::DisableMouseCapture, execute};
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{
|
sync::{atomic::AtomicBool, Arc},
|
||||||
atomic::{AtomicBool, Ordering},
|
|
||||||
Arc,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use tokio::{sync::mpsc::Receiver, task::JoinHandle};
|
use tokio::{sync::mpsc::Receiver, task::JoinHandle};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -438,7 +434,6 @@ impl DockerData {
|
|||||||
spawns: Arc::new(Mutex::new(HashMap::new())),
|
spawns: Arc::new(Mutex::new(HashMap::new())),
|
||||||
};
|
};
|
||||||
inner.initialise_container_data().await;
|
inner.initialise_container_data().await;
|
||||||
|
|
||||||
inner.message_handler().await;
|
inner.message_handler().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -14,7 +14,7 @@
|
|||||||
clippy::similar_names
|
clippy::similar_names
|
||||||
)]
|
)]
|
||||||
// Only allow when debugging
|
// Only allow when debugging
|
||||||
#![allow(unused)]
|
// #![allow(unused)]
|
||||||
|
|
||||||
use app_data::AppData;
|
use app_data::AppData;
|
||||||
use app_error::AppError;
|
use app_error::AppError;
|
||||||
@@ -27,10 +27,7 @@ use docker_data::DockerData;
|
|||||||
use input_handler::InputMessages;
|
use input_handler::InputMessages;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use parse_args::CliArgs;
|
use parse_args::CliArgs;
|
||||||
use std::{
|
use std::sync::{atomic::AtomicBool, Arc};
|
||||||
io::Write,
|
|
||||||
sync::{atomic::AtomicBool, Arc},
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::{Receiver, Sender};
|
use tokio::sync::mpsc::{Receiver, Sender};
|
||||||
use tracing::{info, Level};
|
use tracing::{info, Level};
|
||||||
|
|
||||||
|
|||||||
+27
-24
@@ -6,8 +6,7 @@ use crossterm::{
|
|||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Stdout, Write},
|
io::{self, Stdout},
|
||||||
process::Stdio,
|
|
||||||
sync::{atomic::Ordering, Arc},
|
sync::{atomic::Ordering, Arc},
|
||||||
};
|
};
|
||||||
use std::{sync::atomic::AtomicBool, time::Instant};
|
use std::{sync::atomic::AtomicBool, time::Instant};
|
||||||
@@ -35,12 +34,13 @@ pub struct Ui {
|
|||||||
docker_sx: Sender<DockerMessage>,
|
docker_sx: Sender<DockerMessage>,
|
||||||
gui_state: Arc<Mutex<GuiState>>,
|
gui_state: Arc<Mutex<GuiState>>,
|
||||||
is_running: Arc<AtomicBool>,
|
is_running: Arc<AtomicBool>,
|
||||||
|
now: Instant,
|
||||||
sender: Sender<InputMessages>,
|
sender: Sender<InputMessages>,
|
||||||
terminal: Terminal<CrosstermBackend<Stdout>>,
|
terminal: Terminal<CrosstermBackend<Stdout>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ui {
|
impl Ui {
|
||||||
/// Create a new Ui struct, and execute the drawing loops
|
/// Create a new Ui struct, and execute the drawing loop
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
app_data: Arc<Mutex<AppData>>,
|
app_data: Arc<Mutex<AppData>>,
|
||||||
docker_sx: Sender<DockerMessage>,
|
docker_sx: Sender<DockerMessage>,
|
||||||
@@ -48,35 +48,40 @@ impl Ui {
|
|||||||
is_running: Arc<AtomicBool>,
|
is_running: Arc<AtomicBool>,
|
||||||
sender: Sender<InputMessages>,
|
sender: Sender<InputMessages>,
|
||||||
) {
|
) {
|
||||||
if let Ok(mut terminal) = Self::start_terminal() {
|
if let Ok(terminal) = Self::setup_terminal() {
|
||||||
let mut ui = Self {
|
let mut ui = Self {
|
||||||
app_data,
|
app_data,
|
||||||
docker_sx,
|
docker_sx,
|
||||||
gui_state,
|
gui_state,
|
||||||
is_running,
|
is_running,
|
||||||
|
now: Instant::now(),
|
||||||
sender,
|
sender,
|
||||||
terminal,
|
terminal,
|
||||||
};
|
};
|
||||||
if let Err(e) = ui.draw_ui().await {
|
if let Err(e) = ui.draw_ui().await {
|
||||||
error!("{e}");
|
error!("{e}");
|
||||||
}
|
}
|
||||||
if let Err(e) = ui.end_terminal() {
|
if let Err(e) = ui.reset_terminal() {
|
||||||
error!("{e}");
|
error!("{e}");
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
error!("Terminal Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the terminal for full-screen drawing mode, with mouse capture
|
/// Setup the terminal for full-screen drawing mode, with mouse capture
|
||||||
fn start_terminal() -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
|
fn setup_terminal() -> io::Result<Terminal<CrosstermBackend<Stdout>>> {
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
execute!(stdout, EnableMouseCapture, EnterAlternateScreen)?;
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||||
let backend = CrosstermBackend::new(stdout);
|
let backend = CrosstermBackend::new(stdout);
|
||||||
Terminal::new(backend)
|
Terminal::new(backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// reset the terminal back to default settings
|
/// reset the terminal back to default settings
|
||||||
pub fn end_terminal(&mut self) -> Result<()> {
|
pub fn reset_terminal(&mut self) -> Result<()> {
|
||||||
|
self.terminal.clear()?;
|
||||||
|
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
execute!(
|
execute!(
|
||||||
self.terminal.backend_mut(),
|
self.terminal.backend_mut(),
|
||||||
@@ -90,20 +95,19 @@ impl Ui {
|
|||||||
/// Draw the the error message ui, for 5 seconds, with a countdown
|
/// Draw the the error message ui, for 5 seconds, with a countdown
|
||||||
fn err_loop(&mut self) -> Result<(), AppError> {
|
fn err_loop(&mut self) -> Result<(), AppError> {
|
||||||
let mut seconds = 5;
|
let mut seconds = 5;
|
||||||
let mut now = Instant::now();
|
|
||||||
loop {
|
loop {
|
||||||
// This is a fix for a weird bug on Linux + WSL which will output mouse movement to the stdout
|
// This is a fix for a weird bug on Linux + WSL which will output mouse movement to stdout
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
execute!(io::stdout(), EnableMouseCapture).unwrap_or(());
|
execute!(io::stdout(), EnableMouseCapture).unwrap_or(());
|
||||||
execute!(io::stdout(), DisableMouseCapture).unwrap_or(());
|
execute!(io::stdout(), DisableMouseCapture).unwrap_or(());
|
||||||
});
|
});
|
||||||
|
|
||||||
if now.elapsed() >= std::time::Duration::from_secs(1) {
|
if self.now.elapsed() >= std::time::Duration::from_secs(1) {
|
||||||
seconds -= 1;
|
seconds -= 1;
|
||||||
now = Instant::now();
|
self.now = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
if seconds < 1 {
|
if seconds < 1 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,14 +124,14 @@ impl Ui {
|
|||||||
|
|
||||||
/// The loop for drawing the main UI to the terminal
|
/// The loop for drawing the main UI to the terminal
|
||||||
async fn gui_loop(&mut self) -> Result<(), AppError> {
|
async fn gui_loop(&mut self) -> Result<(), AppError> {
|
||||||
let input_poll_rate = std::time::Duration::from_millis(100);
|
let input_poll_rate = std::time::Duration::from_millis(1);
|
||||||
let update_duration =
|
let update_duration =
|
||||||
std::time::Duration::from_millis(u64::from(self.app_data.lock().args.docker_interval));
|
std::time::Duration::from_millis(u64::from(self.app_data.lock().args.docker_interval));
|
||||||
let mut now = Instant::now();
|
|
||||||
while self.is_running.load(Ordering::SeqCst) {
|
while self.is_running.load(Ordering::SeqCst) {
|
||||||
if self
|
if self
|
||||||
.terminal
|
.terminal
|
||||||
.draw(|frame| ui(frame, &self.app_data, &self.gui_state))
|
.draw(|frame| ui_frame(frame, &self.app_data, &self.gui_state))
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
return Err(AppError::Terminal);
|
return Err(AppError::Terminal);
|
||||||
@@ -151,19 +155,18 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if now.elapsed() >= update_duration {
|
if self.now.elapsed() >= update_duration {
|
||||||
self.docker_sx
|
self.docker_sx
|
||||||
.send(DockerMessage::Update)
|
.send(DockerMessage::Update)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(());
|
.unwrap_or(());
|
||||||
now = Instant::now();
|
self.now = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Draw either the Error, or main oxker ui, to the terminal
|
||||||
/// Draw either the Error, or main oxker ui, to the terminal
|
|
||||||
async fn draw_ui(&mut self) -> Result<(), AppError> {
|
async fn draw_ui(&mut self) -> Result<(), AppError> {
|
||||||
let status_dockerconnect = self
|
let status_dockerconnect = self
|
||||||
.gui_state
|
.gui_state
|
||||||
@@ -180,7 +183,7 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the main ui to a frame of the terminal
|
/// Draw the main ui to a frame of the terminal
|
||||||
fn ui<B: Backend>(
|
fn ui_frame<B: Backend>(
|
||||||
f: &mut Frame<'_, B>,
|
f: &mut Frame<'_, B>,
|
||||||
app_data: &Arc<Mutex<AppData>>,
|
app_data: &Arc<Mutex<AppData>>,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
@@ -232,7 +235,7 @@ fn ui<B: Backend>(
|
|||||||
vec![Constraint::Percentage(100)]
|
vec![Constraint::Percentage(100)]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Split into 3, containers+controls, logs, then graphs
|
// Split into 2, logs, and optional charts
|
||||||
let lower_main = Layout::default()
|
let lower_main = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(lower_split.as_ref())
|
.constraints(lower_split.as_ref())
|
||||||
|
|||||||
Reference in New Issue
Block a user