[ruby/reline] Ensure no escape sequence before printing prompt
(https://github.com/ruby/reline/pull/716) https://github.com/ruby/reline/commit/f9227b5c89
This commit is contained in:
parent
5ea843f9b2
commit
932ecd3a1c
@ -242,7 +242,7 @@ class Reline::ANSI < Reline::IO
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cursor_pos
|
def cursor_pos
|
||||||
if @input.tty? && @output.tty?
|
if both_tty?
|
||||||
res = +''
|
res = +''
|
||||||
m = nil
|
m = nil
|
||||||
@input.raw do |stdin|
|
@input.raw do |stdin|
|
||||||
@ -276,6 +276,10 @@ class Reline::ANSI < Reline::IO
|
|||||||
Reline::CursorPos.new(column, row)
|
Reline::CursorPos.new(column, row)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def both_tty?
|
||||||
|
@input.tty? && @output.tty?
|
||||||
|
end
|
||||||
|
|
||||||
def move_cursor_column(x)
|
def move_cursor_column(x)
|
||||||
@output.write "\e[#{x + 1}G"
|
@output.write "\e[#{x + 1}G"
|
||||||
end
|
end
|
||||||
@ -343,14 +347,14 @@ class Reline::ANSI < Reline::IO
|
|||||||
|
|
||||||
def prep
|
def prep
|
||||||
# Enable bracketed paste
|
# 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
|
retrieve_keybuffer
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def deprep(otio)
|
def deprep(otio)
|
||||||
# Disable bracketed paste
|
# 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
|
Signal.trap('WINCH', @old_winch_handler) if @old_winch_handler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -378,6 +378,18 @@ class Reline::Test < Reline::TestCase
|
|||||||
assert_match(/#<Reline::Dumb/, out.chomp)
|
assert_match(/#<Reline::Dumb/, out.chomp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_print_prompt_before_everything_else
|
||||||
|
pend if win?
|
||||||
|
lib = File.expand_path("../../lib", __dir__)
|
||||||
|
code = "p Reline::IOGate.class; p Reline.readline 'prompt> '"
|
||||||
|
out = IO.popen([Reline.test_rubybin, "-I#{lib}", "-rreline", "-e", code], "r+") do |io|
|
||||||
|
io.write "abc\n"
|
||||||
|
io.close_write
|
||||||
|
io.read
|
||||||
|
end
|
||||||
|
assert_match(/\AReline::ANSI\nprompt> /, out)
|
||||||
|
end
|
||||||
|
|
||||||
def test_require_reline_should_not_trigger_winsize
|
def test_require_reline_should_not_trigger_winsize
|
||||||
pend if win?
|
pend if win?
|
||||||
lib = File.expand_path("../../lib", __dir__)
|
lib = File.expand_path("../../lib", __dir__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user