Skip to content

Commit 70212fa

Browse files
authored
Use Relin::ANSI's buffer instead of calling STDIN.ungetc (#815)
1 parent 7bb1e88 commit 70212fa

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/reline/io/ansi.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def set_screen_size(rows, columns)
205205
break
206206
end
207207
end
208-
buf.chars.reverse_each do |ch|
209-
stdin.ungetc ch
210-
end
208+
@buf.concat buf.bytes
211209
end
212210
[match[:column].to_i - 1, match[:row].to_i - 1] if match
213211
end

test/reline/test_reline.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def test_tty_amibuous_width
442442
ruby_file.write(<<~RUBY)
443443
require 'reline'
444444
Thread.new { sleep 2; puts 'timeout'; exit }
445-
p [Reline.ambiguous_width, gets.chomp]
445+
line = Reline.readline('>')
446+
p [Reline.ambiguous_width, line]
446447
RUBY
447448
ruby_file.close
448449
lib = File.expand_path('../../lib', __dir__)
@@ -452,8 +453,8 @@ def test_tty_amibuous_width
452453
[1, 2].each do |ambiguous_width|
453454
PTY.spawn(*cmd) do |r, w, pid|
454455
loop { break if r.readpartial(1024).include?("\e[6n") }
455-
w.puts "hello\e[10;#{ambiguous_width + 1}Rworld"
456-
assert_include(r.gets, [ambiguous_width, 'helloworld'].inspect)
456+
w.puts "hello\e[10;#{ambiguous_width + 1}Rworld\n"
457+
assert_include(r.gets + r.gets, [ambiguous_width, 'helloworld'].inspect)
457458
ensure
458459
r.close
459460
w.close
@@ -464,8 +465,8 @@ def test_tty_amibuous_width
464465
# Ambiguous width = 1 when cursor pos timed out
465466
PTY.spawn(*cmd) do |r, w, pid|
466467
loop { break if r.readpartial(1024).include?("\e[6n") }
467-
w.puts "hello\e[10;2Sworld"
468-
assert_include(r.gets, [1, "hello\e[10;2Sworld"].inspect)
468+
w.puts "helloworld\n"
469+
assert_include(r.gets + r.gets, [1, "helloworld"].inspect)
469470
ensure
470471
r.close
471472
w.close

0 commit comments

Comments
 (0)