refactor: generate_block()
insert area in gui_state in generate_block, don't pass in currently selected panel, instead get from gui_state itself
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
A simple tui to view and control docker containers
|
A simple tui to view & control docker containers
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -55,7 +55,6 @@ available command line arguments
|
|||||||
|
|
||||||
requires docker & <a href='https://github.com/cross-rs/cross' target='_blank' rel='noopener noreferrer'>cross-rs</a>
|
requires docker & <a href='https://github.com/cross-rs/cross' target='_blank' rel='noopener noreferrer'>cross-rs</a>
|
||||||
|
|
||||||
|
|
||||||
#### 64bit pi (pi 4, pi zero w 2)
|
#### 64bit pi (pi 4, pi zero w 2)
|
||||||
|
|
||||||
```cross build --target aarch64-unknown-linux-gnu --release```
|
```cross build --target aarch64-unknown-linux-gnu --release```
|
||||||
|
|||||||
+20
-25
@@ -42,15 +42,16 @@ const MARGIN: &str = " ";
|
|||||||
/// Generate block, add a border if is the selected panel,
|
/// Generate block, add a border if is the selected panel,
|
||||||
/// add custom title based on state of each panel
|
/// add custom title based on state of each panel
|
||||||
fn generate_block<'a>(
|
fn generate_block<'a>(
|
||||||
selectable_panel: Option<SelectablePanel>,
|
|
||||||
app_data: &Arc<Mutex<AppData>>,
|
app_data: &Arc<Mutex<AppData>>,
|
||||||
selected_panel: &SelectablePanel,
|
area: Rect,
|
||||||
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
|
panel: SelectablePanel,
|
||||||
) -> Block<'a> {
|
) -> Block<'a> {
|
||||||
|
gui_state.lock().insert_into_area_map(panel, area);
|
||||||
let mut block = Block::default()
|
let mut block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded);
|
.border_type(BorderType::Rounded);
|
||||||
|
let current_selected_panel = gui_state.lock().selected_panel;
|
||||||
if let Some(panel) = selectable_panel {
|
|
||||||
let title = match panel {
|
let title = match panel {
|
||||||
SelectablePanel::Containers => {
|
SelectablePanel::Containers => {
|
||||||
format!(
|
format!(
|
||||||
@@ -65,10 +66,9 @@ fn generate_block<'a>(
|
|||||||
_ => String::from(""),
|
_ => String::from(""),
|
||||||
};
|
};
|
||||||
block = block.title(title);
|
block = block.title(title);
|
||||||
if selected_panel == &panel {
|
if current_selected_panel == panel {
|
||||||
block = block.border_style(Style::default().fg(Color::LightCyan));
|
block = block.border_style(Style::default().fg(Color::LightCyan));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,13 +79,8 @@ pub fn draw_commands<B: Backend>(
|
|||||||
f: &mut Frame<'_, B>,
|
f: &mut Frame<'_, B>,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
index: Option<usize>,
|
index: Option<usize>,
|
||||||
selected_panel: &SelectablePanel,
|
|
||||||
) {
|
) {
|
||||||
let panel = SelectablePanel::Commands;
|
let block = generate_block(app_data, area, gui_state, SelectablePanel::Commands);
|
||||||
let block = generate_block(Some(panel), app_data, selected_panel);
|
|
||||||
|
|
||||||
gui_state.lock().insert_into_area_map(panel, area);
|
|
||||||
|
|
||||||
if let Some(i) = index {
|
if let Some(i) = index {
|
||||||
let items = app_data.lock().containers.items[i]
|
let items = app_data.lock().containers.items[i]
|
||||||
.docker_controls
|
.docker_controls
|
||||||
@@ -125,13 +120,14 @@ pub fn draw_containers<B: Backend>(
|
|||||||
area: Rect,
|
area: Rect,
|
||||||
f: &mut Frame<'_, B>,
|
f: &mut Frame<'_, B>,
|
||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
selected_panel: &SelectablePanel,
|
|
||||||
widths: &Columns,
|
widths: &Columns,
|
||||||
) {
|
) {
|
||||||
let panel = SelectablePanel::Containers;
|
let block = generate_block(
|
||||||
let block = generate_block(Some(panel), app_data, selected_panel);
|
app_data,
|
||||||
|
area,
|
||||||
gui_state.lock().insert_into_area_map(panel, area);
|
gui_state,
|
||||||
|
SelectablePanel::Containers,
|
||||||
|
);
|
||||||
|
|
||||||
let items = app_data
|
let items = app_data
|
||||||
.lock()
|
.lock()
|
||||||
@@ -216,7 +212,7 @@ pub fn draw_containers<B: Backend>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the selectable panels
|
/// Draw the logs panels
|
||||||
pub fn draw_logs<B: Backend>(
|
pub fn draw_logs<B: Backend>(
|
||||||
app_data: &Arc<Mutex<AppData>>,
|
app_data: &Arc<Mutex<AppData>>,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
@@ -224,17 +220,16 @@ pub fn draw_logs<B: Backend>(
|
|||||||
gui_state: &Arc<Mutex<GuiState>>,
|
gui_state: &Arc<Mutex<GuiState>>,
|
||||||
index: Option<usize>,
|
index: Option<usize>,
|
||||||
loading_icon: String,
|
loading_icon: String,
|
||||||
selected_panel: &SelectablePanel,
|
|
||||||
) {
|
) {
|
||||||
let panel = SelectablePanel::Logs;
|
let block = generate_block(
|
||||||
|
app_data,
|
||||||
gui_state.lock().insert_into_area_map(panel, area);
|
area,
|
||||||
|
gui_state,
|
||||||
let block = generate_block(Some(panel), app_data, selected_panel);
|
SelectablePanel::Logs,
|
||||||
|
);
|
||||||
|
|
||||||
let init = app_data.lock().init;
|
let init = app_data.lock().init;
|
||||||
if !init {
|
if !init {
|
||||||
// let icon = gui_state.lock().get_loading();
|
|
||||||
let parsing_logs = format!("parsing logs {}", loading_icon);
|
let parsing_logs = format!("parsing logs {}", loading_icon);
|
||||||
let paragraph = Paragraph::new(parsing_logs)
|
let paragraph = Paragraph::new(parsing_logs)
|
||||||
.style(Style::default())
|
.style(Style::default())
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ fn ui<B: Backend>(
|
|||||||
let has_containers = !app_data.lock().containers.items.is_empty();
|
let has_containers = !app_data.lock().containers.items.is_empty();
|
||||||
let has_error = app_data.lock().get_error();
|
let has_error = app_data.lock().get_error();
|
||||||
let log_index = app_data.lock().get_selected_log_index();
|
let log_index = app_data.lock().get_selected_log_index();
|
||||||
let selected_panel = gui_state.lock().selected_panel;
|
|
||||||
let show_help = gui_state.lock().show_help;
|
let show_help = gui_state.lock().show_help;
|
||||||
let info_text = gui_state.lock().info_box_text.clone();
|
let info_text = gui_state.lock().info_box_text.clone();
|
||||||
let loading_icon = gui_state.lock().get_loading();
|
let loading_icon = gui_state.lock().get_loading();
|
||||||
@@ -197,7 +196,6 @@ fn ui<B: Backend>(
|
|||||||
top_panel[0],
|
top_panel[0],
|
||||||
f,
|
f,
|
||||||
gui_state,
|
gui_state,
|
||||||
&selected_panel,
|
|
||||||
&column_widths,
|
&column_widths,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -208,7 +206,6 @@ fn ui<B: Backend>(
|
|||||||
f,
|
f,
|
||||||
gui_state,
|
gui_state,
|
||||||
log_index,
|
log_index,
|
||||||
&selected_panel,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +216,6 @@ fn ui<B: Backend>(
|
|||||||
gui_state,
|
gui_state,
|
||||||
log_index,
|
log_index,
|
||||||
loading_icon.to_owned(),
|
loading_icon.to_owned(),
|
||||||
&selected_panel,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
draw_heading_bar(
|
draw_heading_bar(
|
||||||
|
|||||||
Reference in New Issue
Block a user