mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
Potential fix for a panic with time comparisons
This commit is contained in:
parent
e78fbbbf55
commit
86c8ce68e7
5 changed files with 21 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bottom"
|
||||
version = "0.2.0"
|
||||
version = "0.1.2"
|
||||
authors = ["Clement Tsang <clementjhtsang@gmail.com>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/ClementTsang/bottom"
|
||||
|
|
|
@ -16,10 +16,11 @@ pub enum ApplicationPosition {
|
|||
Process,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ScrollDirection {
|
||||
/// UP means scrolling up --- this usually DECREMENTS
|
||||
// UP means scrolling up --- this usually DECREMENTS
|
||||
UP,
|
||||
/// DOWN means scrolling down --- this usually INCREMENTS
|
||||
// DOWN means scrolling down --- this usually INCREMENTS
|
||||
DOWN,
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,6 @@ impl DataState {
|
|||
self.sys.refresh_network();
|
||||
}
|
||||
|
||||
// Filter out stale timed entries
|
||||
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!
|
||||
|
@ -153,12 +152,14 @@ impl DataState {
|
|||
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
|
||||
.prev_pid_stats
|
||||
.iter()
|
||||
.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())
|
||||
.collect();
|
||||
|
@ -172,8 +173,7 @@ impl DataState {
|
|||
.iter()
|
||||
.cloned()
|
||||
.filter(|entry| {
|
||||
current_instant.duration_since(entry.instant).as_secs()
|
||||
<= self.stale_max_seconds
|
||||
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -183,8 +183,7 @@ impl DataState {
|
|||
.iter()
|
||||
.cloned()
|
||||
.filter(|entry| {
|
||||
current_instant.duration_since(entry.instant).as_secs()
|
||||
<= self.stale_max_seconds
|
||||
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -194,8 +193,7 @@ impl DataState {
|
|||
.iter()
|
||||
.cloned()
|
||||
.filter(|entry| {
|
||||
current_instant.duration_since(entry.instant).as_secs()
|
||||
<= self.stale_max_seconds
|
||||
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -205,8 +203,7 @@ impl DataState {
|
|||
.iter()
|
||||
.cloned()
|
||||
.filter(|entry| {
|
||||
current_instant.duration_since(entry.instant).as_secs()
|
||||
<= self.stale_max_seconds
|
||||
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
@ -216,12 +213,11 @@ impl DataState {
|
|||
.iter()
|
||||
.cloned()
|
||||
.filter(|entry| {
|
||||
current_instant.duration_since(entry.instant).as_secs()
|
||||
<= self.stale_max_seconds
|
||||
clean_instant.duration_since(entry.instant).as_secs() <= self.stale_max_seconds
|
||||
})
|
||||
.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,
|
||||
currently_selected_position: &mut i64,
|
||||
) -> i64 {
|
||||
debug!("Scroll direction: {:?}", scroll_direction);
|
||||
debug!(
|
||||
"Prev: {}, curr: {}",
|
||||
*previous_position, *currently_selected_position
|
||||
);
|
||||
match scroll_direction {
|
||||
app::ScrollDirection::DOWN => {
|
||||
if *currently_selected_position < num_rows {
|
||||
|
|
|
@ -150,14 +150,14 @@ fn main() -> error::Result<()> {
|
|||
loop {
|
||||
if let Ok(event) = event::read() {
|
||||
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() {
|
||||
return;
|
||||
}
|
||||
keyboard_timer = Instant::now();
|
||||
}
|
||||
} 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() {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue