mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-31 01:24:31 +02:00
Potential fix for a panic with time comparisons
This commit is contained in:
parent
e78fbbbf55
commit
86c8ce68e7
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bottom"
|
name = "bottom"
|
||||||
version = "0.2.0"
|
version = "0.1.2"
|
||||||
authors = ["Clement Tsang <clementjhtsang@gmail.com>"]
|
authors = ["Clement Tsang <clementjhtsang@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
repository = "https://github.com/ClementTsang/bottom"
|
repository = "https://github.com/ClementTsang/bottom"
|
||||||
|
@ -16,10 +16,11 @@ pub enum ApplicationPosition {
|
|||||||
Process,
|
Process,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum ScrollDirection {
|
pub enum ScrollDirection {
|
||||||
/// UP means scrolling up --- this usually DECREMENTS
|
// UP means scrolling up --- this usually DECREMENTS
|
||||||
UP,
|
UP,
|
||||||
/// DOWN means scrolling down --- this usually INCREMENTS
|
// DOWN means scrolling down --- this usually INCREMENTS
|
||||||
DOWN,
|
DOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,6 @@ impl DataState {
|
|||||||
self.sys.refresh_network();
|
self.sys.refresh_network();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out stale timed entries
|
|
||||||
let current_instant = std::time::Instant::now();
|
let current_instant = std::time::Instant::now();
|
||||||
|
|
||||||
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
// What we want to do: For timed data, if there is an error, just do not add. For other data, just don't update!
|
||||||
@ -153,12 +152,14 @@ impl DataState {
|
|||||||
self.first_run = false;
|
self.first_run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if current_instant.duration_since(self.last_clean).as_secs() > self.stale_max_seconds {
|
// Filter out stale timed entries
|
||||||
|
let clean_instant = Instant::now();
|
||||||
|
if clean_instant.duration_since(self.last_clean).as_secs() > self.stale_max_seconds {
|
||||||
let stale_list: Vec<_> = self
|
let stale_list: Vec<_> = self
|
||||||
.prev_pid_stats
|
.prev_pid_stats
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|&(_, &v)| {
|
.filter(|&(_, &v)| {
|
||||||
current_instant.duration_since(v.1).as_secs() > self.stale_max_seconds
|
clean_instant.duration_since(v.1).as_secs() > self.stale_max_seconds
|
||||||
})
|
})
|
||||||
.map(|(k, _)| k.clone())
|
.map(|(k, _)| k.clone())
|
||||||
.collect();
|
.collect();
|
||||||
@ -172,8 +173,7 @@ impl DataState {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
current_instant.duration_since(entry.instant).as_secs()
|
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||||
<= self.stale_max_seconds
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -183,8 +183,7 @@ impl DataState {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
current_instant.duration_since(entry.instant).as_secs()
|
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||||
<= self.stale_max_seconds
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -194,8 +193,7 @@ impl DataState {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
current_instant.duration_since(entry.instant).as_secs()
|
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||||
<= self.stale_max_seconds
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -205,8 +203,7 @@ impl DataState {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
current_instant.duration_since(entry.instant).as_secs()
|
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||||
<= self.stale_max_seconds
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -216,12 +213,11 @@ impl DataState {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.filter(|entry| {
|
.filter(|entry| {
|
||||||
current_instant.duration_since(entry.instant).as_secs()
|
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||||
<= self.stale_max_seconds
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
self.last_clean = current_instant;
|
self.last_clean = clean_instant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -974,6 +974,11 @@ fn get_start_position(
|
|||||||
num_rows: i64, scroll_direction: &app::ScrollDirection, previous_position: &mut i64,
|
num_rows: i64, scroll_direction: &app::ScrollDirection, previous_position: &mut i64,
|
||||||
currently_selected_position: &mut i64,
|
currently_selected_position: &mut i64,
|
||||||
) -> i64 {
|
) -> i64 {
|
||||||
|
debug!("Scroll direction: {:?}", scroll_direction);
|
||||||
|
debug!(
|
||||||
|
"Prev: {}, curr: {}",
|
||||||
|
*previous_position, *currently_selected_position
|
||||||
|
);
|
||||||
match scroll_direction {
|
match scroll_direction {
|
||||||
app::ScrollDirection::DOWN => {
|
app::ScrollDirection::DOWN => {
|
||||||
if *currently_selected_position < num_rows {
|
if *currently_selected_position < num_rows {
|
||||||
|
@ -150,14 +150,14 @@ fn main() -> error::Result<()> {
|
|||||||
loop {
|
loop {
|
||||||
if let Ok(event) = event::read() {
|
if let Ok(event) = event::read() {
|
||||||
if let CEvent::Key(key) = event {
|
if let CEvent::Key(key) = event {
|
||||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 30 {
|
if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 {
|
||||||
if tx.send(Event::KeyInput(key)).is_err() {
|
if tx.send(Event::KeyInput(key)).is_err() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keyboard_timer = Instant::now();
|
keyboard_timer = Instant::now();
|
||||||
}
|
}
|
||||||
} else if let CEvent::Mouse(mouse) = event {
|
} else if let CEvent::Mouse(mouse) = event {
|
||||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 30 {
|
if Instant::now().duration_since(mouse_timer).as_millis() >= 20 {
|
||||||
if tx.send(Event::MouseInput(mouse)).is_err() {
|
if tx.send(Event::MouseInput(mouse)).is_err() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user