From 3a9ab729dbd772ebe2729f4faad4319af8a7ee31 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 8 Jan 2021 08:55:43 -0800 Subject: [PATCH] termwiz: fixup win32 build --- termwiz/src/terminal/windows.rs | 80 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/termwiz/src/terminal/windows.rs b/termwiz/src/terminal/windows.rs index d7b647cdb..82bcb7888 100644 --- a/termwiz/src/terminal/windows.rs +++ b/termwiz/src/terminal/windows.rs @@ -1,5 +1,5 @@ use crate::istty::IsTty; -use crate::{bail, format_err, Error}; +use crate::{bail, format_err, Error, Result}; use filedescriptor::{FileDescriptor, OwnedHandle}; use std::cmp::{max, min}; use std::collections::VecDeque; @@ -38,23 +38,23 @@ enum Renderer { } pub trait ConsoleInputHandle { - fn set_input_mode(&mut self, mode: u32) -> Result<(), Error>; - fn get_input_mode(&mut self) -> Result; - fn get_number_of_input_events(&mut self) -> Result; - fn read_console_input(&mut self, num_events: usize) -> Result, Error>; + fn set_input_mode(&mut self, mode: u32) -> Result<()>; + fn get_input_mode(&mut self) -> Result; + fn get_number_of_input_events(&mut self) -> Result; + fn read_console_input(&mut self, num_events: usize) -> Result>; } pub trait ConsoleOutputHandle { - fn set_output_mode(&mut self, mode: u32) -> Result<(), Error>; - fn get_output_mode(&mut self) -> Result; - fn fill_char(&mut self, text: char, x: i16, y: i16, len: u32) -> Result; - fn fill_attr(&mut self, attr: u16, x: i16, y: i16, len: u32) -> Result; - fn set_attr(&mut self, attr: u16) -> Result<(), Error>; - fn set_cursor_position(&mut self, x: i16, y: i16) -> Result<(), Error>; - fn get_buffer_info(&mut self) -> Result; + fn set_output_mode(&mut self, mode: u32) -> Result<()>; + fn get_output_mode(&mut self) -> Result; + fn fill_char(&mut self, text: char, x: i16, y: i16, len: u32) -> Result; + fn fill_attr(&mut self, attr: u16, x: i16, y: i16, len: u32) -> Result; + fn set_attr(&mut self, attr: u16) -> Result<()>; + fn set_cursor_position(&mut self, x: i16, y: i16) -> Result<()>; + fn get_buffer_info(&mut self) -> Result; fn get_buffer_contents(&mut self) -> Result>; fn set_buffer_contents(&mut self, buffer: &[CHAR_INFO]) -> Result<()>; - fn set_viewport(&mut self, left: i16, top: i16, right: i16, bottom: i16) -> Result<(), Error>; + fn set_viewport(&mut self, left: i16, top: i16, right: i16, bottom: i16) -> Result<()>; fn scroll_region( &mut self, left: i16, @@ -64,7 +64,7 @@ pub trait ConsoleOutputHandle { dx: i16, dy: i16, attr: u16, - ) -> Result<(), Error>; + ) -> Result<()>; } struct InputHandle { @@ -72,20 +72,20 @@ struct InputHandle { } impl Read for InputHandle { - fn read(&mut self, buf: &mut [u8]) -> Result { + fn read(&mut self, buf: &mut [u8]) -> IoResult { self.handle.read(buf) } } impl ConsoleInputHandle for InputHandle { - fn set_input_mode(&mut self, mode: u32) -> Result<(), Error> { + fn set_input_mode(&mut self, mode: u32) -> Result<()> { if unsafe { consoleapi::SetConsoleMode(self.handle.as_raw_handle() as *mut _, mode) } == 0 { bail!("SetConsoleMode failed: {}", IoError::last_os_error()); } Ok(()) } - fn get_input_mode(&mut self) -> Result { + fn get_input_mode(&mut self) -> Result { let mut mode = 0; if unsafe { consoleapi::GetConsoleMode(self.handle.as_raw_handle() as *mut _, &mut mode) } == 0 @@ -95,7 +95,7 @@ impl ConsoleInputHandle for InputHandle { Ok(mode) } - fn get_number_of_input_events(&mut self) -> Result { + fn get_number_of_input_events(&mut self) -> Result { let mut num = 0; if unsafe { consoleapi::GetNumberOfConsoleInputEvents( @@ -112,7 +112,7 @@ impl ConsoleInputHandle for InputHandle { Ok(num as usize) } - fn read_console_input(&mut self, num_events: usize) -> Result, Error> { + fn read_console_input(&mut self, num_events: usize) -> Result> { let mut res = Vec::with_capacity(num_events); let empty_record: INPUT_RECORD = unsafe { mem::zeroed() }; res.resize(num_events, empty_record); @@ -216,14 +216,14 @@ impl Write for OutputHandle { } impl ConsoleOutputHandle for OutputHandle { - fn set_output_mode(&mut self, mode: u32) -> Result<(), Error> { + fn set_output_mode(&mut self, mode: u32) -> Result<()> { if unsafe { consoleapi::SetConsoleMode(self.handle.as_raw_handle() as *mut _, mode) } == 0 { bail!("SetConsoleMode failed: {}", IoError::last_os_error()); } Ok(()) } - fn get_output_mode(&mut self) -> Result { + fn get_output_mode(&mut self) -> Result { let mut mode = 0; if unsafe { consoleapi::GetConsoleMode(self.handle.as_raw_handle() as *mut _, &mut mode) } == 0 @@ -233,7 +233,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(mode) } - fn fill_char(&mut self, text: char, x: i16, y: i16, len: u32) -> Result { + fn fill_char(&mut self, text: char, x: i16, y: i16, len: u32) -> Result { let mut wrote = 0; if unsafe { FillConsoleOutputCharacterW( @@ -253,7 +253,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(wrote) } - fn fill_attr(&mut self, attr: u16, x: i16, y: i16, len: u32) -> Result { + fn fill_attr(&mut self, attr: u16, x: i16, y: i16, len: u32) -> Result { let mut wrote = 0; if unsafe { FillConsoleOutputAttribute( @@ -273,7 +273,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(wrote) } - fn set_attr(&mut self, attr: u16) -> Result<(), Error> { + fn set_attr(&mut self, attr: u16) -> Result<()> { if unsafe { SetConsoleTextAttribute(self.handle.as_raw_handle() as *mut _, attr) } == 0 { bail!( "SetConsoleTextAttribute failed: {}", @@ -283,7 +283,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(()) } - fn set_cursor_position(&mut self, x: i16, y: i16) -> Result<(), Error> { + fn set_cursor_position(&mut self, x: i16, y: i16) -> Result<()> { if unsafe { SetConsoleCursorPosition(self.handle.as_raw_handle() as *mut _, COORD { X: x, Y: y }) } == 0 @@ -370,7 +370,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(()) } - fn get_buffer_info(&mut self) -> Result { + fn get_buffer_info(&mut self) -> Result { let mut info: CONSOLE_SCREEN_BUFFER_INFO = unsafe { mem::zeroed() }; let ok = unsafe { GetConsoleScreenBufferInfo(self.handle.as_raw_handle() as *mut _, &mut info as *mut _) @@ -384,7 +384,7 @@ impl ConsoleOutputHandle for OutputHandle { Ok(info) } - fn set_viewport(&mut self, left: i16, top: i16, right: i16, bottom: i16) -> Result<(), Error> { + fn set_viewport(&mut self, left: i16, top: i16, right: i16, bottom: i16) -> Result<()> { let rect = SMALL_RECT { Left: left, Top: top, @@ -406,7 +406,7 @@ impl ConsoleOutputHandle for OutputHandle { dx: i16, dy: i16, attr: u16, - ) -> Result<(), Error> { + ) -> Result<()> { let scroll_rect = SMALL_RECT { Left: max(left, left - dx), Top: max(top, top - dy), @@ -477,7 +477,7 @@ impl WindowsTerminal { /// Note that this will duplicate the underlying file descriptors /// and will no longer participate in the stdin/stdout locking /// provided by the rust standard library. - pub fn new_from_stdio(caps: Capabilities) -> Result { + pub fn new_from_stdio(caps: Capabilities) -> Result { Self::new_with(caps, stdin(), stdout()) } @@ -488,7 +488,7 @@ impl WindowsTerminal { caps: Capabilities, read: A, write: B, - ) -> Result { + ) -> Result { if !read.is_tty() || !write.is_tty() { bail!("stdin and stdout must both be tty handles"); } @@ -558,13 +558,13 @@ impl WindowsTerminal { /// Attempt to explicitly open handles to a console device (CONIN$, /// CONOUT$). This should yield the terminal already associated with /// the process, even if stdio streams have been redirected. - pub fn new(caps: Capabilities) -> Result { + pub fn new(caps: Capabilities) -> Result { let read = OpenOptions::new().read(true).write(true).open("CONIN$")?; let write = OpenOptions::new().read(true).write(true).open("CONOUT$")?; Self::new_with(caps, read, write) } - pub fn enable_virtual_terminal_processing(&mut self) -> Result<(), Error> { + pub fn enable_virtual_terminal_processing(&mut self) -> Result<()> { let mode = self.output_handle.get_output_mode()?; self.output_handle.set_output_mode( mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN, @@ -590,7 +590,7 @@ impl WindowsTerminalWaker { } impl Terminal for WindowsTerminal { - fn set_raw_mode(&mut self) -> Result<(), Error> { + fn set_raw_mode(&mut self) -> Result<()> { let mode = self.output_handle.get_output_mode()?; self.output_handle .set_output_mode(mode | DISABLE_NEWLINE_AUTO_RETURN) @@ -621,18 +621,18 @@ impl Terminal for WindowsTerminal { ) } - fn enter_alternate_screen(&mut self) -> Result<(), Error> { + fn enter_alternate_screen(&mut self) -> Result<()> { // TODO: Implement using CreateConsoleScreenBuffer and // SetConsoleActiveScreenBuffer. Ok(()) } - fn exit_alternate_screen(&mut self) -> Result<(), Error> { + fn exit_alternate_screen(&mut self) -> Result<()> { // TODO: Implement using SetConsoleActiveScreenBuffer. Ok(()) } - fn get_screen_size(&mut self) -> Result { + fn get_screen_size(&mut self) -> Result { let info = self.output_handle.get_buffer_info()?; let (cols, rows) = dimensions_from_buffer_info(info); @@ -644,7 +644,7 @@ impl Terminal for WindowsTerminal { }) } - fn set_screen_size(&mut self, size: ScreenSize) -> Result<(), Error> { + fn set_screen_size(&mut self, size: ScreenSize) -> Result<()> { // FIXME: take into account the visible window size here; // this probably changes the size of everything including scrollback let size = COORD { @@ -661,20 +661,20 @@ impl Terminal for WindowsTerminal { Ok(()) } - fn render(&mut self, changes: &[Change]) -> Result<(), Error> { + fn render(&mut self, changes: &[Change]) -> Result<()> { match &mut self.renderer { Renderer::Terminfo(r) => r.render_to(changes, &mut self.output_handle), Renderer::Windows(r) => r.render_to(changes, &mut self.output_handle), } } - fn flush(&mut self) -> Result<(), Error> { + fn flush(&mut self) -> Result<()> { self.output_handle .flush() .map_err(|e| format_err!("flush failed: {}", e)) } - fn poll_input(&mut self, wait: Option) -> Result, Error> { + fn poll_input(&mut self, wait: Option) -> Result> { loop { if let Some(event) = self.input_queue.pop_front() { return Ok(Some(event));