mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-29 08:34:36 +02:00
drop poll in input thread; may revert but it improves performance
The issue seems to be related to a crossterm update, but not sure.
This commit is contained in:
parent
9340044648
commit
b60704ccc1
@ -192,6 +192,14 @@ impl AppState {
|
||||
// FIXME: Redraw with new screen, save old screen state if main
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_freeze(&mut self) -> Status {
|
||||
self.frozen_state = match self.frozen_state {
|
||||
FrozenState::NotFrozen => FrozenState::Frozen(Box::new(self.data_collection.clone())),
|
||||
FrozenState::Frozen(_) => FrozenState::NotFrozen,
|
||||
};
|
||||
Status::Captured
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for AppState {
|
||||
@ -296,6 +304,7 @@ impl Application for AppState {
|
||||
Event::Keyboard(event) => {
|
||||
if event.modifiers.is_empty() {
|
||||
match event.code {
|
||||
KeyCode::Char('f') | KeyCode::Char('F') => self.toggle_freeze(),
|
||||
KeyCode::Char('q') | KeyCode::Char('Q') => on_quit(messages),
|
||||
_ => Status::Ignored,
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ fn main() -> Result<()> {
|
||||
|
||||
// Set up input handling
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
let input_thread = create_input_thread(sender.clone(), thread_termination_lock.clone());
|
||||
let _input_thread = create_input_thread(sender.clone());
|
||||
|
||||
// Cleaning loop
|
||||
// TODO: [Refactor, Optimization (Potentially, maybe not)] Probably worth spinning this off into an async thread or something...
|
||||
@ -95,7 +95,6 @@ fn main() -> Result<()> {
|
||||
*thread_termination_lock.lock().unwrap() = true;
|
||||
thread_termination_cvar.notify_all();
|
||||
|
||||
let _ = input_thread.join();
|
||||
cleanup_terminal(&mut terminal);
|
||||
|
||||
Ok(())
|
||||
|
68
src/lib.rs
68
src/lib.rs
@ -183,7 +183,6 @@ pub fn panic_hook(panic_info: &PanicInfo<'_>) {
|
||||
|
||||
pub fn create_input_thread(
|
||||
sender: std::sync::mpsc::Sender<RuntimeEvent<AppMessages>>,
|
||||
termination_ctrl_lock: Arc<Mutex<bool>>,
|
||||
) -> std::thread::JoinHandle<()> {
|
||||
thread::spawn(move || {
|
||||
// TODO: [Optimization, Input] Maybe experiment with removing these timers. Look into using buffers instead?
|
||||
@ -191,51 +190,38 @@ pub fn create_input_thread(
|
||||
let mut keyboard_timer = Instant::now();
|
||||
|
||||
loop {
|
||||
if let Ok(is_terminated) = termination_ctrl_lock.try_lock() {
|
||||
// We don't block.
|
||||
if *is_terminated {
|
||||
drop(is_terminated);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(poll) = poll(Duration::from_millis(20)) {
|
||||
if poll {
|
||||
if let Ok(event) = read() {
|
||||
match event {
|
||||
crossterm::event::Event::Key(event) => {
|
||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 {
|
||||
if sender
|
||||
.send(RuntimeEvent::UserInterface(Event::Keyboard(event)))
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
keyboard_timer = Instant::now();
|
||||
}
|
||||
if let Ok(event) = read() {
|
||||
match event {
|
||||
crossterm::event::Event::Key(event) => {
|
||||
if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 {
|
||||
if sender
|
||||
.send(RuntimeEvent::UserInterface(Event::Keyboard(event)))
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
crossterm::event::Event::Mouse(event) => match &event.kind {
|
||||
MouseEventKind::Drag(_) => {}
|
||||
MouseEventKind::Moved => {}
|
||||
_ => {
|
||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 20
|
||||
{
|
||||
if sender
|
||||
.send(RuntimeEvent::UserInterface(Event::Mouse(event)))
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
mouse_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
},
|
||||
crossterm::event::Event::Resize(width, height) => {
|
||||
if sender.send(RuntimeEvent::Resize { width, height }).is_err() {
|
||||
keyboard_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
crossterm::event::Event::Mouse(event) => match &event.kind {
|
||||
MouseEventKind::Drag(_) => {}
|
||||
MouseEventKind::Moved => {}
|
||||
_ => {
|
||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 20 {
|
||||
if sender
|
||||
.send(RuntimeEvent::UserInterface(Event::Mouse(event)))
|
||||
.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
mouse_timer = Instant::now();
|
||||
}
|
||||
}
|
||||
},
|
||||
crossterm::event::Event::Resize(width, height) => {
|
||||
if sender.send(RuntimeEvent::Resize { width, height }).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user