From 0503e344aa729cb6304773d7344d5b591d5b1952 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 2 Oct 2018 17:20:33 -0700 Subject: [PATCH] Second attempt at fixing msys terminal width. Lock the max width on msys-based terminals to 60. I tried a lot of different things, but I was unable to find a way to detect the correct width in mintty. Unfortunately this means that terminals that work correctly like ConEmu will also be capped at 60. C'est la vie. Of course this does not affect cmd, powershell, etc. --- src/cargo/core/shell.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 6b284b7fc76..77f897d6073 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -358,8 +358,7 @@ mod imp { mod imp { extern crate winapi; - use std::mem; - use std::ptr; + use std::{cmp, mem, ptr}; use self::winapi::um::fileapi::*; use self::winapi::um::handleapi::*; use self::winapi::um::processenv::*; @@ -395,13 +394,15 @@ mod imp { CloseHandle(h); if rc != 0 { let width = (csbi.srWindow.Right - csbi.srWindow.Left) as usize; - // Some terminals, such as mintty, always return 79 instead of - // the actual width. In that case, use a conservative value. - if width == 79 { - return Some(60); - } else { - return Some(width); - } + // Unfortunately cygwin/mintty does not set the size of the + // backing console to match the actual window size. This + // always reports a size of 80 or 120 (not sure what + // determines that). Use a conservative max of 60 which should + // work in most circumstances. ConEmu does some magic to + // resize the console correctly, but there's no reasonable way + // to detect which kind of terminal we are running in, or if + // GetConsoleScreenBufferInfo returns accurate information. + return Some(cmp::min(60, width)); } return None; }