refactor: FrameData
This commit is contained in:
+14
-8
@@ -231,7 +231,7 @@ pub fn containers(
|
||||
if items.is_empty() {
|
||||
let text = if fd.filter_term.is_some() {
|
||||
"no containers match filter"
|
||||
} else if gui_state.lock().is_loading() {
|
||||
} else if fd.is_loading {
|
||||
&format!("loading {}", fd.loading_icon)
|
||||
} else {
|
||||
"no containers running"
|
||||
@@ -250,7 +250,8 @@ pub fn containers(
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the logs panel
|
||||
// /// Draw the logs panel
|
||||
// PREV WORKING
|
||||
pub fn logs(
|
||||
app_data: &Arc<Mutex<AppData>>,
|
||||
area: Rect,
|
||||
@@ -267,14 +268,13 @@ pub fn logs(
|
||||
f.render_widget(paragraph, area);
|
||||
} else {
|
||||
let logs = app_data.lock().get_logs();
|
||||
|
||||
if logs.is_empty() {
|
||||
let paragraph = Paragraph::new("no logs found")
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area);
|
||||
} else {
|
||||
let items = List::new(logs)
|
||||
let items = List::new(app_data.lock().get_logs())
|
||||
.block(block)
|
||||
.highlight_symbol(RIGHT_ARROW)
|
||||
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
|
||||
@@ -1004,13 +1004,13 @@ pub fn error(f: &mut Frame, error: AppError, seconds: Option<u8>) {
|
||||
|
||||
/// Draw info box in one of the 9 BoxLocations
|
||||
// TODO is this broken - I don't think so
|
||||
pub fn info(f: &mut Frame, text: &str, instant: Instant, gui_state: &Arc<Mutex<GuiState>>) {
|
||||
pub fn info(f: &mut Frame, text: String, instant: Instant, gui_state: &Arc<Mutex<GuiState>>) {
|
||||
let block = Block::default()
|
||||
.title("")
|
||||
.title_alignment(Alignment::Center)
|
||||
.borders(Borders::NONE);
|
||||
|
||||
let mut max_line_width = max_line_width(text);
|
||||
let mut max_line_width = max_line_width(&text);
|
||||
let mut lines = text.lines().count();
|
||||
|
||||
// Add some horizontal & vertical margins
|
||||
@@ -2804,7 +2804,12 @@ mod tests {
|
||||
setup
|
||||
.terminal
|
||||
.draw(|f| {
|
||||
super::info(f, "test", std::time::Instant::now(), &setup.gui_state);
|
||||
super::info(
|
||||
f,
|
||||
"test".to_owned(),
|
||||
std::time::Instant::now(),
|
||||
&setup.gui_state,
|
||||
);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -2883,11 +2888,12 @@ mod tests {
|
||||
// Test when char added to search term
|
||||
setup.app_data.lock().filter_term_push('c');
|
||||
setup.app_data.lock().filter_term_push('d');
|
||||
let fd = FrameData::from((setup.app_data.lock(), setup.gui_state.lock()));
|
||||
|
||||
setup
|
||||
.terminal
|
||||
.draw(|f| {
|
||||
super::filter_bar(setup.area, f, &setup.fd);
|
||||
super::filter_bar(setup.area, f, &fd);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
||||
+11
-8
@@ -221,21 +221,23 @@ impl Ui {
|
||||
|
||||
/// Frequent data required by multiple framde drawing functions, can reduce mutex reads by placing it all in here
|
||||
/// TODO add more items to this, and split up into parts
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
pub struct FrameData {
|
||||
columns: Columns,
|
||||
container_title: String,
|
||||
log_title: String,
|
||||
delete_confirm: Option<ContainerId>,
|
||||
has_containers: bool,
|
||||
filter_by: FilterBy,
|
||||
filter_term: Option<String>,
|
||||
has_containers: bool,
|
||||
has_error: Option<AppError>,
|
||||
height: u16,
|
||||
help_visible: bool,
|
||||
init: bool,
|
||||
info_text: Option<(String, Instant)>,
|
||||
init: bool,
|
||||
is_loading: bool,
|
||||
loading_icon: String,
|
||||
log_title: String,
|
||||
selected_panel: SelectablePanel,
|
||||
sorted_by: Option<(Header, SortedOrder)>,
|
||||
}
|
||||
@@ -252,17 +254,18 @@ impl From<(MutexGuard<'_, AppData>, MutexGuard<'_, GuiState>)> for FrameData {
|
||||
|
||||
let (filter_by, filter_term) = data.0.get_filter();
|
||||
Self {
|
||||
filter_by,
|
||||
filter_term: filter_term.cloned(),
|
||||
height,
|
||||
columns: data.0.get_width(),
|
||||
container_title: data.0.get_container_title(),
|
||||
delete_confirm: data.1.get_delete_container(),
|
||||
filter_by,
|
||||
filter_term: filter_term.cloned(),
|
||||
has_containers: data.0.get_container_len() > 0,
|
||||
has_error: data.0.get_error(),
|
||||
height,
|
||||
help_visible: data.1.status_contains(&[Status::Help]),
|
||||
info_text: data.1.info_box_text.clone(),
|
||||
init: data.1.status_contains(&[Status::Init]),
|
||||
is_loading: data.1.is_loading(),
|
||||
loading_icon: data.1.get_loading().to_string(),
|
||||
log_title: data.0.get_log_title(),
|
||||
selected_panel: data.1.get_selected_panel(),
|
||||
@@ -358,7 +361,7 @@ fn draw_frame(f: &mut Frame, app_data: &Arc<Mutex<AppData>>, gui_state: &Arc<Mut
|
||||
}
|
||||
|
||||
if let Some((text, instant)) = fd.info_text {
|
||||
draw_blocks::info(f, &text, instant, gui_state);
|
||||
draw_blocks::info(f, text, instant, gui_state);
|
||||
}
|
||||
|
||||
// Check if error, and show popup if so
|
||||
|
||||
Reference in New Issue
Block a user