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,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},
+19 -15
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()
.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,
},
},
};
+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},
},
};
+18 -18
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;
@@ -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));
+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},
+7 -7
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,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) {
+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| {
+79 -67
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,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);
+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,
},
},
};
+5 -5
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;
@@ -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
+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,
},
},
};
+25 -22
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,26 +75,29 @@ impl Ui {
is_running: Arc<AtomicBool>,
redraw: Arc<Redraw>,
) {
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");
}
}