Skip to content

Commit

Permalink
Reposition cursor on exit and fix `The cursor position could not be r…
Browse files Browse the repository at this point in the history
…ead within a normal duration` errors due to blocking reads
  • Loading branch information
pdecat committed Dec 19, 2022
1 parent 6e7309e commit a904b54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/command/client/search/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{thread, time::Duration};

use crossbeam_channel::unbounded;
use crossterm::event::read;
use crossterm::event::{poll, read};

pub enum Event<I> {
Input(I),
Expand Down Expand Up @@ -38,10 +38,12 @@ impl Events {
{
let tx = tx.clone();
thread::spawn(move || loop {
let event = read().unwrap();
if let Err(err) = tx.send(Event::Input(event)) {
eprintln!("{err}");
return;
if poll(Duration::from_millis(10)).unwrap() {
let event = read().unwrap();
if let Err(err) = tx.send(Event::Input(event)) {
eprintln!("{err}");
return;
}
}
})
};
Expand Down
3 changes: 3 additions & 0 deletions src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ pub async fn history(
execute!(terminal.backend_mut(), DisableMouseCapture)?;
disable_raw_mode()?;

let current_cursor = terminal.get_cursor()?;
terminal.set_cursor(0, current_cursor.1 + 2)?;

if index < results.len() {
// index is in bounds so we return that entry
Ok(results.swap_remove(index).command)
Expand Down

0 comments on commit a904b54

Please sign in to comment.