Project

General

Profile

Actions

Bug #13707

closed

Windows ANSI escape sequences incorrectly positions cursor

Added by caspercg (Casper G) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [i386-mingw32]
[ruby-core:81883]

Description

Positioning the cursor on Windows with the ANSI CSI n;m H sequence ("\e[n;mH") incorrectly moves the cursor relative to the console BUFFER, and not the actual console window as would be expected.

Doing print "\e[1;1H" should put the cursor in the top corner of the window, but instead it moves the cursor to the top of the internal DOS prompt buffer, and even moves the scrollbar to the top.

This is inconsistent with all other implementations of ANSI sequence processing on other platforms, and makes it hard to use simple cursor positioning sequences reliably on Windows.

The in-built IO.console.winsize does report the correct window size, which is good, but it's useless since the CSI H-sequence does not respect these size parameters.

Clear screen (CSI 2 J / "\e[2J") also clears everything, instead of just the visible portion. CSI 3 J seems to be reserved for full clearing (source), but CSI 2 J should only clear the visible portion.

To reproduce:

  1. Open a Windows command prompt with irb, where the buffer is larger than the window size (scrollbar visible)
  2. Run print "\e[1;1H"
Actions #1

Updated by caspercg (Casper G) over 6 years ago

  • Description updated (diff)

Updated by caspercg (Casper G) over 6 years ago

Actually in an empty console you need to run 1000.times { |i| puts "#{i}" }; print "\e[1;1H" to observe the effect properly.

Actions #3

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59254.


win32.c: cursor relative to screen

  • win32/win32.c (constat_apply): move relative to visible screen,
    not the entire buffer. [ruby-core:81883] [Bug #13707]

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

Note: cls command on Windows clears the entire buffer, unlike "clear screen" of VT100.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0