chore: update to ratatui v0.26.0

This commit is contained in:
Jack Wills
2024-02-05 22:11:49 +00:00
parent 5b28741631
commit d33dce3eec
6 changed files with 97 additions and 100 deletions
+2 -2
View File
@@ -689,7 +689,7 @@ mod tests {
use super::{ByteStats, ContainerName, CpuStats, LogsTz};
#[test]
// Display CpuStats as a string
/// Display CpuStats as a string
fn test_container_state_cpustats_to_string() {
let test = |f: f64, s: &str| {
assert_eq!(CpuStats::new(f).to_string(), s);
@@ -702,7 +702,7 @@ mod tests {
}
#[test]
// Display bytestats as a string, convert into correct data unit (Kb, MB, GB)
/// Display bytestats as a string, convert into correct data unit (Kb, MB, GB)
fn test_container_state_bytestats_to_string() {
let test = |u: u64, s: &str| {
assert_eq!(ByteStats::new(u).to_string(), s);
+1 -1
View File
@@ -71,7 +71,7 @@ pub struct DockerData {
impl DockerData {
/// Use docker stats to calculate current cpu usage
#[allow(clippy::cast_precision_loss)]
// FIX: this can overflow
// TODO FIX: this can overflow
fn calculate_usage(stats: &Stats) -> f64 {
let mut cpu_percentage = 0.0;
let previous_cpu = stats.precpu_stats.cpu_usage.total_usage;
+2 -2
View File
@@ -103,7 +103,7 @@ mod tests {
}
#[test]
// Use the escape codes to colorize the text
/// Use the escape codes to colorize the text
fn color_match_colorize() {
let result = log_sanitizer::colorize_logs(INPUT);
let expected = vec![Line {
@@ -136,7 +136,7 @@ mod tests {
}
#[test]
// Remove all escape ansi codes from given input
/// Remove all escape ansi codes from given input
fn color_match_remove_ansi() {
let result = log_sanitizer::remove_ansi(INPUT);
let expected = vec![Line {
+82 -86
View File
@@ -44,9 +44,9 @@ const MARGIN: &str = " ";
const RIGHT_ARROW: &str = "";
const CIRCLE: &str = "";
const CONSTRAINT_50_50: [Constraint; 2] = [Constraint::Percentage(50), Constraint::Percentage(50)];
const CONSTRAINT_100: [Constraint; 1] = [Constraint::Percentage(100)];
// TODO FIX THIS
const CONSTRAINT_POPUP: [Constraint; 5] = [
Constraint::Min(2),
Constraint::Max(1),
@@ -113,8 +113,7 @@ pub fn commands(
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
) {
let block = || generate_block(app_data, area, fd, gui_state, SelectablePanel::Commands);
// let block = block();
let block = generate_block(app_data, area, fd, gui_state, SelectablePanel::Commands);
let items = app_data.lock().get_control_items().map_or(vec![], |i| {
i.iter()
.map(|c| {
@@ -127,17 +126,17 @@ pub fn commands(
.collect::<Vec<_>>()
});
let items = List::new(items)
.block(block())
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol(RIGHT_ARROW);
if let Some(i) = app_data.lock().get_control_state() {
let items = List::new(items)
.block(block)
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol(RIGHT_ARROW);
f.render_stateful_widget(items, area, i);
} else {
let block = || generate_block(app_data, area, fd, gui_state, SelectablePanel::Commands);
let paragraph = Paragraph::new("")
.block(block())
.block(block)
.alignment(Alignment::Center);
f.render_widget(paragraph, area);
}
@@ -260,11 +259,11 @@ pub fn logs(
fd: &FrameData,
gui_state: &Arc<Mutex<GuiState>>,
) {
let block = || generate_block(app_data, area, fd, gui_state, SelectablePanel::Logs);
let block = generate_block(app_data, area, fd, gui_state, SelectablePanel::Logs);
if fd.init {
let paragraph = Paragraph::new(format!("parsing logs {}", fd.loading_icon))
.style(Style::default())
.block(block())
.block(block)
.alignment(Alignment::Center);
f.render_widget(paragraph, area);
} else {
@@ -272,12 +271,12 @@ pub fn logs(
if logs.is_empty() {
let paragraph = Paragraph::new("no logs found")
.block(block())
.block(block)
.alignment(Alignment::Center);
f.render_widget(paragraph, area);
} else {
let items = List::new(logs)
.block(block())
.block(block)
.highlight_symbol(RIGHT_ARROW)
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
// This should always return Some, as logs is not empty
@@ -524,9 +523,9 @@ pub fn heading_bar(
let column_width = if column_width > 0 { column_width } else { 1 };
let splits = if data.has_containers {
vec![
Constraint::Min(2),
Constraint::Max(2),
Constraint::Min(column_width.try_into().unwrap_or_default()),
Constraint::Min(info_width.try_into().unwrap_or_default()),
Constraint::Max(info_width.try_into().unwrap_or_default()),
]
} else {
CONSTRAINT_100.to_vec()
@@ -773,16 +772,16 @@ pub fn help_box(f: &mut Frame) {
BoxLocation::MiddleCentre,
);
// This is wrong!
// TODO
let split_popup = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Max(name_info.height.try_into().unwrap_or_default()),
Constraint::Max(description_info.height.try_into().unwrap_or_default()),
Constraint::Max(button_info.height.try_into().unwrap_or_default()),
Constraint::Max(final_info.height.try_into().unwrap_or_default()),
]
)
.constraints([
Constraint::Max(name_info.height.try_into().unwrap_or_default()),
Constraint::Max(description_info.height.try_into().unwrap_or_default()),
Constraint::Max(button_info.height.try_into().unwrap_or_default()),
Constraint::Min(final_info.height.try_into().unwrap_or_default()),
])
.split(area);
let name_paragraph = Paragraph::new(name_info.lines)
@@ -1079,7 +1078,7 @@ mod tests {
// ******************** //
#[test]
// Test that when DockerCommands are available, they are drawn correctly, dependant on container state
/// Test that when DockerCommands are available, they are drawn correctly, dependant on container state
fn test_draw_blocks_commands_none() {
let (w, h) = (12, 6);
let mut setup = test_setup(w, h, false, false);
@@ -1112,7 +1111,7 @@ mod tests {
}
}
#[test]
#[test]
// Test that when DockerCommands are available, they are drawn correctly, dependant on container state
fn test_draw_blocks_commands_some() {
let (w, h) = (12, 6);
@@ -1230,7 +1229,7 @@ mod tests {
}
#[test]
// When control panel is selected, the border is blue, if not then white, selected text is highlighted
/// When control panel is selected, the border is blue, if not then white, selected text is highlighted
fn test_draw_blocks_commands_panel_selected_color() {
let (w, h) = (12, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1320,7 +1319,7 @@ mod tests {
}
#[test]
// No containers, panel unselected, then selected, border color changes correctly
/// No containers, panel unselected, then selected, border color changes correctly
fn test_draw_blocks_containers_none() {
let (w, h) = (25, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1381,7 +1380,7 @@ mod tests {
}
#[test]
// Containers panel drawn, selected line is bold, border is blue
/// Containers panel drawn, selected line is bold, border is blue
fn test_draw_blocks_containers_some() {
let (w, h) = (130, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1740,7 +1739,7 @@ mod tests {
// ********** //
#[test]
// No logs, panel unselected, then selected, border color changes correctly
/// No logs, panel unselected, then selected, border color changes correctly
fn test_draw_blocks_logs_none() {
let (w, h) = (25, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1802,7 +1801,7 @@ mod tests {
}
#[test]
// Parsing logs, spinner visible, and then animates by one frame
/// Parsing logs, spinner visible, and then animates by one frame
fn test_draw_blocks_logs_parsing() {
let (w, h) = (25, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1868,7 +1867,7 @@ mod tests {
}
#[test]
// Logs correct displayed, changing log state also draws correctly
/// Logs correct displayed, changing log state also draws correctly
fn test_draw_blocks_logs_some() {
let (w, h) = (25, 6);
let mut setup = test_setup(w, h, true, true);
@@ -1937,7 +1936,7 @@ mod tests {
}
#[test]
// Full (long) name displayed in logs border
/// Full (long) name displayed in logs border
fn test_draw_blocks_logs_long_name() {
let (w, h) = (80, 6);
let mut setup = test_setup(w, h, true, true);
@@ -2026,7 +2025,7 @@ mod tests {
}
}
#[test]
// When status is Running, but not data, charts drawn without dots etc
/// When status is Running, but not data, charts drawn without dots etc
fn test_draw_blocks_charts_running_none() {
let (w, h) = (80, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2081,7 +2080,7 @@ mod tests {
}
#[test]
// When status is Running, charts correctly drawn
/// When status is Running, charts correctly drawn
fn test_draw_blocks_charts_running_some() {
let (w, h) = (80, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2134,7 +2133,7 @@ mod tests {
}
#[test]
// Whens status paused, some text is now Yellow
/// Whens status paused, some text is now Yellow
fn test_draw_blocks_charts_paused() {
let (w, h) = (80, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2182,7 +2181,7 @@ mod tests {
}
#[test]
// When dead, text is read
/// When dead, text is read
fn test_draw_blocks_charts_dead() {
let (w, h) = (80, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2329,7 +2328,6 @@ mod tests {
let result = &setup.terminal.backend().buffer().content;
for (index, expected_char) in expected.chars().enumerate() {
let result_cell = &result[index];
assert_eq!(result_cell.symbol(), expected_char.to_string());
assert_eq!(result_cell.bg, Color::Magenta);
assert_eq!(
@@ -2377,8 +2375,8 @@ mod tests {
test(" name state status cpu memory/limit id image ▼ ↓ rx ↑ tx ( h ) show help ", 99..=108, (Header::Rx, SortedOrder::Desc));
// tx
test(" name state status cpu memory/limit id image ↓ rx ▲ ↑ tx ( h ) show help ", 109..=122, (Header::Tx, SortedOrder::Asc));
test(" name state status cpu memory/limit id image ↓ rx ▼ ↑ tx ( h ) show help ", 109..=122, (Header::Tx, SortedOrder::Desc));
test(" name state status cpu memory/limit id image ↓ rx ▲ ↑ tx ( h ) show help ", 109..=118, (Header::Tx, SortedOrder::Asc));
test(" name state status cpu memory/limit id image ↓ rx ▼ ↑ tx ( h ) show help ", 109..=118, (Header::Tx, SortedOrder::Desc));
}
#[test]
@@ -2419,7 +2417,7 @@ mod tests {
// Help popup //
// ********** //
#[test]
// This will cause issues once the version has more than the current 5 chars (0.5.0)
/// This will cause issues once the version has more than the current 5 chars (0.5.0)
// Help popup is drawn correctly
fn test_draw_blocks_help() {
let (w, h) = (87, 30);
@@ -2519,7 +2517,7 @@ mod tests {
// ************ //
#[test]
// Delete container popup is drawn correctly
/// Delete container popup is drawn correctly
fn test_draw_blocks_delete() {
let (w, h) = (82, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2611,13 +2609,13 @@ mod tests {
.unwrap();
let result = &setup.terminal.backend().buffer().content;
for (row_index, row) in expected.iter().enumerate() {
for (char_index, expected_char) in row.chars().enumerate() {
let index = row_index * usize::from(w) + char_index;
let result_cell = &result[index];
assert_eq!(expected_char.to_string(), result_cell.symbol());
let (fg, bg) = if row_index >= 6 && char_index >= 32 {
(Color::White, Color::Blue)
} else {
@@ -2635,7 +2633,7 @@ mod tests {
// *********** //
#[test]
// Test that the error popup is centered, red background, white border, white text, and displays the correct text
/// Test that the error popup is centered, red background, white border, white text, and displays the correct text
fn test_draw_blocks_docker_connect_error() {
let (w, h) = (46, 9);
let mut setup = test_setup(w, h, true, true);
@@ -2686,7 +2684,7 @@ mod tests {
}
#[test]
// Test that the clearable error popup is centered, red background, white border, white text, and displays the correct text
/// Test that the clearable error popup is centered, red background, white border, white text, and displays the correct text
fn test_draw_blocks_clearable_error() {
let (w, h) = (39, 10);
let mut setup = test_setup(w, h, true, true);
@@ -2738,7 +2736,7 @@ mod tests {
}
#[test]
// Port section when container has no ports
/// Port section when container has no ports
fn test_draw_blocks_ports_no_ports() {
let (w, h) = (30, 8);
let mut setup = test_setup(w, h, true, true);
@@ -2818,7 +2816,7 @@ mod tests {
}
#[test]
// Port section when container has multiple ports
/// Port section when container has multiple ports
fn test_draw_blocks_ports_multiple_ports() {
let (w, h) = (32, 8);
let mut setup = test_setup(w, h, true, true);
@@ -2891,51 +2889,51 @@ mod tests {
}
#[test]
// Port section title color correct dependant on state
/// Port section title color correct dependant on state
fn test_draw_blocks_ports_container_state() {
let (w, h) = (32, 8);
let mut setup = test_setup(w, h, true, true);
let max_lens = setup.app_data.lock().get_longest_port();
// setup.app_data.lock().containers.items[0].state = State::Paused;
// setup
// .terminal
// .draw(|f| {
// super::ports(f, setup.area, &setup.app_data, max_lens);
// })
// .unwrap();
setup.app_data.lock().containers.items[0].state = State::Paused;
setup
.terminal
.draw(|f| {
super::ports(f, setup.area, &setup.app_data, max_lens);
})
.unwrap();
// let expected = [
// "╭─────────── ports ────────────╮",
// "│ ip private public │",
// "│ 8001 │",
// "│ │",
// "│ │",
// "│ │",
// "│ │",
// "╰──────────────────────────────╯",
// ];
let expected = [
"╭─────────── ports ────────────╮",
"│ ip private public │",
"│ 8001 │",
"│ │",
"│ │",
"│ │",
"│ │",
"╰──────────────────────────────╯",
];
// let result = &setup.terminal.backend().buffer().content;
// for (row_index, row) in expected.iter().enumerate() {
// for (char_index, expected_char) in row.chars().enumerate() {
// let index = row_index * usize::from(w) + char_index;
// let result_cell = &result[index];
let result = &setup.terminal.backend().buffer().content;
for (row_index, row) in expected.iter().enumerate() {
for (char_index, expected_char) in row.chars().enumerate() {
let index = row_index * usize::from(w) + char_index;
let result_cell = &result[index];
// assert_eq!(expected_char.to_string(), result_cell.symbol());
assert_eq!(expected_char.to_string(), result_cell.symbol());
// if row_index == 0
// && result_cell
// .symbol()
// .chars()
// .next()
// .unwrap()
// .is_ascii_alphanumeric()
// {
// assert_eq!(result_cell.fg, Color::Yellow);
// }
// }
// }
if row_index == 0
&& result_cell
.symbol()
.chars()
.next()
.unwrap()
.is_ascii_alphanumeric()
{
assert_eq!(result_cell.fg, Color::Yellow);
}
}
}
setup.app_data.lock().containers.items[0].state = State::Dead;
setup
@@ -2945,9 +2943,7 @@ mod tests {
})
.unwrap();
println!("{:?}", setup.terminal.backend().buffer());
// This is wrong
// This is wrong - why?
let expected = [
"╭─────────── ports ────────────╮",
"│ ip private public │",
@@ -2985,7 +2981,7 @@ mod tests {
// The whole layout //
// **************** //
#[test]
// Check that the whole layout is drawn correctly
/// Check that the whole layout is drawn correctly
fn test_draw_blocks_whole_layout() {
let (w, h) = (160, 30);
let mut setup = test_setup(w, h, true, true);
+6 -6
View File
@@ -109,19 +109,19 @@ impl BoxLocation {
) -> [Constraint; 3] {
match self {
Self::TopLeft | Self::MiddleLeft | Self::BottomLeft => [
Constraint::Max(text_width),
Constraint::Min(text_width),
Constraint::Max(blank_horizontal),
Constraint::Max(blank_horizontal),
],
Self::TopCentre | Self::MiddleCentre | Self::BottomCentre => [
Constraint::Max(blank_horizontal),
Constraint::Max(text_width),
Constraint::Min(text_width),
Constraint::Max(blank_horizontal),
],
Self::TopRight | Self::MiddleRight | Self::BottomRight => [
Constraint::Max(blank_horizontal),
Constraint::Max(blank_horizontal),
Constraint::Max(text_width),
Constraint::Min(text_width),
],
}
}
@@ -133,19 +133,19 @@ impl BoxLocation {
) -> [Constraint; 3] {
match self {
Self::TopLeft | Self::TopCentre | Self::TopRight => [
Constraint::Max(number_lines),
Constraint::Min(number_lines),
Constraint::Max(blank_vertical),
Constraint::Max(blank_vertical),
],
Self::MiddleLeft | Self::MiddleCentre | Self::MiddleRight => [
Constraint::Max(blank_vertical),
Constraint::Max(number_lines),
Constraint::Min(number_lines),
Constraint::Max(blank_vertical),
],
Self::BottomLeft | Self::BottomCentre | Self::BottomRight => [
Constraint::Max(blank_vertical),
Constraint::Max(blank_vertical),
Constraint::Max(number_lines),
Constraint::Min(number_lines),
],
}
}
+4 -3
View File
@@ -265,13 +265,14 @@ fn draw_frame(f: &mut Frame, app_data: &Arc<Mutex<AppData>>, gui_state: &Arc<Mut
let whole_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(1), Constraint::Min(100)].as_ref())
.constraints([Constraint::Max(1), Constraint::Min(1)].as_ref())
.split(f.size());
// Split into 3, containers+controls, logs, then graphs
// This one is the issue!
let upper_main = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Max(fd.height), Constraint::Percentage(50)].as_ref())
.constraints([Constraint::Max(fd.height), Constraint::Min(1)].as_ref())
.split(whole_layout[1]);
let top_split = if fd.has_containers {
@@ -286,7 +287,7 @@ fn draw_frame(f: &mut Frame, app_data: &Arc<Mutex<AppData>>, gui_state: &Arc<Mut
.split(upper_main[0]);
let lower_split = if fd.has_containers {
vec![Constraint::Percentage(70), Constraint::Percentage(20)]
vec![Constraint::Percentage(70), Constraint::Percentage(30)]
} else {
vec![Constraint::Percentage(100)]
};