Skip to content

Commit edf8d6b

Browse files
authored
Fix iogate.getc input byte order shuffled bug (#891)
When iogate.cursor_pos is called while handling signal inside iogate.getc, getc return bytes in wrong order. We need to always check `@buf` after `Reline.core.line_editor.handle_signal` is called.
1 parent 4167623 commit edf8d6b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

lib/reline/io/ansi.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ def with_raw_input
114114
end
115115

116116
def inner_getc(timeout_second)
117-
unless @buf.empty?
118-
return @buf.shift
119-
end
120-
until @input.wait_readable(0.01)
117+
while true
118+
# @buf may change while handling signal, so we need to check it in each loop iteration.
119+
return @buf.shift unless @buf.empty?
120+
break if @input.wait_readable(0.01)
121+
121122
timeout_second -= 0.01
122123
return nil if timeout_second <= 0
123124

125+
# handle_signal may call cursor_pos which modifies @buf
124126
Reline.core.line_editor.handle_signal
125127
end
126128
c = @input.getbyte

0 commit comments

Comments
 (0)