From 932ecd3a1c8a2c5094406063903866499176529e Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Wed, 5 Jun 2024 03:34:57 +0900 Subject: [PATCH] [ruby/reline] Ensure no escape sequence before printing prompt (https://github.com/ruby/reline/pull/716) https://github.com/ruby/reline/commit/f9227b5c89 --- lib/reline/io/ansi.rb | 10 +++++++--- test/reline/test_reline.rb | 12 ++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb index aa8ff256e2..2b5a5c5786 100644 --- a/lib/reline/io/ansi.rb +++ b/lib/reline/io/ansi.rb @@ -242,7 +242,7 @@ class Reline::ANSI < Reline::IO end def cursor_pos - if @input.tty? && @output.tty? + if both_tty? res = +'' m = nil @input.raw do |stdin| @@ -276,6 +276,10 @@ class Reline::ANSI < Reline::IO Reline::CursorPos.new(column, row) end + def both_tty? + @input.tty? && @output.tty? + end + def move_cursor_column(x) @output.write "\e[#{x + 1}G" end @@ -343,14 +347,14 @@ class Reline::ANSI < Reline::IO def prep # Enable bracketed paste - @output.write "\e[?2004h" if Reline.core.config.enable_bracketed_paste + @output.write "\e[?2004h" if Reline.core.config.enable_bracketed_paste && both_tty? retrieve_keybuffer nil end def deprep(otio) # Disable bracketed paste - @output.write "\e[?2004l" if Reline.core.config.enable_bracketed_paste + @output.write "\e[?2004l" if Reline.core.config.enable_bracketed_paste && both_tty? Signal.trap('WINCH', @old_winch_handler) if @old_winch_handler end end diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb index deff411232..601e484048 100644 --- a/test/reline/test_reline.rb +++ b/test/reline/test_reline.rb @@ -378,6 +378,18 @@ class Reline::Test < Reline::TestCase assert_match(/# /, out) + end + def test_require_reline_should_not_trigger_winsize pend if win? lib = File.expand_path("../../lib", __dir__)