1

When I run the following in either the Windows 10 Command Prompt or in Powershell

ruby -e 'puts "Hello world!\e[K\nWhats up?"'

I get the following:

  <!-- this line blank -->
Whats up?

What I expect is this:

Hello world!
Whats up?

What's going on? I am not really sure how to go about debugging this. I have isolated this to Windows and ruby because the same ruby command works as expected on Linux, and the following command on Command Prompt and Powershell also produces the correct output:

printf "Hello world!\\e[K\nWhats up?\n"

Some things:

  • \e[K is the Erase in Line (EL) ANSI character sequence. Without arguments it is supposed to clear the line from the cursor to the end.
  • Terminal sequences are supported on Windows 10, as verified by the printf command and this documentation. (This was not the case in earlier versions of Windows, that being the answer in numerous other, older, Stack Overflow posts.)
  • All other terminal sequences emitted by ruby seem to do the Right Thing™; this one seems to be clearing the entire line instead (no matter what arguments are passed in).
  • Ruby version: ruby 2.4.2p198 (2017-09-14 revision 59899) [x64-mingw32]
  • Windows version: Version 10.0.16299 Build 16299
  • Let me know if I should edit in any other information.
Alex Gittemeier
  • 5,224
  • 30
  • 55
  • [Report it as a bug.](https://bugs.ruby-lang.org/) It looks definitely like a MRI/CRuby bug [because it's processing these sequences on its own](https://github.com/ruby/ruby/blob/v2_5_1/win32/win32.c#L6775-L6795). This was added before Windows supported them. – cremno Apr 14 '18 at 12:51

1 Answers1

0

This behavior was caused by a bug in Ruby, which was patched in this commit.

Alex Gittemeier
  • 5,224
  • 30
  • 55