mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-29 16:44:54 +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
|
// 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 {
|
impl Application for AppState {
|
||||||
@ -296,6 +304,7 @@ impl Application for AppState {
|
|||||||
Event::Keyboard(event) => {
|
Event::Keyboard(event) => {
|
||||||
if event.modifiers.is_empty() {
|
if event.modifiers.is_empty() {
|
||||||
match event.code {
|
match event.code {
|
||||||
|
KeyCode::Char('f') | KeyCode::Char('F') => self.toggle_freeze(),
|
||||||
KeyCode::Char('q') | KeyCode::Char('Q') => on_quit(messages),
|
KeyCode::Char('q') | KeyCode::Char('Q') => on_quit(messages),
|
||||||
_ => Status::Ignored,
|
_ => Status::Ignored,
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
// Set up input handling
|
// Set up input handling
|
||||||
let (sender, receiver) = mpsc::channel();
|
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
|
// Cleaning loop
|
||||||
// TODO: [Refactor, Optimization (Potentially, maybe not)] Probably worth spinning this off into an async thread or something...
|
// 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_lock.lock().unwrap() = true;
|
||||||
thread_termination_cvar.notify_all();
|
thread_termination_cvar.notify_all();
|
||||||
|
|
||||||
let _ = input_thread.join();
|
|
||||||
cleanup_terminal(&mut terminal);
|
cleanup_terminal(&mut terminal);
|
||||||
|
|
||||||
Ok(())
|
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(
|
pub fn create_input_thread(
|
||||||
sender: std::sync::mpsc::Sender<RuntimeEvent<AppMessages>>,
|
sender: std::sync::mpsc::Sender<RuntimeEvent<AppMessages>>,
|
||||||
termination_ctrl_lock: Arc<Mutex<bool>>,
|
|
||||||
) -> std::thread::JoinHandle<()> {
|
) -> std::thread::JoinHandle<()> {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
// TODO: [Optimization, Input] Maybe experiment with removing these timers. Look into using buffers instead?
|
// 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();
|
let mut keyboard_timer = Instant::now();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(is_terminated) = termination_ctrl_lock.try_lock() {
|
if let Ok(event) = read() {
|
||||||
// We don't block.
|
match event {
|
||||||
if *is_terminated {
|
crossterm::event::Event::Key(event) => {
|
||||||
drop(is_terminated);
|
if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 {
|
||||||
break;
|
if sender
|
||||||
}
|
.send(RuntimeEvent::UserInterface(Event::Keyboard(event)))
|
||||||
}
|
.is_err()
|
||||||
|
{
|
||||||
if let Ok(poll) = poll(Duration::from_millis(20)) {
|
break;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
crossterm::event::Event::Mouse(event) => match &event.kind {
|
keyboard_timer = Instant::now();
|
||||||
MouseEventKind::Drag(_) => {}
|
}
|
||||||
MouseEventKind::Moved => {}
|
}
|
||||||
_ => {
|
crossterm::event::Event::Mouse(event) => match &event.kind {
|
||||||
if Instant::now().duration_since(mouse_timer).as_millis() >= 20
|
MouseEventKind::Drag(_) => {}
|
||||||
{
|
MouseEventKind::Moved => {}
|
||||||
if sender
|
_ => {
|
||||||
.send(RuntimeEvent::UserInterface(Event::Mouse(event)))
|
if Instant::now().duration_since(mouse_timer).as_millis() >= 20 {
|
||||||
.is_err()
|
if sender
|
||||||
{
|
.send(RuntimeEvent::UserInterface(Event::Mouse(event)))
|
||||||
break;
|
.is_err()
|
||||||
}
|
{
|
||||||
mouse_timer = Instant::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
crossterm::event::Event::Resize(width, height) => {
|
|
||||||
if sender.send(RuntimeEvent::Resize { width, height }).is_err() {
|
|
||||||
break;
|
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