Skip to content

Commit

Permalink
Change to finish input with a newline when enter is pressed inside th…
Browse files Browse the repository at this point in the history
…e line
  • Loading branch information
piotrmurach committed Dec 23, 2020
1 parent cc38ead commit f7ce562
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tty/reader.rb
Expand Up @@ -287,7 +287,7 @@ def read_line(prompt = "", value: "", echo: true, raw: true, nonblock: false)
elsif console.keys[char] == :end
line.move_to_end
else
if raw && code == CARRIAGE_RETURN
if raw && [CARRIAGE_RETURN, NEWLINE].include?(code)
char = "\n"
line.move_to_end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/read_line_spec.rb
Expand Up @@ -85,6 +85,15 @@
expect(answer).to eq("acc\n")
end

it "finishes input with enter pressed inside the line" do
input << "aaa" << "\e[D" << "\e[D" << "\n"
input.rewind

answer = reader.read_line

expect(answer).to eq("aaa\n")
end

it "reads multibyte line" do
input << "한글"
input.rewind
Expand Down

0 comments on commit f7ce562

Please sign in to comment.