feat: update Rust edition to 2024

This commit is contained in:
Jack Wills
2025-02-21 22:45:06 +00:00
parent e5f355a192
commit 7e4a960b88
21 changed files with 387 additions and 244 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "oxker"
version = "0.9.0"
edition = "2021"
edition = "2024"
authors = ["Jack Wills <email@mrjackwills.com>"]
description = "A simple tui to view & control docker containers"
repository = "https://github.com/mrjackwills/oxker"
+14 -15
View File
@@ -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<T> StatefulList<T> {
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 }),
));
}
}
+2 -2
View File
@@ -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::*;
+3 -3
View File
@@ -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;
+11 -8
View File
@@ -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,6 +263,10 @@ impl ExecMode {
)
.await
{
Ok(StartExecResults::Attached {
mut output,
mut input,
}) => {
if let Some(tty) = AsyncTTY::get(&cancel_token) {
tokio::spawn(async move {
enable_raw_mode().ok();
@@ -298,10 +299,12 @@ impl ExecMode {
self.internal_cleanup()?;
}
} else {
}
_ => {
return Err(AppError::Terminal);
}
}
}
Ok(())
}
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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;
+1 -1
View File
@@ -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},
+13 -9
View File
@@ -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()
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()
.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)];
.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,
},
},
};
+2 -2
View File
@@ -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},
},
};
+17 -17
View File
@@ -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;
@@ -677,7 +677,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;
@@ -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));
+2 -2
View File
@@ -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},
},
};
+2 -2
View File
@@ -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},
+6 -6
View File
@@ -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,7 +193,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) {
@@ -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) {
+150 -28
View File
@@ -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| {
+24 -12
View File
@@ -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,7 +445,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -479,7 +481,7 @@ mod tests {
" │ │ ",
" │ │ ",
" ╰───────────────────────────────────────────────────────────────────────────────────╯ ",
" "
" ",
];
for (row_index, result_row) in get_result(&setup, w) {
@@ -551,7 +553,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -585,7 +589,7 @@ mod tests {
" │ │ ",
" │ │ ",
" ╰───────────────────────────────────────────────────────────────────────────────────╯ ",
" "
" ",
];
for (row_index, result_row) in get_result(&setup, w) {
@@ -675,7 +679,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ─────────────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ─────────────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -723,7 +729,7 @@ mod tests {
" │ │ ",
" │ │ ",
" ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ",
" "
" ",
];
for (row_index, result_row) in get_result(&setup, w) {
@@ -777,7 +783,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -881,7 +889,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ───────────────────────────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -958,7 +968,9 @@ mod tests {
})
.unwrap();
let version_row = format!("{VERSION} ────────────────────────────────────────────────────────────────────────────╮ ");
let version_row = format!(
" ╭ {VERSION} ────────────────────────────────────────────────────────────────────────────╮ "
);
let expected = [
" ",
version_row.as_str(),
@@ -994,7 +1006,7 @@ mod tests {
" │ │ ",
" │ │ ",
" ╰───────────────────────────────────────────────────────────────────────────────────╯ ",
" "
" ",
];
for (row_index, result_row) in get_result(&setup, w) {
+2 -2
View File
@@ -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};
+5 -5
View File
@@ -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,
},
},
};
+3 -3
View File
@@ -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;
+4 -4
View File
@@ -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,
},
},
};
+8 -5
View File
@@ -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,7 +75,8 @@ impl Ui {
is_running: Arc<AtomicBool>,
redraw: Arc<Redraw>,
) {
if let Ok(mut terminal) = Self::setup_terminal() {
match Self::setup_terminal() {
Ok(mut terminal) => {
let cursor_position = terminal.get_cursor_position().unwrap_or_default();
let mut ui = Self {
app_data,
@@ -93,10 +94,12 @@ impl Ui {
if let Err(e) = ui.reset_terminal() {
error!("{e}");
};
} else {
}
_ => {
error!("Terminal Error");
}
}
}
/// Setup the terminal for full-screen drawing mode, with mouse capture
fn setup_terminal() -> Result<Terminal<CrosstermBackend<Stdout>>> {