summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-12-24 20:06:48 +0900
committergit <svn-admin@ruby-lang.org>2021-12-25 00:32:57 +0900
commitb0db420b0e70753986d42579439acdd7ff0d9e95 (patch)
treed55f5934cac635dc01ac3297986575ac8954de0b
parent22cc2243f92ef09c10534412511a02ca8ccd45cb (diff)
[ruby/reline] Escape newline(s) in prompt
https://github.com/ruby/reline/commit/b545459fca
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb13
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index ff5d160e64..5968af708b 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -260,7 +260,7 @@ class Reline::LineEditor
end
def reset_variables(prompt = '', encoding:)
- @prompt = prompt
+ @prompt = prompt.gsub("\n", "\\n")
@mark_pointer = nil
@encoding = encoding
@is_multiline = false
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 0d1100f70c..8ddf95c1ba 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -1228,6 +1228,19 @@ begin
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