Backport #5023

irb does not like window resizes

Added by Michael Schnupp about 4 years ago. Updated over 2 years ago.

[ruby-core:38041]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA

Description

  • open irb
  • type until line wraps to the next line
  • increase the width of the terminal
  • notice that the text of in the second line will not come up to the first line. -> there is no more useful display/navigation in long lines unless window is resized to exactly the same width. :(

My irb uses libreadline. (Readline module is visible and config in ~/.inputrc is applied.)
Other readline applications like bash do not have that problem.
irb in 1.8 works fine, too.
all versions of 1.9 (including head) have the described problem.
(I tested mainly on my ubuntu box.)


Related issues

Related to Ruby trunk - Bug #5423: readlineの入力待機中に端末のウィンドウサイズ変更すると入力内容が乱れる Closed 10/08/2011

Associated revisions

Revision 39377
Added by Usaku NAKAMURA over 2 years ago

merge revision(s) 36130: [Backport #5023]

* ext/readline/readline.c (Init_readline): don't set 0 to
  rl_catch_signals and rl_catch_sigwinch. [Bug #5423]

History

#1 Updated by Yui NARUSE about 4 years ago

  • Assignee set to Keiju Ishitsuka
  • Target version set to 2.0.0
  • Status changed from Open to Assigned

#2 Updated by Ralf Kistner over 3 years ago

This is solved by using Readline.set_screen_size(lines, columns) to the correct size, every time the size has changed.

The only reliable way I've found to get the terminal size (on Ubuntu) is with the 'ruby-terminfo' gem: https://github.com/genki/ruby-terminfo

require 'terminfo'
Readline.set_screen_size(TermInfo.screen_size[0], TermInfo.screen_size[1])

Calling the above two lines before each readline() solved the issue for me.
Instead of polling for the terminal size, we could instead trap the SIGWINCH signal:

require 'terminfo'
Signal.trap('SIGWINCH', proc { Readline.set_screen_size(TermInfo.screen_size[0], TermInfo.screen_size[1]) })

Also see my answer on this stackoverflow post: http://stackoverflow.com/a/10444128/214837

#3 Updated by Zachary Scott over 2 years ago

Using 1.9.3-p372 I was able to reproduce this issue, but unable to reproduce in 2.0.0-dev.

#4 Updated by Zachary Scott over 2 years ago

I think we just need to backport to 1.9.3 branch, but I'm not sure what to backport.

#5 Updated by Keiju Ishitsuka over 2 years ago

zzak (Zachary Scott) wrote:

I think we just need to backport to 1.9.3 branch, but I'm not sure what to backport.

I have identified a commit which solve this problem.
The commit is revision 36130.

I think the following is applied only:

--- ext/readline/readline.c (revision 38896)
+++ ext/readline/readline.c (working copy)
@@ -1679,9 +1679,7 @@
#ifdef HAVE_RL_CATCH_SIGNALS
rl_catch_signals = 0;
#endif
-#ifdef HAVE_RL_CATCH_SIGWINCH
- rl_catch_sigwinch = 0;
-#endif
+
#ifdef HAVE_RL_CLEAR_SIGNALS
rl_clear_signals();
#endif

#6 Updated by Zachary Scott over 2 years ago

Thank you Keiju-san!

Will you please open a backport request for usa?

#7 Updated by Keiju Ishitsuka over 2 years ago

  • Target version changed from 2.0.0 to 1.9.3
  • Assignee changed from Keiju Ishitsuka to Usaku NAKAMURA

zzak (Zachary Scott) wrote:

Thank you Keiju-san!

Will you please open a backport request for usa?

OK.

Usa-san, yoroshiku.

#8 Updated by Usaku NAKAMURA over 2 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport193
  • Target version deleted (1.9.3)

#9 Updated by Usaku NAKAMURA over 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39377.
Michael, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 36130: [Backport #5023]

* ext/readline/readline.c (Init_readline): don't set 0 to
  rl_catch_signals and rl_catch_sigwinch. [Bug #5423]

Also available in: Atom PDF