chore: update to ratatui v0.26.0
This commit is contained in:
+82
-86
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user