Ruby IRB (REPL) screen wrap around to first line when hitting bottom of screen #16538

Closed
opened 2026-01-31 05:15:03 +00:00 by claunia · 23 comments
Owner

Originally created by @eabase on GitHub (Jan 28, 2022).

Windows Terminal version

  1. 11.3471.0

Windows build number

10.0.19042.0

Other Software

ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt]
irb 1.4.1 (2021-12-25)

Steps to reproduce

Run irb.bat

Keep hitting return until you get past end of last line in terminal.
Prompt then starts overwriting previous text on top of the screen.

Expected Behavior

that screen scroll down normally

Actual Behavior

wraps to top of screen and overwrite what was there before.

Does not happen in Powershell (pwsh)!

Originally created by @eabase on GitHub (Jan 28, 2022). ### Windows Terminal version 1. 11.3471.0 ### Windows build number 10.0.19042.0 ### Other Software ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x64-mingw-ucrt] irb 1.4.1 (2021-12-25) ### Steps to reproduce # Run irb.bat Keep hitting return until you get past end of last line in terminal. Prompt then starts overwriting previous text on top of the screen. ### Expected Behavior that screen scroll down normally ### Actual Behavior wraps to top of screen and overwrite what was there before. **Does not happen in Powershell (pwsh)!**
claunia added the Needs-TriageResolution-ExternalNeeds-Tag-Fix labels 2026-01-31 05:15:04 +00:00
Author
Owner

@eabase commented on GitHub (Jan 28, 2022):

Possibly relevant terminal settings:

-----------------------------------------------------------------------
  PowerShell Version    : 7.2.1
  OS Name               : Microsoft Windows 10 Home (64-bit)
  OS Version            : 10.0.19042  [2021-06-28 07:45:15 PM]
  OS BuildLabEx         : 19041.1
  OS HAL                : 10.0.19041.1151
  OS Kernel             : 10.0.19041.1466
  OS UBR                : 1466
  -------------------------------------------------------
  ExecutionPolicy:
      MachinePolicy     : Undefined
      UserPolicy        : Undefined
      Process           : Undefined
      CurrentUser       : Bypass
      LocalMachine      : RemoteSigned
  Firewall:
      Status            : OK
  Console Settings:
      Type              : ConsoleHost
      OutputEncoding    : Unicode (UTF-8)
      Color Capability  : TRUECOLOR
      Registry VT Level : 1
      CodePage (input)  : 65001
      CodePage (output) : 65001
      ConInMode         : 0x1f7
      ConOutMode        : 0x7
      Buffer Size (W H) : 160 50
      PSReadLine version: 2.2.0-beta5

@eabase commented on GitHub (Jan 28, 2022): Possibly relevant terminal settings: ``` ----------------------------------------------------------------------- PowerShell Version : 7.2.1 OS Name : Microsoft Windows 10 Home (64-bit) OS Version : 10.0.19042 [2021-06-28 07:45:15 PM] OS BuildLabEx : 19041.1 OS HAL : 10.0.19041.1151 OS Kernel : 10.0.19041.1466 OS UBR : 1466 ------------------------------------------------------- ExecutionPolicy: MachinePolicy : Undefined UserPolicy : Undefined Process : Undefined CurrentUser : Bypass LocalMachine : RemoteSigned Firewall: Status : OK Console Settings: Type : ConsoleHost OutputEncoding : Unicode (UTF-8) Color Capability : TRUECOLOR Registry VT Level : 1 CodePage (input) : 65001 CodePage (output) : 65001 ConInMode : 0x1f7 ConOutMode : 0x7 Buffer Size (W H) : 160 50 PSReadLine version: 2.2.0-beta5 ```
Author
Owner

@elsaco commented on GitHub (Jan 30, 2022):

@eabase for comparison only, when using a WSL distro (ArchLinux in this case) irb works as expected in wt:

irb_wsl_test

@elsaco commented on GitHub (Jan 30, 2022): @eabase for comparison only, when using a WSL distro (ArchLinux in this case) `irb` works as expected in `wt`: ![irb_wsl_test](https://user-images.githubusercontent.com/3933920/151709366-381eceae-9ecc-44b4-917d-11a17ae9c2c3.png)
Author
Owner

@eabase commented on GitHub (Jan 30, 2022):

@elsaco
First of all it seem you're not running ruby with the windows version, but the apt package under your archlinux. Second, I am reporting the problem for powershell and the windows version. So I have no idea what purpose your comparison serves.

@eabase commented on GitHub (Jan 30, 2022): @elsaco First of all it seem you're not running ruby with the windows version, but the apt package under your archlinux. Second, I am reporting the problem for powershell and the windows version. So I have no idea what purpose your comparison serves.
Author
Owner

@eabase commented on GitHub (Jan 30, 2022):

Same problem, with running (same) Windows version of Ruby under WSL.
(To do that you need to copy the ruby script embedded in the irb file into rirb.rb.)

cat rirb.rb:

#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'irb' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

Gem.use_gemdeps

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('irb', 'irb', version)
else
gem "irb", version
load Gem.bin_path("irb", "irb", version)
end

Now you can run it with: ruby.exe -x rirb.rb.

Same problem!

@eabase commented on GitHub (Jan 30, 2022): Same problem, with running (same) Windows version of Ruby under WSL. (To do that you need to copy the ruby script embedded in the `irb` file into `rirb.rb`.) `cat rirb.rb`: ```runy #!/usr/bin/env ruby # # This file was generated by RubyGems. # # The application 'irb' is installed as part of a gem, and # this file is here to facilitate running it. # require 'rubygems' Gem.use_gemdeps version = ">= 0.a" str = ARGV.first if str str = str.b[/\A_(.*)_\z/, 1] if str and Gem::Version.correct?(str) version = str ARGV.shift end end if Gem.respond_to?(:activate_bin_path) load Gem.activate_bin_path('irb', 'irb', version) else gem "irb", version load Gem.bin_path("irb", "irb", version) end ``` Now you can run it with: `ruby.exe -x rirb.rb`. Same problem!
Author
Owner

@elsaco commented on GitHub (Jan 31, 2022):

Here is some debug output with Windows irb. Notice prompt 24:

wt_irb_debug1

wt_irb_debug2

@elsaco commented on GitHub (Jan 31, 2022): Here is some debug output with Windows `irb`. Notice prompt 24: ![wt_irb_debug1](https://user-images.githubusercontent.com/3933920/151724061-d9039186-c1a0-4ba3-b356-ff24f8aa34e1.PNG) ![wt_irb_debug2](https://user-images.githubusercontent.com/3933920/151724074-28a004e5-01fd-4686-b951-c6bd37ff8989.png)
Author
Owner

@j4james commented on GitHub (Jan 31, 2022):

Can you reproduce this in conhost? I'd suggest testing with the screen buffer height set to match the window height, because that could be a factor.

@j4james commented on GitHub (Jan 31, 2022): Can you reproduce this in conhost? I'd suggest testing with the screen buffer height set to match the window height, because that could be a factor.
Author
Owner

@eabase commented on GitHub (Jan 31, 2022):

@elsaco
How did you generate that ANSI ESC debug output?

@j4james
Who are you talking to?
WT has the buffer set by default to whatever the size of the windows is.
IDK, where to change this in WT, and is related to:

There you will find some historical context of the buffer issue.

@eabase commented on GitHub (Jan 31, 2022): @elsaco How did you generate that ANSI ESC debug output? @j4james Who are you talking to? WT has the buffer set by default to whatever the size of the windows is. IDK, where to change this in WT, and is related to: * https://github.com/PowerShell/PowerShell/issues/16732 There you will find some historical context of the buffer issue.
Author
Owner

@zadjii-msft commented on GitHub (Jan 31, 2022):

@j4james is talking to you (@eabase) I'd reckon, it's the same question I'd ask. Set the buffer size to the same thing as window size, and see if this repros:
image

@zadjii-msft commented on GitHub (Jan 31, 2022): @j4james is talking to you (@eabase) I'd reckon, it's the same question I'd ask. Set the buffer size to the same thing as window size, and see if this repros: ![image](https://user-images.githubusercontent.com/18356694/151795579-d9ea3873-244f-418a-9184-3eca5f7c8ed7.png)
Author
Owner

@eabase commented on GitHub (Jan 31, 2022):

@zadjii-msft
Hi Mike,
Now I feel like complete idiot, as I am not able to find those settings for WT!

  • (a) I don't have those properties for conhost.exe under System32.
  • (b) clicking on props for the exe's under:
    C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.11.3471.0_x64__8wekyb3d8bbwe
    also doesn't have those props.

Please explain where you hid them?
(For pwsh, you just right click on the top bar...)

@eabase commented on GitHub (Jan 31, 2022): @zadjii-msft Hi Mike, Now I feel like complete idiot, as I am not able to find those settings for WT! - (a) I don't have those properties for conhost.exe under System32. - (b) clicking on props for the exe's under: `C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.11.3471.0_x64__8wekyb3d8bbwe` also doesn't have those props. Please explain where you hid them? (For pwsh, you just right click on the top bar...)
Author
Owner

@zadjii-msft commented on GitHub (Jan 31, 2022):

I'm sorry, maybe I'm miscommunicating. I was hoping you could:

  1. Open a new console window (pwsh, powershell.exe, doesn't matter, either will open conhost.exe, the vintage console)
  2. Use the console property sheet (in the titlebar under Properties, as you've noted) to set the window size equal to the screen buffer size
  3. run irb in that window and see if the issue happens.

Like you've noted, the Terminal's backing buffer size is always the same as the window size. I suspect there's a bug in irb that happens when the prompt reaches the bottom of the screen buffer. By doing the above steps, we can check if that theory holds for the vintage console host, without even involving the Terminal.

@zadjii-msft commented on GitHub (Jan 31, 2022): I'm sorry, maybe I'm miscommunicating. I was hoping you could: 1. Open a new console window (`pwsh`, `powershell.exe`, doesn't matter, either will open `conhost.exe`, the vintage console) 2. Use the console property sheet (in the titlebar under Properties, as you've noted) to set the window size equal to the screen buffer size 3. run `irb` in that window and see if the issue happens. Like you've noted, the Terminal's backing buffer size is always the same as the window size. I suspect there's a bug in `irb` that happens when the prompt reaches the bottom of the screen buffer. By doing the above steps, we can check if that theory holds for the vintage console host, without even involving the Terminal.
Author
Owner

@elsaco commented on GitHub (Jan 31, 2022):

Using same window/buffer size the issue reproduces, still:

conhost_buffer_size

wt_irb_conhost

@elsaco commented on GitHub (Jan 31, 2022): Using same window/buffer size the issue reproduces, still: ![conhost_buffer_size](https://user-images.githubusercontent.com/3933920/151811269-88d216af-b09c-4f3d-a792-ec318fcad309.png) ![wt_irb_conhost](https://user-images.githubusercontent.com/3933920/151811283-53063af5-81a1-4e6b-a321-bb75abeb3c77.png)
Author
Owner

@eabase commented on GitHub (Jan 31, 2022):

@zadjii-msft
Yep, surely changing from 9001 to 60 for the buffer in pwsh, also causes this issue.

@eabase commented on GitHub (Jan 31, 2022): @zadjii-msft Yep, surely changing from 9001 to 60 for the buffer in pwsh, also causes this issue.
Author
Owner

@zadjii-msft commented on GitHub (Jan 31, 2022):

Great, just as I suspected. Thats a totally valid configuration for the console window to be in, so I think this should be moved upstream to wherever irb tracks their bugs (https://github.com/ruby/irb looks like the place, doesn't look like they're already tracking this from a cursory glance). Basically, it seems like they've got some code taht tries to account for being at the bottom of the text buffer (or, possibly just breaks at the bottom of the buffer). They should probably fix that.

@zadjii-msft commented on GitHub (Jan 31, 2022): Great, just as I suspected. Thats a totally valid configuration for the console window to be in, so I think this should be moved upstream to wherever irb tracks their bugs (https://github.com/ruby/irb looks like the place, doesn't look like they're already tracking this from a cursory glance). Basically, it seems like they've got some code taht tries to account for being at the bottom of the text buffer (or, possibly just breaks at the bottom of the buffer). They should probably fix that.
Author
Owner

@eabase commented on GitHub (Jan 31, 2022):

@elsaco
How can I get that debug output? Seem to be a very useful tool!

@eabase commented on GitHub (Jan 31, 2022): @elsaco How can I get that debug output? Seem to be a very useful tool!
Author
Owner

@elsaco commented on GitHub (Jan 31, 2022):

@eabase open settings.json and add "debugFeatures": true action. Then press left-alt and right-alt at the same time while opening a new tab.

@elsaco commented on GitHub (Jan 31, 2022): @eabase open `settings.json` and add `"debugFeatures": true` action. Then press `left-alt` and `right-alt` at the same time while opening a new tab.
Author
Owner

@eabase commented on GitHub (Jan 31, 2022):

Then press left-alt and right-alt at the same time while opening a new tab.

I only have 2 hands! LoL, Who thought of that nearly impossible combo?

@eabase commented on GitHub (Jan 31, 2022): > Then press left-alt and right-alt at the same time while opening a new tab. I only have 2 hands! LoL, Who thought of that nearly impossible combo?
Author
Owner

@zadjii-msft commented on GitHub (Jan 31, 2022):

It's a debugging feature, it's intentionally hard to activate 😉

@zadjii-msft commented on GitHub (Jan 31, 2022): It's a debugging feature, it's intentionally hard to activate 😉
Author
Owner

@eabase commented on GitHub (Feb 1, 2022):

  • What is the sequence in red doing?
    \e[13;28;13;1;0;1_\e[13;28;13;0;0;1_
    (I can't find any documentation of this ESC sequence.)

Also, the debug tool is great, but could certainly be improved if you could add an option to actually do a \n when that character is received. So that it would look like:

blah blahblah   blah
[C/R] blah blah

I suggest the option to be called: debugFeature_Show_NL: true.
Now filed feature suggestion:


UPDATE
For reference:

^[ [ Vk ; Sc ; Uc ; Kd ; Cs ; Rc _

where:

Vk: the value of wVirtualKeyCode    - any number. If omitted, defaults to '0'.
Sc: the value of wVirtualScanCode   - any number. If omitted, defaults to '0'.
Uc: the decimal value of UnicodeChar. For example: 
    NUL is "0", LF is "10", the character 'A' is "65". - If omitted, defaults to '0'.
Kd: the value of bKeyDown           - either a '0' or '1'. If omitted, defaults to '0'.
Cs: the value of dwControlKeyState  - any number. If omitted, defaults to '0'.
Rc: the value of wRepeatCount       - any number. If omitted, defaults to '1'.
@eabase commented on GitHub (Feb 1, 2022): * What is the sequence in red doing? `\e[13;28;13;1;0;1_\e[13;28;13;0;0;1_` (I can't find any documentation of this ESC sequence.) Also, the debug tool is great, but could certainly be improved if you could add an option to actually do a `\n` when that character is received. So that it would look like: ``` blah blahblah blah [C/R] blah blah ``` I suggest the option to be called: `debugFeature_Show_NL: true`. Now filed feature suggestion: * #12312 --- **UPDATE** For [reference](https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md): ``` ^[ [ Vk ; Sc ; Uc ; Kd ; Cs ; Rc _ ``` where: ``` Vk: the value of wVirtualKeyCode - any number. If omitted, defaults to '0'. Sc: the value of wVirtualScanCode - any number. If omitted, defaults to '0'. Uc: the decimal value of UnicodeChar. For example: NUL is "0", LF is "10", the character 'A' is "65". - If omitted, defaults to '0'. Kd: the value of bKeyDown - either a '0' or '1'. If omitted, defaults to '0'. Cs: the value of dwControlKeyState - any number. If omitted, defaults to '0'. Rc: the value of wRepeatCount - any number. If omitted, defaults to '1'. ```
Author
Owner

@zadjii-msft commented on GitHub (Feb 1, 2022):

Everything in red is input. That's our custom win32-input-mode, which I have documented in #4999 et. al. We need that for keypresses and releases that aren't otherwise encodable in other VT sequences.

@zadjii-msft commented on GitHub (Feb 1, 2022): Everything in red is _input_. That's our custom `win32-input-mode`, which I have documented in #4999 et. al. We need that for keypresses and releases that aren't otherwise encodable in other VT sequences.
Author
Owner

@YO4 commented on GitHub (Feb 4, 2022):

Cursor jump is reline (ruby's line input library) issue.
Reline bundled with ruby 3.1.0 contains wrong code that misidentifies the cursor position that causes cursor jump when scrolling. That has been fixed in reline 0.3.1.

That bug introduced when converting CSI S to \n for scrollback past lines on Windows Terminal.

@YO4 commented on GitHub (Feb 4, 2022): Cursor jump is reline (ruby's line input library) issue. Reline bundled with ruby 3.1.0 contains wrong code that misidentifies the cursor position that causes cursor jump when scrolling. That has been fixed in reline 0.3.1. That bug introduced when converting CSI S to \n for scrollback past lines on Windows Terminal.
Author
Owner

@eabase commented on GitHub (Feb 4, 2022):

@YO4

Where do I find reline (for Ruby)?
Can you link to the fix please?

@eabase commented on GitHub (Feb 4, 2022): @YO4 Where do I find `reline` (for Ruby)? Can you link to the fix please?
Author
Owner

@elsaco commented on GitHub (Feb 4, 2022):

@eabase it's a gem:

[tux@RIPPER ~]$ gem info reline

*** LOCAL GEMS ***

reline (0.3.1, 0.2.5)
    Author: aycabta
    Homepage: https://github.com/ruby/reline
    License: Ruby
    Installed at (0.3.1): /usr/lib/ruby/gems/3.0.0
                 (0.2.5, default): /usr/lib/ruby/gems/3.0.0

    Alternative GNU Readline or Editline implementation by pure Ruby.

More info at https://rubygems.org/gems/reline

@elsaco commented on GitHub (Feb 4, 2022): @eabase it's a `gem`: ``` [tux@RIPPER ~]$ gem info reline *** LOCAL GEMS *** reline (0.3.1, 0.2.5) Author: aycabta Homepage: https://github.com/ruby/reline License: Ruby Installed at (0.3.1): /usr/lib/ruby/gems/3.0.0 (0.2.5, default): /usr/lib/ruby/gems/3.0.0 Alternative GNU Readline or Editline implementation by pure Ruby. ``` More info at https://rubygems.org/gems/reline
Author
Owner

@Surya-Prakasam-Siva commented on GitHub (Jan 31, 2025):

Solved this irb screen wrap issue by updating irb gem in ruby.
gem update irb

@Surya-Prakasam-Siva commented on GitHub (Jan 31, 2025): Solved this irb screen wrap issue by updating irb gem in ruby. `gem update irb`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16538