aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-11 19:08:29 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-11 19:08:29 -0800
commit0f01c2aa5cca178ca2c46e512931302b069886af (patch)
treefc97545c414dd2c41789796523197e00f44fcbc3
parent28dffed640adf8815294faa7a1f4b4d8a50c9707 (diff)
downloadeditor-0f01c2aa5cca178ca2c46e512931302b069886af.tar.zst
Don't call read immediately in cursor_pos.
I forgot that read can block. We actually don't want cursor_pos to block for user input before querying, since it will fail nearly every time. It did give me a good opportunity to test the error handling though.
-rw-r--r--src/term.rs3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/term.rs b/src/term.rs
index d77a8f6..54b241c 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -109,8 +109,7 @@ pub fn read_key(stdin: &mut BufReader<Stdin>) -> Result<Key, Box<dyn Error>> {
// cursor_pos *WILL* fail if the user is typing on the keyboard. Be sure to handle
// errors appropriately.
pub fn cursor_pos(stdin: &mut BufReader<Stdin>) -> Result<(u16, u16), Box<dyn Error>> {
- let buf = stdin.fill_buf()?;
- if buf.len() > 0 {
+ if stdin.buffer().len() > 0 {
// If there is any buffered input, the below call to fill_buf will just return the buffered
// data and not actually read the terminal response.
return Err(Box::from("interrupted"));