From cbedfc8a6412483c5a623aecd63042ff273c24ce Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 31 Jan 2025 11:23:00 -0600 Subject: [PATCH] Use Write::write_all(), not write() There is no guarantee that Write::write() will write the entirety of the provided buffer in one go, regardless of how short it is, because that depends on the semantics of the underlying write handle (even if it was a single byte, though in this case that would be because of an interrupt). The only case I'm aware of that would guarantee a single Write::write() call would suffice is when writing into a high-level memory-backed buffer, and we can't make that guarantee (now or in perpetuity). --- src/output.rs | 2 +- src/reader.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/output.rs b/src/output.rs index 8833df4a0..c5d6421f0 100644 --- a/src/output.rs +++ b/src/output.rs @@ -432,7 +432,7 @@ pub fn tputs(&mut self, str: &CStr) { pub fn tputs_bytes(&mut self, str: &[u8]) { self.begin_buffering(); - let _ = self.write(str); + let _ = self.write_all(str); self.end_buffering(); } diff --git a/src/reader.rs b/src/reader.rs index 1c6d0381c..43a5dac97 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1416,7 +1416,7 @@ pub fn request_cursor_position( assert!(self.blocking_wait.is_none()); self.blocking_wait = Some(BlockingWait::CursorPosition(cursor_position_wait)); } - let _ = out.write(b"\x1b[6n"); + let _ = out.write_all(b"\x1b[6n"); self.save_screen_state(); } @@ -2175,12 +2175,12 @@ fn readline(&mut self, nchars: Option) -> Option { let mut out = Outputter::stdoutput().borrow_mut(); out.begin_buffering(); // Query for kitty keyboard protocol support. - let _ = out.write(kitty_progressive_enhancements_query()); + let _ = out.write_all(kitty_progressive_enhancements_query()); // Query for cursor position reporting support. zelf.request_cursor_position(&mut out, None); // Query for synchronized output support. - let _ = out.write(b"\x1b[?2026$p"); - let _ = out.write(QUERY_PRIMARY_DEVICE_ATTRIBUTE); + let _ = out.write_all(b"\x1b[?2026$p"); + let _ = out.write_all(QUERY_PRIMARY_DEVICE_ATTRIBUTE); out.end_buffering(); } } @@ -2518,7 +2518,7 @@ fn handle_char_event(&mut self, injected_event: Option) -> ControlFlo let mut out = Outputter::stdoutput().borrow_mut(); out.begin_buffering(); query_capabilities_via_dcs(out.by_ref()); - let _ = out.write(QUERY_PRIMARY_DEVICE_ATTRIBUTE); + let _ = out.write_all(QUERY_PRIMARY_DEVICE_ATTRIBUTE); out.end_buffering(); self.save_screen_state(); self.blocking_wait = Some(BlockingWait::Startup(Queried::Twice)); @@ -2556,12 +2556,12 @@ fn xtgettcap(out: &mut impl Write, cap: &str) { } fn query_capabilities_via_dcs(out: &mut impl std::io::Write) { - let _ = out.write(b"\x1b[?2026h"); // begin synchronized update - let _ = out.write(b"\x1b[?1049h"); // enable alternative screen buffer + let _ = out.write_all(b"\x1b[?2026h"); // begin synchronized update + let _ = out.write_all(b"\x1b[?1049h"); // enable alternative screen buffer xtgettcap(out.by_ref(), "indn"); xtgettcap(out.by_ref(), "cuu"); - let _ = out.write(b"\x1b[?1049l"); // disable alternative screen buffer - let _ = out.write(b"\x1b[?2026l"); // end synchronized update + let _ = out.write_all(b"\x1b[?1049l"); // disable alternative screen buffer + let _ = out.write_all(b"\x1b[?2026l"); // end synchronized update } impl<'a> Reader<'a> {