feat: use gui_status for various gui states
This commit is contained in:
+35
-47
@@ -216,43 +216,36 @@ pub fn logs<B: Backend>(
|
||||
loading_icon: &str,
|
||||
) {
|
||||
let block = generate_block(app_data, area, gui_state, SelectablePanel::Logs);
|
||||
let status = gui_state.lock().get_status();
|
||||
match status {
|
||||
Status::Init => {
|
||||
let paragraph = Paragraph::new(format!("parsing logs {}", loading_icon))
|
||||
.style(Style::default())
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
let contains_init = gui_state.lock().status_contains(&[Status::Init]);
|
||||
if contains_init {
|
||||
let paragraph = Paragraph::new(format!("parsing logs {}", loading_icon))
|
||||
.style(Style::default())
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area);
|
||||
} else if let Some(index) = index {
|
||||
let items = app_data.lock().containers.items[index]
|
||||
.logs
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|i| i.1.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
_ => {
|
||||
if let Some(index) = index {
|
||||
let items = app_data.lock().containers.items[index]
|
||||
.logs
|
||||
.items
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|i| i.1.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let items = List::new(items)
|
||||
.block(block)
|
||||
.highlight_symbol(ARROW)
|
||||
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
|
||||
f.render_stateful_widget(
|
||||
items,
|
||||
area,
|
||||
&mut app_data.lock().containers.items[index].logs.state,
|
||||
);
|
||||
} else {
|
||||
let paragraph = Paragraph::new("no logs found")
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area);
|
||||
// }
|
||||
}
|
||||
}
|
||||
let items = List::new(items)
|
||||
.block(block)
|
||||
.highlight_symbol(ARROW)
|
||||
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
|
||||
f.render_stateful_widget(
|
||||
items,
|
||||
area,
|
||||
&mut app_data.lock().containers.items[index].logs.state,
|
||||
);
|
||||
} else {
|
||||
let paragraph = Paragraph::new("no logs found")
|
||||
.block(block)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,7 +349,7 @@ pub fn heading_bar<B: Backend>(
|
||||
gui_state: &Arc<Mutex<GuiState>>,
|
||||
) {
|
||||
let block = |fg: Color| Block::default().style(Style::default().bg(Color::Magenta).fg(fg));
|
||||
let info_visible = gui_state.lock().get_status() == Status::Help;
|
||||
let help_visible = gui_state.lock().status_contains(&[Status::Help]);
|
||||
|
||||
f.render_widget(block(Color::Black), area);
|
||||
|
||||
@@ -436,13 +429,8 @@ pub fn heading_bar<B: Backend>(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let suffix = if info_visible { "exit" } else { "show" };
|
||||
let info_text = format!(
|
||||
"( h ) {} help {} {:?}",
|
||||
suffix,
|
||||
MARGIN,
|
||||
gui_state.lock().get_status()
|
||||
);
|
||||
let suffix = if help_visible { "exit" } else { "show" };
|
||||
let info_text = format!("( h ) {} help {}", suffix, MARGIN,);
|
||||
let info_width = info_text.chars().count();
|
||||
|
||||
let column_width = usize::from(area.width) - info_width;
|
||||
@@ -484,10 +472,10 @@ pub fn heading_bar<B: Backend>(
|
||||
}
|
||||
|
||||
// show/hide help
|
||||
let color = if info_visible {
|
||||
Color::White
|
||||
} else {
|
||||
let color = if help_visible {
|
||||
Color::Black
|
||||
} else {
|
||||
Color::White
|
||||
};
|
||||
let help_paragraph = Paragraph::new(info_text)
|
||||
.block(block(color))
|
||||
|
||||
Reference in New Issue
Block a user