From 675b1d36260b3d5b5e68ffedd7a02481975e94a6 Mon Sep 17 00:00:00 2001 From: tompng Date: Fri, 27 Mar 2026 22:15:51 +0900 Subject: [PATCH] Fix iogate.getc input byte order shuffled bug 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. --- lib/reline/io/ansi.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb index 49068955d0..f2e9ecf56a 100644 --- a/lib/reline/io/ansi.rb +++ b/lib/reline/io/ansi.rb @@ -114,13 +114,15 @@ def with_raw_input end def inner_getc(timeout_second) - unless @buf.empty? - return @buf.shift - end - until @input.wait_readable(0.01) + while true + # @buf may change while handling signal, so we need to check it in each loop iteration. + return @buf.shift unless @buf.empty? + break if @input.wait_readable(0.01) + timeout_second -= 0.01 return nil if timeout_second <= 0 + # handle_signal may call cursor_pos which modifies @buf Reline.core.line_editor.handle_signal end c = @input.getbyte