File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,20 @@ async def task(g=None, prompt="--> "):
119119
pt = t # save previous time
120120
t = time.ticks_ms()
121121
if c < 0x20 or c > 0x7E:
122-
if c == 0x0A:
123-
# LF
122+
if c == 0x0A or c == 0x0D:
123+
# LF or CR (handle both for raw terminal mode compatibility)
124124
if paste:
125+
# In paste mode, preserve the actual character
125126
sys.stdout.write(b)
126127
cmd += b
127128
continue
128-
# If the previous character was also LF, and was less
129-
# than 20 ms ago, this was likely due to CRLF->LFLF
130-
# conversion, so ignore this linefeed.
131-
if pc == 0x0A and time.ticks_diff(t, pt) < 20:
129+
# Handle various newline sequences to avoid double-execution:
130+
# - CR+LF (Windows style): ignore LF if it follows CR quickly
131+
# - LF+LF (PTY double-newline): ignore second LF if it follows quickly
132+
# - CR+CR (potential double-CR): ignore second CR if it follows quickly
133+
if ((c == 0x0A and pc == 0x0D) or # LF after CR (CRLF)
134+
(c == 0x0A and pc == 0x0A) or # LF after LF (double LF)
135+
(c == 0x0D and pc == 0x0D)) and time.ticks_diff(t, pt) < 20: # CR after CR
132136
continue
133137
if curs:
134138
# move cursor to end of the line

0 commit comments

Comments
 (0)