Skip to content

Commit

Permalink
Escape newline(s) in prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Dec 24, 2021
1 parent 20fcd22 commit b545459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def eof?
end

def reset_variables(prompt = '', encoding:)
@prompt = prompt
@prompt = prompt.gsub("\n", "\\n")
@mark_pointer = nil
@encoding = encoding
@is_multiline = false
Expand Down
13 changes: 13 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,19 @@ def test_clear_dialog_in_pasting
EOC
end

def test_prompt_with_newline
ENV['RELINE_TEST_PROMPT'] = "::\n> "
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\n 3\nend")
close
assert_screen(<<~'EOC')
Multiline REPL.
::\n> def hoge
::\n> 3
::\n> end
EOC
end

def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content
Expand Down

0 comments on commit b545459

Please sign in to comment.