From 7e4a960b888f1dab524d6045504162cea1171d20 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Fri, 21 Feb 2025 22:45:06 +0000 Subject: [PATCH] feat: update Rust edition to 2024 --- Cargo.toml | 2 +- src/app_data/container_state.rs | 33 +++-- src/app_data/mod.rs | 4 +- src/docker_data/mod.rs | 6 +- src/exec.rs | 75 +++++------ src/input_handler/mod.rs | 4 +- src/main.rs | 6 +- src/ui/color_match.rs | 2 +- src/ui/draw_blocks/charts.rs | 34 ++--- src/ui/draw_blocks/commands.rs | 4 +- src/ui/draw_blocks/containers.rs | 36 +++--- src/ui/draw_blocks/delete_confirm.rs | 4 +- src/ui/draw_blocks/error.rs | 4 +- src/ui/draw_blocks/filter.rs | 14 +-- src/ui/draw_blocks/headers.rs | 178 ++++++++++++++++++++++----- src/ui/draw_blocks/help.rs | 146 ++++++++++++---------- src/ui/draw_blocks/info.rs | 4 +- src/ui/draw_blocks/logs.rs | 10 +- src/ui/draw_blocks/mod.rs | 10 +- src/ui/draw_blocks/ports.rs | 8 +- src/ui/mod.rs | 47 +++---- 21 files changed, 387 insertions(+), 244 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 547a46a..9c1ad0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "oxker" version = "0.9.0" -edition = "2021" +edition = "2024" authors = ["Jack Wills "] description = "A simple tui to view & control docker containers" repository = "https://github.com/mrjackwills/oxker" diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index a510e61..d1d3786 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -6,7 +6,7 @@ use std::{ }; use bollard::service::Port; -use jiff::{tz::TimeZone, Timestamp}; +use jiff::{Timestamp, tz::TimeZone}; use ratatui::{ style::Color, widgets::{ListItem, ListState}, @@ -177,25 +177,24 @@ impl StatefulList { pub fn next(&mut self) { if !self.items.is_empty() { - self.state.select(Some(self.state.selected().map_or(0, |i| { - if i < self.items.len() - 1 { - i + 1 - } else { - i - } - }))); + self.state.select(Some( + self.state.selected().map_or( + 0, + |i| { + if i < self.items.len() - 1 { i + 1 } else { i } + }, + ), + )); } } pub fn previous(&mut self) { if !self.items.is_empty() { - self.state.select(Some(self.state.selected().map_or(0, |i| { - if i == 0 { - 0 - } else { - i - 1 - } - }))); + self.state.select(Some( + self.state + .selected() + .map_or(0, |i| if i == 0 { 0 } else { i - 1 }), + )); } } @@ -697,7 +696,7 @@ impl ContainerItem { self.cpu_stats .iter() .enumerate() - .map(|i| (i.0 as f64, i.1 .0)) + .map(|i| (i.0 as f64, i.1.0)) .collect::>() } @@ -707,7 +706,7 @@ impl ContainerItem { self.mem_stats .iter() .enumerate() - .map(|i| (i.0 as f64, i.1 .0 as f64)) + .map(|i| (i.0 as f64, i.1.0 as f64)) .collect::>() } diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 658e2e4..c01988a 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -11,10 +11,10 @@ use std::{ mod container_state; use crate::{ + ENTRY_POINT, app_error::AppError, config::Config, - ui::{log_sanitizer, GuiState, Redraw, Status}, - ENTRY_POINT, + ui::{GuiState, Redraw, Status, log_sanitizer}, }; pub use container_state::*; diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 87382a5..dfa561b 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -1,16 +1,16 @@ use bollard::{ + Docker, container::{ ListContainersOptions, LogsOptions, MemoryStatsStats, RemoveContainerOptions, StartContainerOptions, Stats, StatsOptions, }, service::ContainerSummary, - Docker, }; use futures_util::StreamExt; use parking_lot::Mutex; use std::{ collections::HashMap, - sync::{atomic::AtomicUsize, Arc}, + sync::{Arc, atomic::AtomicUsize}, }; use tokio::{ sync::mpsc::{Receiver, Sender}, @@ -19,11 +19,11 @@ use tokio::{ use uuid::Uuid; use crate::{ + ENTRY_POINT, app_data::{AppData, ContainerId, DockerCommand, State}, app_error::AppError, config::Config, ui::{GuiState, Status}, - ENTRY_POINT, }; mod message; pub use message::DockerMessage; diff --git a/src/exec.rs b/src/exec.rs index a7c3b8b..0a49edd 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -1,16 +1,16 @@ use std::{ io::{Read, Stdout, Write}, - sync::{atomic::AtomicBool, mpsc::Sender, Arc}, + sync::{Arc, atomic::AtomicBool, mpsc::Sender}, }; use bollard::{ - exec::{CreateExecOptions, ResizeExecOptions, StartExecOptions, StartExecResults}, Docker, + exec::{CreateExecOptions, ResizeExecOptions, StartExecOptions, StartExecResults}, }; use crossterm::terminal::enable_raw_mode; use futures_util::StreamExt; use parking_lot::Mutex; -use ratatui::{backend::CrosstermBackend, Terminal}; +use ratatui::{Terminal, backend::CrosstermBackend}; use tokio::{ fs::File, io::{AsyncReadExt, AsyncWriteExt}, @@ -253,10 +253,7 @@ impl ExecMode { ) .await { - if let Ok(StartExecResults::Attached { - mut output, - mut input, - }) = docker + match docker .start_exec( &exec_result.id, Some(StartExecOptions { @@ -266,40 +263,46 @@ impl ExecMode { ) .await { - if let Some(tty) = AsyncTTY::get(&cancel_token) { - tokio::spawn(async move { - enable_raw_mode().ok(); - let mut stdout = std::io::stdout(); - stdout.write_all(CURSOR_POS.as_bytes()).ok(); - stdout.flush().ok(); - while let Some(Ok(x)) = output.next().await { - stdout.write_all(&x.into_bytes()).ok(); + Ok(StartExecResults::Attached { + mut output, + mut input, + }) => { + if let Some(tty) = AsyncTTY::get(&cancel_token) { + tokio::spawn(async move { + enable_raw_mode().ok(); + let mut stdout = std::io::stdout(); + stdout.write_all(CURSOR_POS.as_bytes()).ok(); stdout.flush().ok(); + while let Some(Ok(x)) = output.next().await { + stdout.write_all(&x.into_bytes()).ok(); + stdout.flush().ok(); + } + cancel_token.cancel(); + }); + + if let Some(terminal_size) = terminal_size { + docker + .resize_exec( + &exec_result.id, + ResizeExecOptions { + height: terminal_size.height, + width: terminal_size.width, + }, + ) + .await + .ok(); } - cancel_token.cancel(); - }); - if let Some(terminal_size) = terminal_size { - docker - .resize_exec( - &exec_result.id, - ResizeExecOptions { - height: terminal_size.height, - width: terminal_size.width, - }, - ) - .await - .ok(); + while let Ok(x) = tty.rx.recv() { + input.write_all(&[x]).await.ok(); + } + + self.internal_cleanup()?; } - - while let Ok(x) = tty.rx.recv() { - input.write_all(&[x]).await.ok(); - } - - self.internal_cleanup()?; } - } else { - return Err(AppError::Terminal); + _ => { + return Err(AppError::Terminal); + } } } Ok(()) diff --git a/src/input_handler/mod.rs b/src/input_handler/mod.rs index fad84a6..7ba06b0 100644 --- a/src/input_handler/mod.rs +++ b/src/input_handler/mod.rs @@ -1,7 +1,7 @@ use std::{ fs::OpenOptions, io::{BufWriter, Write}, - sync::{atomic::AtomicBool, Arc}, + sync::{Arc, atomic::AtomicBool}, time::SystemTime, }; @@ -23,7 +23,7 @@ use crate::{ app_error::AppError, config, docker_data::DockerMessage, - exec::{tty_readable, ExecMode}, + exec::{ExecMode, tty_readable}, ui::{DeleteButton, GuiState, SelectablePanel, Status, Ui}, }; pub use message::InputMessages; diff --git a/src/main.rs b/src/main.rs index 2f2b2eb..6a0142d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use app_data::AppData; use app_error::AppError; -use bollard::{Docker, API_DEFAULT_VERSION}; +use bollard::{API_DEFAULT_VERSION, Docker}; use config::Config; use docker_data::DockerData; use input_handler::InputMessages; @@ -8,12 +8,12 @@ use parking_lot::Mutex; use std::{ process, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, }; use tokio::sync::mpsc::{Receiver, Sender}; -use tracing::{error, info, Level}; +use tracing::{Level, error, info}; mod app_data; mod app_error; diff --git a/src/ui/color_match.rs b/src/ui/color_match.rs index a065a8e..b54d63a 100644 --- a/src/ui/color_match.rs +++ b/src/ui/color_match.rs @@ -1,6 +1,6 @@ pub mod log_sanitizer { - use cansi::{v3::categorise_text, Color as CansiColor, Intensity}; + use cansi::{Color as CansiColor, Intensity, v3::categorise_text}; use ratatui::{ style::{Color, Modifier, Style}, text::{Line, Span}, diff --git a/src/ui/draw_blocks/charts.rs b/src/ui/draw_blocks/charts.rs index f35454b..0de3f48 100644 --- a/src/ui/draw_blocks/charts.rs +++ b/src/ui/draw_blocks/charts.rs @@ -1,15 +1,15 @@ use std::fmt::Display; use ratatui::{ + Frame, layout::{Alignment, Direction, Layout, Rect}, style::{Color, Modifier, Style, Stylize}, symbols, text::Span, widgets::{Axis, Block, BorderType, Borders, Chart, Dataset, GraphType}, - Frame, }; -use super::{FrameData, CONSTRAINT_50_50}; +use super::{CONSTRAINT_50_50, FrameData}; use crate::{ app_data::{ByteStats, CpuStats, State, Stats}, config::AppColors, @@ -124,16 +124,20 @@ pub fn draw(area: Rect, colors: AppColors, f: &mut Frame, fd: &FrameData) { .constraints(CONSTRAINT_50_50) .split(area); - let cpu_dataset = vec![Dataset::default() - .marker(symbols::Marker::Dot) - .style(Style::default().fg(colors.chart_cpu.points)) - .graph_type(GraphType::Line) - .data(&cpu.0)]; - let mem_dataset = vec![Dataset::default() - .marker(symbols::Marker::Dot) - .style(Style::default().fg(colors.chart_memory.points)) - .graph_type(GraphType::Line) - .data(&mem.0)]; + let cpu_dataset = vec![ + Dataset::default() + .marker(symbols::Marker::Dot) + .style(Style::default().fg(colors.chart_cpu.points)) + .graph_type(GraphType::Line) + .data(&cpu.0), + ]; + let mem_dataset = vec![ + Dataset::default() + .marker(symbols::Marker::Dot) + .style(Style::default().fg(colors.chart_memory.points)) + .graph_type(GraphType::Line) + .data(&mem.0), + ]; let cpu_stats = CpuStats::new(cpu.0.last().map_or(0.00, |f| f.1)); #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] @@ -169,10 +173,10 @@ mod tests { app_data::State, config::AppColors, ui::{ - draw_blocks::tests::{ - expected_to_vec, get_result, insert_chart_data, test_setup, COLOR_ORANGE, - }, FrameData, + draw_blocks::tests::{ + COLOR_ORANGE, expected_to_vec, get_result, insert_chart_data, test_setup, + }, }, }; diff --git a/src/ui/draw_blocks/commands.rs b/src/ui/draw_blocks/commands.rs index 100ffc0..25dc74f 100644 --- a/src/ui/draw_blocks/commands.rs +++ b/src/ui/draw_blocks/commands.rs @@ -8,11 +8,11 @@ use crate::{ }; use parking_lot::Mutex; use ratatui::{ + Frame, layout::{Alignment, Rect}, style::{Modifier, Style, Stylize}, text::{Line, Span}, widgets::{List, ListItem, Paragraph}, - Frame, }; use super::generate_block; @@ -61,8 +61,8 @@ mod tests { config::AppColors, tests::gen_container_summary, ui::{ - draw_blocks::tests::{expected_to_vec, get_result, test_setup, BORDER_CHARS}, FrameData, + draw_blocks::tests::{BORDER_CHARS, expected_to_vec, get_result, test_setup}, }, }; diff --git a/src/ui/draw_blocks/containers.rs b/src/ui/draw_blocks/containers.rs index 0082a3b..b817785 100644 --- a/src/ui/draw_blocks/containers.rs +++ b/src/ui/draw_blocks/containers.rs @@ -3,11 +3,11 @@ use std::sync::Arc; use super::MARGIN; use parking_lot::Mutex; use ratatui::{ + Frame, layout::{Alignment, Rect}, style::{Modifier, Style, Stylize}, text::{Line, Span}, widgets::{List, ListItem, Paragraph}, - Frame, }; use crate::{ @@ -16,7 +16,7 @@ use crate::{ ui::{FrameData, GuiState, SelectablePanel}, }; -use super::{generate_block, CIRCLE}; +use super::{CIRCLE, generate_block}; /// Format the container data to display nicely on the screen fn format_containers<'a>(colors: AppColors, i: &ContainerItem, widths: &Columns) -> Line<'a> { @@ -142,11 +142,11 @@ mod tests { app_data::{ContainerImage, ContainerName, ContainerStatus, State, StatefulList}, config::AppColors, ui::{ - draw_blocks::tests::{ - expected_to_vec, get_result, test_setup, TuiTestSetup, BORDER_CHARS, COLOR_ORANGE, - COLOR_RX, COLOR_TX, - }, FrameData, + draw_blocks::tests::{ + BORDER_CHARS, COLOR_ORANGE, COLOR_RX, COLOR_TX, TuiTestSetup, expected_to_vec, + get_result, test_setup, + }, }, }; @@ -318,7 +318,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); let colors = setup.app_data.lock().config.app_colors; @@ -671,13 +671,13 @@ mod tests { setup.app_data.lock().containers.items[0].state = State::from(("running", &status)); setup.app_data.lock().containers.items[0].status = status; - let expected= [ + let expected = [ "╭ Containers 1/3 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮", "│⚪ container_1 ! running Up 1 hour (unhealthy) 00.00% 0.00 kB / 0.00 kB 1 image_1 0.00 kB 0.00 kB │", "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); let colors = setup.app_data.lock().config.app_colors; @@ -778,7 +778,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); let mut colors = AppColors::new(); @@ -852,7 +852,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -898,7 +898,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -945,7 +945,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -991,7 +991,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -1037,7 +1037,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -1083,7 +1083,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -1129,7 +1129,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); @@ -1175,7 +1175,7 @@ mod tests { "│ container_2 ✓ running Up 2 hour 00.00% 0.00 kB / 0.00 kB 2 image_2 0.00 kB 0.00 kB │", "│ container_3 ✓ running Up 3 hour 00.00% 0.00 kB / 0.00 kB 3 image_3 0.00 kB 0.00 kB │", "│ │", - "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯" + "╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯", ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); diff --git a/src/ui/draw_blocks/delete_confirm.rs b/src/ui/draw_blocks/delete_confirm.rs index e7659f3..efa1345 100644 --- a/src/ui/draw_blocks/delete_confirm.rs +++ b/src/ui/draw_blocks/delete_confirm.rs @@ -2,11 +2,11 @@ use std::sync::Arc; use parking_lot::Mutex; use ratatui::{ + Frame, layout::{Alignment, Direction, Layout}, style::{Modifier, Style}, text::{Line, Span}, widgets::{Block, BorderType, Borders, Clear, Paragraph}, - Frame, }; use super::{CONSTRAINT_BUTTONS, CONSTRAINT_POPUP}; @@ -14,8 +14,8 @@ use crate::{ app_data::ContainerName, config::{AppColors, Keymap}, ui::{ - gui_state::{BoxLocation, Region}, DeleteButton, GuiState, + gui_state::{BoxLocation, Region}, }, }; diff --git a/src/ui/draw_blocks/error.rs b/src/ui/draw_blocks/error.rs index c21b857..551b023 100644 --- a/src/ui/draw_blocks/error.rs +++ b/src/ui/draw_blocks/error.rs @@ -1,11 +1,11 @@ use ratatui::{ + Frame, layout::Alignment, style::Style, widgets::{Block, BorderType, Borders, Clear, Paragraph}, - Frame, }; -use super::{max_line_width, NAME, VERSION}; +use super::{NAME, VERSION, max_line_width}; use crate::{ app_error::AppError, config::{AppColors, Keymap}, diff --git a/src/ui/draw_blocks/filter.rs b/src/ui/draw_blocks/filter.rs index 54e280e..5e39cb4 100644 --- a/src/ui/draw_blocks/filter.rs +++ b/src/ui/draw_blocks/filter.rs @@ -1,8 +1,8 @@ use ratatui::{ + Frame, layout::Rect, style::{Modifier, Style, Stylize}, text::{Line, Span}, - Frame, }; use crate::{app_data::FilterBy, config::AppColors, ui::FrameData}; @@ -76,8 +76,8 @@ mod tests { use crate::{ config::AppColors, ui::{ - draw_blocks::tests::{expected_to_vec, get_result, test_setup}, FrameData, + draw_blocks::tests::{expected_to_vec, get_result, test_setup}, }, }; @@ -101,7 +101,7 @@ mod tests { .unwrap(); let expected = [ - " Esc clear ← by → Name Image Status All term: " + " Esc clear ← by → Name Image Status All term: ", ]; for (row_index, result_row) in get_result(&setup, w) { @@ -148,7 +148,7 @@ mod tests { .unwrap(); let expected = [ - " Esc clear ← by → Name Image Status All term: cd " + " Esc clear ← by → Name Image Status All term: cd ", ]; for (row_index, result_row) in get_result(&setup, w) { @@ -193,8 +193,8 @@ mod tests { .unwrap(); let expected = [ - " Esc clear ← by → Name Image Status All term: cd " - ]; + " Esc clear ← by → Name Image Status All term: cd ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -257,7 +257,7 @@ mod tests { .unwrap(); let expected = [ - " Esc clear ← by → Name Image Status All term: cd " + " Esc clear ← by → Name Image Status All term: cd ", ]; for (row_index, result_row) in get_result(&setup, w) { diff --git a/src/ui/draw_blocks/headers.rs b/src/ui/draw_blocks/headers.rs index 3450deb..7feae86 100644 --- a/src/ui/draw_blocks/headers.rs +++ b/src/ui/draw_blocks/headers.rs @@ -2,17 +2,17 @@ use std::sync::Arc; use parking_lot::Mutex; use ratatui::{ + Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Color, Style}, widgets::{Block, Paragraph}, - Frame, }; use super::{CONSTRAINT_100, MARGIN}; use crate::{ app_data::{Header, SortedOrder}, config::{AppColors, Keymap}, - ui::{gui_state::Region, FrameData, GuiState, Status}, + ui::{FrameData, GuiState, Status, gui_state::Region}, }; // Draw heading bar at top of program, always visible @@ -191,8 +191,8 @@ mod tests { app_data::{Header, SortedOrder, StatefulList}, config::{AppColors, Keymap}, ui::{ - draw_blocks::tests::{expected_to_vec, get_result, test_setup}, FrameData, Status, + draw_blocks::tests::{expected_to_vec, get_result, test_setup}, }, }; @@ -205,7 +205,9 @@ mod tests { let mut fd = FrameData::from((&setup.app_data, &setup.gui_state)); - let expected = [" ( h ) show help "]; + let expected = [ + " ( h ) show help ", + ]; setup .terminal @@ -231,7 +233,9 @@ mod tests { } fd.status.insert(Status::Help); - let expected = [" ( h ) exit help "]; + let expected = [ + " ( h ) exit help ", + ]; setup .terminal .draw(|f| { @@ -263,7 +267,9 @@ mod tests { let mut setup = test_setup(w, h, true, true); let fd = FrameData::from((&setup.app_data, &setup.gui_state)); - let expected = [" name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "]; + let expected = [ + " name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ]; setup .terminal .draw(|f| { @@ -385,32 +391,140 @@ mod tests { }; // Name - test(&[" name ▲ state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "], 1..=17, (Header::Name, SortedOrder::Asc)); - test(&[" name ▼ state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "], 1..=17, (Header::Name, SortedOrder::Desc)); + test( + &[ + " name ▲ state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 1..=17, + (Header::Name, SortedOrder::Asc), + ); + test( + &[ + " name ▼ state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 1..=17, + (Header::Name, SortedOrder::Desc), + ); // state - test(&[" name state ▲ status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "],18..=29, (Header::State, SortedOrder::Asc)); - test(&[" name state ▼ status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "], 18..=29, (Header::State, SortedOrder::Desc)); + test( + &[ + " name state ▲ status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 18..=29, + (Header::State, SortedOrder::Asc), + ); + test( + &[ + " name state ▼ status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 18..=29, + (Header::State, SortedOrder::Desc), + ); // status - test(&[" name state status ▲ cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "], 30..=41, (Header::Status, SortedOrder::Asc)); - test(&[" name state status ▼ cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "], 30..=41, (Header::Status, SortedOrder::Desc)); + test( + &[ + " name state status ▲ cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 30..=41, + (Header::Status, SortedOrder::Asc), + ); + test( + &[ + " name state status ▼ cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 30..=41, + (Header::Status, SortedOrder::Desc), + ); // cpu - test(&[" name state status cpu ▲ memory/limit id image ↓ rx ↑ tx ( h ) show help "],42..=50, (Header::Cpu, SortedOrder::Asc)); - test(&[" name state status cpu ▼ memory/limit id image ↓ rx ↑ tx ( h ) show help "],42..=50, (Header::Cpu, SortedOrder::Desc)); + test( + &[ + " name state status cpu ▲ memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 42..=50, + (Header::Cpu, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu ▼ memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ], + 42..=50, + (Header::Cpu, SortedOrder::Desc), + ); // memory - test(&[" name state status cpu memory/limit ▲ id image ↓ rx ↑ tx ( h ) show help "], 51..=70, (Header::Memory, SortedOrder::Asc)); - test(&[" name state status cpu memory/limit ▼ id image ↓ rx ↑ tx ( h ) show help "], 51..=70, (Header::Memory, SortedOrder::Desc)); + test( + &[ + " name state status cpu memory/limit ▲ id image ↓ rx ↑ tx ( h ) show help ", + ], + 51..=70, + (Header::Memory, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu memory/limit ▼ id image ↓ rx ↑ tx ( h ) show help ", + ], + 51..=70, + (Header::Memory, SortedOrder::Desc), + ); //id - test(&[" name state status cpu memory/limit id ▲ image ↓ rx ↑ tx ( h ) show help "], 71..=81, (Header::Id, SortedOrder::Asc)); - test(&[" name state status cpu memory/limit id ▼ image ↓ rx ↑ tx ( h ) show help "], 71..=81, (Header::Id, SortedOrder::Desc)); + test( + &[ + " name state status cpu memory/limit id ▲ image ↓ rx ↑ tx ( h ) show help ", + ], + 71..=81, + (Header::Id, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu memory/limit id ▼ image ↓ rx ↑ tx ( h ) show help ", + ], + 71..=81, + (Header::Id, SortedOrder::Desc), + ); // image - test(&[" name state status cpu memory/limit id image ▲ ↓ rx ↑ tx ( h ) show help "], 82..=91, (Header::Image, SortedOrder::Asc)); - test(&[" name state status cpu memory/limit id image ▼ ↓ rx ↑ tx ( h ) show help "], 82..=91, (Header::Image, SortedOrder::Desc)); + test( + &[ + " name state status cpu memory/limit id image ▲ ↓ rx ↑ tx ( h ) show help ", + ], + 82..=91, + (Header::Image, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu memory/limit id image ▼ ↓ rx ↑ tx ( h ) show help ", + ], + 82..=91, + (Header::Image, SortedOrder::Desc), + ); // rx - test(&[" name state status cpu memory/limit id image ↓ rx ▲ ↑ tx ( h ) show help "], 92..=101, (Header::Rx, SortedOrder::Asc)); - test(&[" name state status cpu memory/limit id image ↓ rx ▼ ↑ tx ( h ) show help "], 92..=101, (Header::Rx, SortedOrder::Desc)); + test( + &[ + " name state status cpu memory/limit id image ↓ rx ▲ ↑ tx ( h ) show help ", + ], + 92..=101, + (Header::Rx, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu memory/limit id image ↓ rx ▼ ↑ tx ( h ) show help ", + ], + 92..=101, + (Header::Rx, SortedOrder::Desc), + ); // tx - test(&[" name state status cpu memory/limit id image ↓ rx ↑ tx ▲ ( h ) show help "], 102..=111, (Header::Tx, SortedOrder::Asc)); - test(&[" name state status cpu memory/limit id image ↓ rx ↑ tx ▼ ( h ) show help "], 102..=111, (Header::Tx, SortedOrder::Desc)); + test( + &[ + " name state status cpu memory/limit id image ↓ rx ↑ tx ▲ ( h ) show help ", + ], + 102..=111, + (Header::Tx, SortedOrder::Asc), + ); + test( + &[ + " name state status cpu memory/limit id image ↓ rx ↑ tx ▼ ( h ) show help ", + ], + 102..=111, + (Header::Tx, SortedOrder::Desc), + ); } #[test] @@ -422,7 +536,9 @@ mod tests { setup.gui_state.lock().next_loading(uuid); let fd = FrameData::from((&setup.app_data, &setup.gui_state)); - let expected = [" ⠙ name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "]; + let expected = [ + " ⠙ name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ]; setup .terminal @@ -472,7 +588,9 @@ mod tests { colors.headers_bar.text = Color::Blue; colors.headers_bar.text_selected = Color::Yellow; - let expected = [" ⠙ name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help "]; + let expected = [ + " ⠙ name state status cpu memory/limit id image ↓ rx ↑ tx ( h ) show help ", + ]; setup .terminal @@ -509,7 +627,9 @@ mod tests { keymap.toggle_help = (KeyCode::Char('T'), None); - let expected = [" name state status cpu memory/limit id image ↓ rx ↑ tx ( T ) show help "]; + let expected = [ + " name state status cpu memory/limit id image ↓ rx ↑ tx ( T ) show help ", + ]; setup .terminal .draw(|f| { @@ -532,7 +652,9 @@ mod tests { } keymap.toggle_help = (KeyCode::Char('T'), Some(KeyCode::Tab)); - let expected = [" name state status cpu memory/limit id image ↓ rx ↑ tx ( T | Tab ) show help "]; + let expected = [ + " name state status cpu memory/limit id image ↓ rx ↑ tx ( T | Tab ) show help ", + ]; setup .terminal .draw(|f| { diff --git a/src/ui/draw_blocks/help.rs b/src/ui/draw_blocks/help.rs index f01ddca..a7dd43c 100644 --- a/src/ui/draw_blocks/help.rs +++ b/src/ui/draw_blocks/help.rs @@ -1,11 +1,11 @@ use crossterm::event::KeyCode; use jiff::tz::TimeZone; use ratatui::{ + Frame, layout::{Alignment, Constraint, Direction, Layout}, style::{Color, Modifier, Style}, text::{Line, Span}, widgets::{Block, BorderType, Borders, Clear, Paragraph}, - Frame, }; use crate::{ @@ -13,7 +13,7 @@ use crate::{ ui::gui_state::BoxLocation, }; -use super::{popup, DESCRIPTION, NAME_TEXT, REPO, VERSION}; +use super::{DESCRIPTION, NAME_TEXT, REPO, VERSION, popup}; /// Help popup box needs these three pieces of information struct HelpInfo { @@ -445,9 +445,11 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ - " ", + " ", version_row.as_str(), " │ │ ", " │ 88 │ ", @@ -479,8 +481,8 @@ mod tests { " │ │ ", " │ │ ", " ╰───────────────────────────────────────────────────────────────────────────────────╯ ", - " " - ]; + " ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -551,9 +553,11 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ - " ", + " ", version_row.as_str(), " │ │ ", " │ 88 │ ", @@ -585,8 +589,8 @@ mod tests { " │ │ ", " │ │ ", " ╰───────────────────────────────────────────────────────────────────────────────────╯ ", - " " - ]; + " ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -675,7 +679,9 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ─────────────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ─────────────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ " ", version_row.as_str(), @@ -723,8 +729,8 @@ mod tests { " │ │ ", " │ │ ", " ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ", - " " - ]; + " ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -777,56 +783,58 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ - " ", + " ", version_row.as_str(), - " │ │ ", - " │ 88 │ ", - " │ 88 │ ", - " │ 88 │ ", - " │ ,adPPYba, 8b, ,d8 88 ,d8 ,adPPYba, 8b,dPPYba, │ ", - r#" │ a8" "8a `Y8, ,8P' 88 ,a8" a8P_____88 88P' "Y8 │ "#, - r#" │ 8b d8 )888( 8888[ 8PP""""""" 88 │ "#, - r#" │ "8a, ,a8" ,d8" "8b, 88`"Yba, "8b, ,aa 88 │ "#, - r#" │ `"YbbdP"' 8P' `Y8 88 `Y8a `"Ybbd8"' 88 │ "#, - " │ │ ", - " │ A simple tui to view & control docker containers │ ", - " │ │ ", - " │ ( 0 ) or ( 1 ) select next panel │ ", - " │ ( 2 ) or ( 3 ) select previous panel │ ", - " │ ( q ) or ( r ) scroll list down by one │ ", - " │ ( y ) or ( z ) scroll list up by one │ ", - " │ ( o ) or ( p ) scroll list down by many │ ", - " │ ( w ) or ( x ) scroll list by up many │ ", - " │ ( s ) or ( t ) scroll list to end │ ", - " │ ( u ) or ( v ) scroll list to start │ ", - " │ ( enter ) send docker container command │ ", - " │ ( g ) or ( h ) exec into a container │ ", - " │ ( Home ) or ( Del ) toggle this help information - or click heading │ ", - " │ ( Home ) or ( Del ) save logs to file │ ", - " │ ( Page Down ) or ( Page Up ) toggle mouse capture - if disabled, text on screen can be selected & copied │ ", - " │ ( i ) or ( j ) enter filter mode │ ", - " │ ( Up ) or ( Down ) reset container sorting │ ", - " │ ( 4 ) or ( 5 ) sort containers by name │ ", - " │ ( 6 ) or ( 7 ) sort containers by state │ ", - " │ ( 8 ) or ( 9 ) sort containers by status │ ", - " │ ( F1 ) or ( F12 ) sort containers by cpu │ ", - " │ ( # ) or ( - ) sort containers by memory │ ", - " │ ( / ) or ( = ) sort containers by id │ ", - r" │ ( , ) or ( \ ) sort containers by image │ ", - " │ ( . ) or ( ] ) sort containers by rx │ ", - " │ ( Backspace ) or ( Back Tab ) sort containers by tx │ ", - " │ ( a ) or ( b ) close dialog │ ", - " │ ( k ) or ( l ) quit at any time │ ", - " │ │ ", - " │ currently an early work in progress, all and any input appreciated │ ", - " │ https://github.com/mrjackwills/oxker │ ", - " │ │ ", - " │ │ ", - " ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ", - " ", - ]; + " │ │ ", + " │ 88 │ ", + " │ 88 │ ", + " │ 88 │ ", + " │ ,adPPYba, 8b, ,d8 88 ,d8 ,adPPYba, 8b,dPPYba, │ ", + r#" │ a8" "8a `Y8, ,8P' 88 ,a8" a8P_____88 88P' "Y8 │ "#, + r#" │ 8b d8 )888( 8888[ 8PP""""""" 88 │ "#, + r#" │ "8a, ,a8" ,d8" "8b, 88`"Yba, "8b, ,aa 88 │ "#, + r#" │ `"YbbdP"' 8P' `Y8 88 `Y8a `"Ybbd8"' 88 │ "#, + " │ │ ", + " │ A simple tui to view & control docker containers │ ", + " │ │ ", + " │ ( 0 ) or ( 1 ) select next panel │ ", + " │ ( 2 ) or ( 3 ) select previous panel │ ", + " │ ( q ) or ( r ) scroll list down by one │ ", + " │ ( y ) or ( z ) scroll list up by one │ ", + " │ ( o ) or ( p ) scroll list down by many │ ", + " │ ( w ) or ( x ) scroll list by up many │ ", + " │ ( s ) or ( t ) scroll list to end │ ", + " │ ( u ) or ( v ) scroll list to start │ ", + " │ ( enter ) send docker container command │ ", + " │ ( g ) or ( h ) exec into a container │ ", + " │ ( Home ) or ( Del ) toggle this help information - or click heading │ ", + " │ ( Home ) or ( Del ) save logs to file │ ", + " │ ( Page Down ) or ( Page Up ) toggle mouse capture - if disabled, text on screen can be selected & copied │ ", + " │ ( i ) or ( j ) enter filter mode │ ", + " │ ( Up ) or ( Down ) reset container sorting │ ", + " │ ( 4 ) or ( 5 ) sort containers by name │ ", + " │ ( 6 ) or ( 7 ) sort containers by state │ ", + " │ ( 8 ) or ( 9 ) sort containers by status │ ", + " │ ( F1 ) or ( F12 ) sort containers by cpu │ ", + " │ ( # ) or ( - ) sort containers by memory │ ", + " │ ( / ) or ( = ) sort containers by id │ ", + r" │ ( , ) or ( \ ) sort containers by image │ ", + " │ ( . ) or ( ] ) sort containers by rx │ ", + " │ ( Backspace ) or ( Back Tab ) sort containers by tx │ ", + " │ ( a ) or ( b ) close dialog │ ", + " │ ( k ) or ( l ) quit at any time │ ", + " │ │ ", + " │ currently an early work in progress, all and any input appreciated │ ", + " │ https://github.com/mrjackwills/oxker │ ", + " │ │ ", + " │ │ ", + " ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ", + " ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -881,7 +889,9 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ " ", version_row.as_str(), @@ -930,7 +940,7 @@ mod tests { " │ │ ", " ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ", " ", - ]; + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); @@ -958,9 +968,11 @@ mod tests { }) .unwrap(); - let version_row = format!(" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "); + let version_row = format!( + " ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ " + ); let expected = [ - " ", + " ", version_row.as_str(), " │ │ ", " │ 88 │ ", @@ -994,8 +1006,8 @@ mod tests { " │ │ ", " │ │ ", " ╰───────────────────────────────────────────────────────────────────────────────────╯ ", - " " - ]; + " ", + ]; for (row_index, result_row) in get_result(&setup, w) { let expected_row = expected_to_vec(&expected, row_index); diff --git a/src/ui/draw_blocks/info.rs b/src/ui/draw_blocks/info.rs index 7f65310..5016a46 100644 --- a/src/ui/draw_blocks/info.rs +++ b/src/ui/draw_blocks/info.rs @@ -2,15 +2,15 @@ use std::{sync::Arc, time::Instant}; use parking_lot::Mutex; use ratatui::{ + Frame, layout::Alignment, style::Style, widgets::{Block, Borders, Clear, Paragraph}, - Frame, }; use crate::{ config::AppColors, - ui::{gui_state::BoxLocation, GuiState}, + ui::{GuiState, gui_state::BoxLocation}, }; use super::{max_line_width, popup}; diff --git a/src/ui/draw_blocks/logs.rs b/src/ui/draw_blocks/logs.rs index 8ca623b..2510f92 100644 --- a/src/ui/draw_blocks/logs.rs +++ b/src/ui/draw_blocks/logs.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use parking_lot::Mutex; use ratatui::{ + Frame, layout::{Alignment, Rect}, style::{Modifier, Style, Stylize}, widgets::{List, Paragraph}, - Frame, }; use crate::{ @@ -14,7 +14,7 @@ use crate::{ ui::{FrameData, GuiState, SelectablePanel, Status}, }; -use super::{generate_block, RIGHT_ARROW}; +use super::{RIGHT_ARROW, generate_block}; /// Draw the logs panel pub fn draw( @@ -81,10 +81,10 @@ mod tests { app_data::{ContainerImage, ContainerName}, config::AppColors, ui::{ - draw_blocks::tests::{ - expected_to_vec, get_result, insert_logs, test_setup, BORDER_CHARS, - }, FrameData, Status, + draw_blocks::tests::{ + BORDER_CHARS, expected_to_vec, get_result, insert_logs, test_setup, + }, }, }; diff --git a/src/ui/draw_blocks/mod.rs b/src/ui/draw_blocks/mod.rs index 26a662c..479306a 100644 --- a/src/ui/draw_blocks/mod.rs +++ b/src/ui/draw_blocks/mod.rs @@ -9,7 +9,7 @@ use ratatui::{ use crate::config::AppColors; -use super::{gui_state::Region, FrameData, GuiState, SelectablePanel, Status}; +use super::{FrameData, GuiState, SelectablePanel, Status, gui_state::Region}; pub mod charts; pub mod commands; @@ -118,12 +118,12 @@ pub mod tests { }; use parking_lot::Mutex; - use ratatui::{backend::TestBackend, layout::Rect, style::Color, Terminal}; + use ratatui::{Terminal, backend::TestBackend, layout::Rect, style::Color}; use crate::{ app_data::{AppData, ContainerId, ContainerImage, ContainerName, ContainerPorts}, tests::{gen_appdata, gen_containers}, - ui::{draw_frame, GuiState, Redraw}, + ui::{GuiState, Redraw, draw_frame}, }; use super::FrameData; @@ -382,7 +382,7 @@ pub mod tests { "│ │•• ••• ││ │•• ••• ││ │", "│ │ ││ │ ││ │", "╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰────────────────────────────╯", - ]; + ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); let colors = setup.app_data.lock().config.app_colors; let keymap = setup.app_data.lock().config.keymap.clone(); @@ -439,7 +439,7 @@ pub mod tests { "│ │ ││ │ ││ │", "╰───────────────────────────────────────────────────────────────╯╰───────────────────────────────────────────────────────────────╯╰────────────────────────────╯", " Esc clear ← by → Name Image Status All term: r_1 ", - ]; + ]; let fd = FrameData::from((&setup.app_data, &setup.gui_state)); setup .terminal diff --git a/src/ui/draw_blocks/ports.rs b/src/ui/draw_blocks/ports.rs index d4f62a8..61add99 100644 --- a/src/ui/draw_blocks/ports.rs +++ b/src/ui/draw_blocks/ports.rs @@ -1,9 +1,9 @@ use ratatui::{ + Frame, layout::{Alignment, Rect}, style::{Color, Modifier, Style, Stylize}, text::{Line, Span}, widgets::{Block, BorderType, Borders, Paragraph}, - Frame, }; use crate::{app_data::State, config::AppColors, ui::FrameData}; @@ -82,10 +82,10 @@ mod tests { app_data::{ContainerPorts, RunningState, State}, config::AppColors, ui::{ - draw_blocks::tests::{ - expected_to_vec, get_result, test_setup, COLOR_ORANGE, COLOR_RX, COLOR_TX, - }, FrameData, + draw_blocks::tests::{ + COLOR_ORANGE, COLOR_RX, COLOR_TX, expected_to_vec, get_result, test_setup, + }, }, }; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 318ded1..c017e51 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -2,18 +2,18 @@ use anyhow::Result; use crossterm::{ event::{self, DisableMouseCapture, Event}, execute, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, + terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, }; use parking_lot::Mutex; use ratatui::{ + Frame, Terminal, backend::CrosstermBackend, layout::{Constraint, Direction, Layout, Position}, - Frame, Terminal, }; use std::{ collections::HashSet, io::{self, Stdout, Write}, - sync::{atomic::Ordering, Arc}, + sync::{Arc, atomic::Ordering}, time::Duration, }; use std::{sync::atomic::AtomicBool, time::Instant}; @@ -75,26 +75,29 @@ impl Ui { is_running: Arc, redraw: Arc, ) { - if let Ok(mut terminal) = Self::setup_terminal() { - let cursor_position = terminal.get_cursor_position().unwrap_or_default(); - let mut ui = Self { - app_data, - cursor_position, - gui_state, - input_tx, - is_running, - now: Instant::now(), - redraw, - terminal, - }; - if let Err(e) = ui.draw_ui().await { - error!("{e}"); + match Self::setup_terminal() { + Ok(mut terminal) => { + let cursor_position = terminal.get_cursor_position().unwrap_or_default(); + let mut ui = Self { + app_data, + cursor_position, + gui_state, + input_tx, + is_running, + now: Instant::now(), + redraw, + terminal, + }; + if let Err(e) = ui.draw_ui().await { + error!("{e}"); + } + if let Err(e) = ui.reset_terminal() { + error!("{e}"); + }; + } + _ => { + error!("Terminal Error"); } - if let Err(e) = ui.reset_terminal() { - error!("{e}"); - }; - } else { - error!("Terminal Error"); } }