Project

General

Profile

Bug #13888

Consistent error in IO::Console.winsize=

Added by jm_beauvais (Jean-Michel Beauvais) 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]
[ruby-core:82741]

Description

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 :

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).

Associated revisions

Revision 59844
Added by nobu (Nobuyoshi Nakada) 3 months ago

console.c: set winsize on Windows

  • ext/io/console/console.c (console_set_winsize): retry shrinking window and screen buffer. [Bug #13888]

History

#1 Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59844.


console.c: set winsize on Windows

  • ext/io/console/console.c (console_set_winsize): retry shrinking window and screen buffer. [Bug #13888]

Also available in: Atom PDF