Skip to content

Commit

Permalink
Fix logfile not updated (after initial logfile load)
Browse files Browse the repository at this point in the history
  • Loading branch information
happybeing committed Sep 25, 2020
1 parent 02b68d3 commit 0e3bf6a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/bin/logtail-crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
Some(Ok(line)) => {
let source_str = line.source().to_str().unwrap();
let source = String::from(source_str);

match app.monitors.get_mut(&source) {
None => (),
Some(monitor) => monitor.append_to_content(line.line())
}
match app.get_monitor_for_file_path(&source) {
Some(monitor) => monitor.append_to_content(line.line()),
None => panic!("No monitor for file: {}",&source),
}
},
Some(Err(e)) => panic!("{}", e),
None => (),
Expand Down
8 changes: 3 additions & 5 deletions src/bin/logtail-termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ async fn terminal_main() -> std::io::Result<()> {
let source_str = line.source().to_str().unwrap();
let source = String::from(source_str);

match app.monitors.get_mut(&source) {
Some(monitor) => {
monitor.append_to_content(line.line())
},
None => (),
match app.get_monitor_for_file_path(&source) {
Some(monitor) => monitor.append_to_content(line.line()),
None => panic!("No monitor for file: {}",&source),
}
},
Some(Err(e)) => {
Expand Down
22 changes: 22 additions & 0 deletions src/custom/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ impl App {
Ok(app)
}

pub fn get_monitor_for_file_path(&mut self, logfile: &String) -> Option<(&mut LogMonitor)> {
let mut index = 0;
let mut monitor_for_path = None;
for (monitor_file, mut monitor) in self.monitors.iter_mut() {
if monitor_file.eq(logfile) {
monitor_for_path = Some(monitor);
break;
}
use std::env::current_dir;
use std::path::Path;
if let Ok(current_dir) = current_dir() {
let logfile_path = Path::new(logfile.as_str());
if current_dir.join(monitor_file).eq(&logfile_path) {
monitor_for_path = Some(monitor);
break;
}
}
index += 1;
}
return monitor_for_path;
}

pub fn get_monitor_with_focus(&mut self) -> Option<(&mut LogMonitor)> {
match (&mut self.monitors).get_mut(&self.logfile_with_focus) {
Some(mut monitor) => Some(monitor),
Expand Down

0 comments on commit 0e3bf6a

Please sign in to comment.