mirror of
https://github.com/bobwen-dev/hunter
synced 2025-04-12 00:55:41 +02:00
improved procview
This commit is contained in:
parent
9338f5e912
commit
32ab32fc5d
@ -12,6 +12,7 @@ use crate::listview::{Listable, ListView};
|
|||||||
use crate::textview::TextView;
|
use crate::textview::TextView;
|
||||||
use crate::widget::Widget;
|
use crate::widget::Widget;
|
||||||
use crate::window::{send_event, Events};
|
use crate::window::{send_event, Events};
|
||||||
|
use crate::preview::WillBeWidget;
|
||||||
use crate::fail::{HResult, HError};
|
use crate::fail::{HResult, HError};
|
||||||
use crate::term;
|
use crate::term;
|
||||||
|
|
||||||
@ -143,7 +144,8 @@ impl ListView<Vec<Process>> {
|
|||||||
pub struct ProcView {
|
pub struct ProcView {
|
||||||
coordinates: Coordinates,
|
coordinates: Coordinates,
|
||||||
proc_list: ListView<Vec<Process>>,
|
proc_list: ListView<Vec<Process>>,
|
||||||
textview: TextView,
|
textview: Option<WillBeWidget<TextView>>,
|
||||||
|
viewing: Option<usize>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProcView {
|
impl ProcView {
|
||||||
@ -151,7 +153,8 @@ impl ProcView {
|
|||||||
ProcView {
|
ProcView {
|
||||||
coordinates: Coordinates::new(),
|
coordinates: Coordinates::new(),
|
||||||
proc_list: ListView::new(vec![]),
|
proc_list: ListView::new(vec![]),
|
||||||
textview: TextView::new_blank(),
|
textview: None,
|
||||||
|
viewing: None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,14 +164,38 @@ impl ProcView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_proc(&mut self) -> HResult<()> {
|
pub fn remove_proc(&mut self) -> HResult<()> {
|
||||||
|
let (_, coords) = self.calculate_coordinates();
|
||||||
|
let coords2 = coords.clone();
|
||||||
|
|
||||||
self.proc_list.remove_proc()?;
|
self.proc_list.remove_proc()?;
|
||||||
self.textview.set_text("");
|
self.textview = Some(WillBeWidget::new(Box::new(move |_| {
|
||||||
|
let mut textview = TextView::new_blank();
|
||||||
|
textview.set_coordinates(&coords);
|
||||||
|
textview.refresh();
|
||||||
|
textview.animate_slide_up();
|
||||||
|
Ok(textview)
|
||||||
|
})));
|
||||||
|
self.textview.as_mut().unwrap().set_coordinates(&coords2);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_output(&mut self) -> HResult<()> {
|
fn show_output(&mut self) -> HResult<()> {
|
||||||
let output = self.proc_list.selected_proc()?.output.lock()?;
|
if Some(self.proc_list.get_selection()) == self.viewing {
|
||||||
self.textview.set_text(&*output);
|
return Ok(());
|
||||||
|
}
|
||||||
|
let output = self.proc_list.selected_proc()?.output.lock()?.clone();
|
||||||
|
let (_, coords) = self.calculate_coordinates();
|
||||||
|
let coords2 = coords.clone();
|
||||||
|
|
||||||
|
self.textview = Some(WillBeWidget::new(Box::new(move |_| {
|
||||||
|
let mut textview = TextView::new_blank();
|
||||||
|
textview.set_coordinates(&coords);
|
||||||
|
textview.set_text(&output);
|
||||||
|
textview.animate_slide_up();
|
||||||
|
Ok(textview)
|
||||||
|
})));
|
||||||
|
self.textview.as_mut().unwrap().set_coordinates(&coords2);
|
||||||
|
self.viewing = Some(self.proc_list.get_selection());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +240,9 @@ impl Widget for ProcView {
|
|||||||
|
|
||||||
let (lcoord, rcoord) = self.calculate_coordinates();
|
let (lcoord, rcoord) = self.calculate_coordinates();
|
||||||
self.proc_list.set_coordinates(&lcoord);
|
self.proc_list.set_coordinates(&lcoord);
|
||||||
self.textview.set_coordinates(&rcoord);
|
if let Some(textview) = &mut self.textview {
|
||||||
|
textview.set_coordinates(&rcoord);
|
||||||
|
}
|
||||||
|
|
||||||
self.refresh();
|
self.refresh();
|
||||||
}
|
}
|
||||||
@ -221,12 +250,18 @@ impl Widget for ProcView {
|
|||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
fn refresh(&mut self) {
|
fn refresh(&mut self) {
|
||||||
self.show_output().ok();
|
self.show_output();
|
||||||
self.proc_list.refresh();
|
self.proc_list.refresh();
|
||||||
self.textview.refresh();
|
if let Some(textview) = &mut self.textview {
|
||||||
|
textview.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn get_drawlist(&self) -> String {
|
fn get_drawlist(&self) -> String {
|
||||||
self.proc_list.get_drawlist() + &self.textview.get_drawlist()
|
if let Some(textview) = &self.textview {
|
||||||
|
self.proc_list.get_drawlist() + &textview.get_drawlist()
|
||||||
|
} else {
|
||||||
|
self.proc_list.get_drawlist()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn on_key(&mut self, key: Key) -> HResult<()> {
|
fn on_key(&mut self, key: Key) -> HResult<()> {
|
||||||
match key {
|
match key {
|
||||||
@ -236,10 +271,12 @@ impl Widget for ProcView {
|
|||||||
Key::Up | Key::Char('p') => {
|
Key::Up | Key::Char('p') => {
|
||||||
self.proc_list.move_up();
|
self.proc_list.move_up();
|
||||||
self.proc_list.refresh();
|
self.proc_list.refresh();
|
||||||
|
self.show_output().ok();
|
||||||
}
|
}
|
||||||
Key::Down | Key::Char('n') => {
|
Key::Down | Key::Char('n') => {
|
||||||
self.proc_list.move_down();
|
self.proc_list.move_down();
|
||||||
self.proc_list.refresh();
|
self.proc_list.refresh();
|
||||||
|
self.show_output().ok();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user