feat: export logs feature, closes #1
Save logs to a file. `--logs-dir` cli arg to change from the default location. Refactor of input_handler
This commit is contained in:
@@ -10,7 +10,7 @@ use ratatui::{
|
||||
},
|
||||
Frame,
|
||||
};
|
||||
use std::default::Default;
|
||||
use std::{default::Default, time::Instant};
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
use crate::app_data::{ContainerItem, Header, SortedOrder};
|
||||
@@ -20,7 +20,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{
|
||||
gui_state::{BoxLocation, DeleteButton, Region},
|
||||
gui_state::{self, BoxLocation, DeleteButton, Region},
|
||||
FrameData,
|
||||
};
|
||||
use super::{GuiState, SelectablePanel};
|
||||
@@ -877,7 +877,7 @@ pub fn error(f: &mut Frame, error: AppError, seconds: Option<u8>) {
|
||||
}
|
||||
|
||||
/// Draw info box in one of the 9 BoxLocations
|
||||
pub fn info(f: &mut Frame, text: &str) {
|
||||
pub fn info(f: &mut Frame, text: &str, instant: Instant, gui_state: &Arc<Mutex<GuiState>>) {
|
||||
let block = Block::default()
|
||||
.title("")
|
||||
.title_alignment(Alignment::Center)
|
||||
@@ -898,6 +898,9 @@ pub fn info(f: &mut Frame, text: &str) {
|
||||
let area = popup(lines, max_line_width, f.size(), BoxLocation::BottomRight);
|
||||
f.render_widget(Clear, area);
|
||||
f.render_widget(paragraph, area);
|
||||
if instant.elapsed().as_millis() > 4000 {
|
||||
gui_state.lock().reset_info_box();
|
||||
}
|
||||
}
|
||||
|
||||
/// draw a box in the one of the BoxLocations, based on max line width + number of lines
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ use ratatui::layout::{Constraint, Rect};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
time::Instant,
|
||||
};
|
||||
use tokio::task::JoinHandle;
|
||||
use uuid::Uuid;
|
||||
@@ -158,12 +159,13 @@ const FRAMES_LEN: u8 = 9;
|
||||
/// Various functions (e.g input handler), operate differently depending upon current Status
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
|
||||
pub enum Status {
|
||||
Exec,
|
||||
DeleteConfirm,
|
||||
DockerConnect,
|
||||
Error,
|
||||
Exec,
|
||||
Help,
|
||||
Init,
|
||||
Logs,
|
||||
}
|
||||
|
||||
/// Global gui_state, stored in an Arc<Mutex>
|
||||
@@ -178,7 +180,7 @@ pub struct GuiState {
|
||||
selected_panel: SelectablePanel,
|
||||
status: HashSet<Status>,
|
||||
exec_mode: Option<ExecMode>,
|
||||
pub info_box_text: Option<String>,
|
||||
pub info_box_text: Option<(String, Instant)>,
|
||||
}
|
||||
impl GuiState {
|
||||
/// Clear panels hash map, so on resize can fix the sizes for mouse clicks
|
||||
@@ -366,7 +368,7 @@ impl GuiState {
|
||||
|
||||
/// Set info box content
|
||||
pub fn set_info_box(&mut self, text: &str) {
|
||||
self.info_box_text = Some(text.to_owned());
|
||||
self.info_box_text = Some((text.to_owned(), std::time::Instant::now()));
|
||||
}
|
||||
|
||||
/// Remove info box content
|
||||
|
||||
+3
-3
@@ -247,7 +247,7 @@ pub struct FrameData {
|
||||
height: u16,
|
||||
help_visible: bool,
|
||||
init: bool,
|
||||
info_text: Option<String>,
|
||||
info_text: Option<(String, Instant)>,
|
||||
loading_icon: String,
|
||||
selected_panel: SelectablePanel,
|
||||
sorted_by: Option<(Header, SortedOrder)>,
|
||||
@@ -347,8 +347,8 @@ fn draw_frame(f: &mut Frame, app_data: &Arc<Mutex<AppData>>, gui_state: &Arc<Mut
|
||||
draw_blocks::chart(f, lower_main[1], app_data);
|
||||
}
|
||||
|
||||
if let Some(info) = fd.info_text {
|
||||
draw_blocks::info(f, &info);
|
||||
if let Some((text, instant)) = fd.info_text {
|
||||
draw_blocks::info(f, &text, instant, gui_state);
|
||||
}
|
||||
|
||||
// Check if error, and show popup if so
|
||||
|
||||
Reference in New Issue
Block a user