diff --git a/crossterm_terminal/src/sys/winapi.rs b/crossterm_terminal/src/sys/winapi.rs index 1244143..18dbf15 100644 --- a/crossterm_terminal/src/sys/winapi.rs +++ b/crossterm_terminal/src/sys/winapi.rs @@ -8,6 +8,10 @@ pub fn exit() { #[cfg(windows)] pub fn get_terminal_size() -> Result<(u16, u16)> { - let buffer = ScreenBuffer::current()?; - Ok(buffer.info()?.terminal_size().into()) + let terminal_size = ScreenBuffer::current()?.info()?.terminal_size(); + // windows starts counting at 0, unix at 1, add one to replicated unix behaviour. + Ok(( + (terminal_size.width + 1) as u16, + (terminal_size.height + 1) as u16, + )) } diff --git a/crossterm_terminal/src/terminal/ansi_terminal.rs b/crossterm_terminal/src/terminal/ansi_terminal.rs index 24093e3..06adcf9 100644 --- a/crossterm_terminal/src/terminal/ansi_terminal.rs +++ b/crossterm_terminal/src/terminal/ansi_terminal.rs @@ -85,8 +85,8 @@ mod tests { use super::{AnsiTerminal, ITerminal}; /* ======================== ANSI =========================== */ - // TODO - Test is disabled, because it's failing on Travis CI #[test] + // TODO - Test is disabled, because it's failing on Travis CI #[ignore] fn test_resize_ansi() { if try_enable_ansi() { @@ -94,11 +94,12 @@ mod tests { let (width, height) = terminal.size().unwrap(); - terminal.set_size(30, 30).unwrap(); + terminal.set_size(35, 35).unwrap(); // see issue: https://github.com/eminence/terminal-size/issues/11 thread::sleep(time::Duration::from_millis(30)); - assert_eq!((30, 30), terminal.size().unwrap()); + assert_eq!((35, 35), terminal.size().unwrap()); + // reset to previous size terminal.set_size(width, height).unwrap(); // see issue: https://github.com/eminence/terminal-size/issues/11 thread::sleep(time::Duration::from_millis(30)); diff --git a/crossterm_terminal/src/terminal/winapi_terminal.rs b/crossterm_terminal/src/terminal/winapi_terminal.rs index 50d2504..42ca353 100644 --- a/crossterm_terminal/src/terminal/winapi_terminal.rs +++ b/crossterm_terminal/src/terminal/winapi_terminal.rs @@ -129,7 +129,7 @@ impl ITerminal for WinApiTerminal { } if resize_buffer { - if let Err(_) = screen_buffer.set_size(new_size.width, new_size.height) { + if let Err(_) = screen_buffer.set_size(new_size.width - 1, new_size.height - 1) { return Err(ErrorKind::ResizingTerminalFailure(String::from( "Something went wrong when setting screen buffer size.", ))); @@ -138,13 +138,14 @@ impl ITerminal for WinApiTerminal { let mut window = window.clone(); // Preserve the position, but change the size. - window.bottom = window.top + height; - window.right = window.left + width; + window.bottom = window.top + height - 1; + window.right = window.left + width - 1; console.set_console_info(true, window)?; // If we resized the buffer, un-resize it. if resize_buffer { - if let Err(_) = screen_buffer.set_size(current_size.width, current_size.height) { + if let Err(_) = screen_buffer.set_size(current_size.width - 1, current_size.height - 1) + { return Err(ErrorKind::ResizingTerminalFailure(String::from( "Something went wrong when setting screen buffer size.", ))); @@ -280,9 +281,7 @@ fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) -> mod tests { use super::{ITerminal, WinApiTerminal}; - // TODO - Test is ignored, because it returns wrong result (31 != 30) #[test] - #[ignore] fn test_resize_winapi() { let terminal = WinApiTerminal::new(); @@ -291,6 +290,7 @@ mod tests { terminal.set_size(30, 30).unwrap(); assert_eq!((30, 30), terminal.size().unwrap()); + // reset to previous size terminal.set_size(width, height).unwrap(); assert_eq!((width, height), terminal.size().unwrap()); }