Issue #13888 has been reported by jm_beauvais (Jean-Michel Beauvais).

----------------------------------------
Bug #13888: Consistent error in IO::Console.winsize=
https://bugs.ruby-lang.org/issues/13888

* Author: jm_beauvais (Jean-Michel Beauvais)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
When trying to change the console window size, an error is always thrown, but the column size gets changed if the new value is higher than old value.
This behaviour can be observed by running the following code :

~~~ ruby
require 'io/console'

rows, cols = IO::console.winsize
puts "START : r = #{rows}, c = #{cols}", '* INCREASE COLUMNS BY 1', nil
arr = rows, cols+1
# 4 args same error
#arr = rows, cols+1, 0, 0

begin
	IO::console.winsize = arr
rescue Errno::EINVAL
	puts 'Predicted error...', $!
end

rows, cols = IO::console.winsize
puts nil, " STEP : r = #{rows}, c = #{cols}", '* DECREASE COLUMNS BY 1', nil # Column size has increased even if an error was raised.
arr = rows, cols-1
#arr = rows, cols-1, 0, 0

begin
	IO::console.winsize = arr
rescue Errno::EINVAL
	puts 'Predicted error...', $!
end

rows, cols = IO::console.winsize
puts nil, "  END : r = #{rows}, c = #{cols}" # Column size was not decreased.
gets
~~~

Which returns :

~~~

START : r = 25, c = 80
* INCREASE COLUMNS BY 1

Predicted error...
Invalid argument - SetConsoleWindowInfo

 STEP : r = 25, c = 81
* DECREASE COLUMNS BY 1

Predicted error...
Invalid argument - SetConsoleWindowInfo

  END : r = 25, c = 81

~~~

This was observed on a Windows 7 x64 computer (all important updates installed up to 2017-09-10).




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>