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 @@ def set_screen_size(rows, columns) end def cursor_pos - if @input.tty? && @output.tty? + if both_tty? res = +'' m = nil @input.raw do |stdin| @@ -276,6 +276,10 @@ def cursor_pos 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 @@ def set_winch_handler(&handler) 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 @@ def test_dumb_terminal assert_match(/# /, out) + end + def test_require_reline_should_not_trigger_winsize pend if win? lib = File.expand_path("../../lib", __dir__)