diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_browser.rs | 56 | ||||
-rw-r--r-- | src/proclist.rs | 46 | ||||
-rw-r--r-- | src/widget.rs | 21 |
3 files changed, 89 insertions, 34 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs index 5f4e5fb..bb4a1a7 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -578,6 +578,33 @@ impl FileBrowser { Ok(()) } + + pub fn get_footer(&self) -> HResult<String> { + let xsize = self.get_coordinates()?.xsize(); + let ypos = self.get_coordinates()?.position().y(); + let file = self.selected_file()?; + + let permissions = file.pretty_print_permissions().unwrap_or("NOPERMS".into()); + let user = file.pretty_user().unwrap_or("NOUSER".into()); + let group = file.pretty_group().unwrap_or("NOGROUP".into()); + let mtime = file.pretty_mtime().unwrap_or("NOMTIME".into()); + + let main_widget = self.main_widget()?.widget()?; + let selection = main_widget.lock()?.as_ref().unwrap().get_selection(); + let file_count = main_widget.lock()?.as_ref().unwrap().content.len(); + let file_count = format!("{}", file_count); + let digits = file_count.len(); + let file_count = format!("{:digits$}/{:digits$}", + selection, + file_count, + digits = digits); + let count_xpos = xsize - file_count.len() as u16; + let count_ypos = ypos + self.get_coordinates()?.ysize(); + + let status = format!("{} {}:{} {} {} {}", permissions, user, group, mtime, + crate::term::goto_xy(count_xpos, count_ypos), file_count); + Ok(status) + } } impl Widget for FileBrowser { @@ -603,30 +630,11 @@ impl Widget for FileBrowser { Ok(sized_path) } fn render_footer(&self) -> HResult<String> { - let xsize = self.get_coordinates()?.xsize(); - let ypos = self.get_coordinates()?.position().y(); - let file = self.selected_file()?; - - let permissions = file.pretty_print_permissions().unwrap_or("NOPERMS".into()); - let user = file.pretty_user().unwrap_or("NOUSER".into()); - let group = file.pretty_group().unwrap_or("NOGROUP".into()); - let mtime = file.pretty_mtime().unwrap_or("NOMTIME".into()); - - let main_widget = self.main_widget()?.widget()?; - let selection = main_widget.lock()?.as_ref().unwrap().get_selection(); - let file_count = main_widget.lock()?.as_ref().unwrap().content.len(); - let file_count = format!("{}", file_count); - let digits = file_count.len(); - let file_count = format!("{:digits$}/{:digits$}", - selection, - file_count, - digits = digits); - let count_xpos = xsize - file_count.len() as u16; - let count_ypos = ypos + self.get_coordinates()?.ysize(); - - Ok(format!("{} {}:{} {} {} {}", permissions, user, group, mtime, - crate::term::goto_xy(count_xpos, count_ypos), file_count)) - } + match self.get_core()?.status_bar_content.lock()?.as_mut().take() { + Some(status) => Ok(status.clone()), + _ => { self.get_footer() }, + } + } fn refresh(&mut self) -> HResult<()> { //self.proc_view.lock()?.set_coordinates(self.get_coordinates()?); self.handle_dir_events().ok(); diff --git a/src/proclist.rs b/src/proclist.rs index 5c04f5f..acacf2e 100644 --- a/src/proclist.rs +++ b/src/proclist.rs @@ -1,7 +1,7 @@ use std::sync::{Arc, Mutex}; use std::sync::mpsc::Sender; use std::process::Child; -use std::os::unix::process::CommandExt; +use std::os::unix::process::{CommandExt, ExitStatusExt}; use std::io::{BufRead, BufReader}; use termion::event::Key; @@ -39,11 +39,13 @@ impl Process { let status = self.status.clone(); let success = self.success.clone(); let sender = self.sender.clone(); + let cmd = self.cmd.clone(); + let pid = self.handle.lock()?.id(); std::thread::spawn(move || -> HResult<()> { let stdout = handle.lock()?.stdout.take()?; let mut stdout = BufReader::new(stdout); - let mut processor = move || -> HResult<()> { + let mut processor = move |cmd, sender: &Sender<Events>| -> HResult<()> { loop { let buffer = stdout.fill_buf()?; let len = buffer.len(); @@ -52,15 +54,47 @@ impl Process { if len == 0 { return Ok(()) } output.lock()?.push_str(&buffer); - sender.send(Events::WidgetReady)?; + + let status = format!("{}: read {} chars!", cmd, len); + sender.send(Events::Status(status))?; stdout.consume(len); } }; - processor().log(); + processor(&cmd, &sender).log(); + if let Ok(proc_status) = handle.lock()?.wait() { - *success.lock()? = Some(proc_status.success()); - *status.lock()? = proc_status.code(); + let proc_success = proc_status.success(); + let proc_status = match proc_status.code() { + Some(status) => status, + None => proc_status.signal().unwrap_or(-1) + }; + + *success.lock()? = Some(proc_success); + *status.lock()? = Some(proc_status); + + let color_success = + if proc_success { + format!("{}successfully", term::color_green()) + } else { + format!("{}unsuccessfully", term::color_red()) + }; + + let color_status = + if proc_success { + format!("{}{}", term::color_green(), proc_status) + } else { + format!("{}{}", term::color_red(), proc_status) + }; + + let status = format!("Process: {}:{} exited {}{}{} with status: {}", + cmd, + pid, + color_success, + term::reset(), + term::status_bg(), + color_status); + sender.send(Events::Status(status))?; } Ok(()) }); diff --git a/src/widget.rs b/src/widget.rs index 6dfac9b..87d0b2f 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -19,6 +19,7 @@ pub enum Events { InputEvent(Event), WidgetReady, ExclusiveEvent(Option<Sender<Events>>), + Status(String) } impl PartialEq for WidgetCore { @@ -107,6 +108,7 @@ pub trait Widget { fn on_event(&mut self, event: Event) -> HResult<()> { + self.clear_status().log(); match event { Event::Key(Key::Char('q')) => HError::quit(), Event::Key(key) => self.on_key(key), @@ -290,6 +292,9 @@ pub trait Widget { } self.draw().ok(); }, + Events::Status(status) => { + self.show_status(&status).log(); + } _ => { self.refresh().ok(); self.draw().ok(); @@ -301,9 +306,10 @@ pub trait Widget { fn draw_status(&self) -> HResult<()> { let xsize = term::xsize() as u16; - let status = &self.get_core()?.status_bar_content; - - let status = status.lock()?; + let status = match self.get_core()?.status_bar_content.lock()?.as_ref() { + Some(status) => status.to_string(), + None => "".to_string(), + }; self.write_to_screen( &format!( @@ -312,7 +318,7 @@ pub trait Widget { term::status_bg(), " ", term::move_bottom(), - status.as_ref()?, + status, xsize = xsize as usize )).log(); @@ -328,6 +334,13 @@ pub trait Widget { Ok(()) } + fn clear_status(&self) -> HResult<()> { + if self.get_core()?.status_bar_content.lock()?.take().is_some() { + self.draw_status().log(); + } + Ok(()) + } + fn minibuffer(&self, query: &str) -> HResult<String> { let answer = self.get_core()?.minibuffer.lock()?.as_mut()?.query(query); let mut screen = self.get_core()?.screen.lock()?; |