crash fix

This commit is contained in:
rabite 2019-03-10 12:55:56 +01:00
parent e1a9d62b16
commit 9fcc12f464
2 changed files with 18 additions and 6 deletions

View File

@ -172,10 +172,9 @@ impl ListView<Vec<Process>> {
Ok(format!( Ok(format!(
"{}{}{}{}{}{}", "{}{}{}{}{}{}",
termion::cursor::Save, termion::cursor::Save,
format!("{}{}{:padding$}{}", format!("{}{:padding$}{}",
term::normal_color(), term::normal_color(),
&sized_string, &sized_string,
" ",
term::normal_color(), term::normal_color(),
padding = padding as usize), padding = padding as usize),
termion::cursor::Restore, termion::cursor::Restore,
@ -271,6 +270,7 @@ impl ProcView {
} }
pub fn remove_proc(&mut self) -> HResult<()> { pub fn remove_proc(&mut self) -> HResult<()> {
if self.get_listview().content.len() == 0 { return Ok(()) }
self.get_listview().remove_proc()?; self.get_listview().remove_proc()?;
self.get_textview().change_to(Box::new(move |_, core| { self.get_textview().change_to(Box::new(move |_, core| {
let mut textview = TextView::new_blank(&core); let mut textview = TextView::new_blank(&core);

View File

@ -43,15 +43,28 @@ impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
pub fn push_widget(&mut self, widget: T) -> HResult<()> { pub fn push_widget(&mut self, widget: T) -> HResult<()> {
self.widgets.push(widget); self.widgets.push(widget);
self.refresh() Ok(())
} }
pub fn pop_widget(&mut self) -> HResult<T> { pub fn pop_widget(&mut self) -> HResult<T> {
let widget = self.widgets.pop()?; let widget = self.widgets.pop()?;
self.refresh()?; if self.widgets.len() <= self.active {
self.active -= 1;
}
Ok(widget) Ok(widget)
} }
pub fn remove_widget(&mut self, index: usize) -> HResult<()> {
let len = self.widgets.len();
if len > 1 {
self.widgets.remove(index);
if index+1 == len {
self.active -= 1;
}
}
Ok(())
}
pub fn active_tab_(&self) -> &T { pub fn active_tab_(&self) -> &T {
&self.widgets[self.active] &self.widgets[self.active]
} }
@ -61,8 +74,7 @@ impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
} }
pub fn close_tab_(&mut self) -> HResult<()> { pub fn close_tab_(&mut self) -> HResult<()> {
self.pop_widget()?; self.remove_widget(self.active).log();
self.active -= 1;
Ok(()) Ok(())
} }