From 82c04c9ed586a0e89a344c5147796f35315ab3a7 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 7 Jun 2024 17:12:44 +0200 Subject: [PATCH] CLI/readline * there are still terminals out there sending \r as line terminator... --- includes/utilities.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/utilities.php b/includes/utilities.php index 872d8743..bab3d23f 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -394,9 +394,9 @@ abstract class CLI { $keyId = $ordinals[$idx]; - // ignore these ones - if ($keyId == self::CHR_TAB || $keyId == self::CHR_CR) - continue 2; + // skip char if horizontal tab or \r if followed by \n + if ($keyId == self::CHR_TAB || ($keyId == self::CHR_CR && ($ordinals[$i + 1] ?? '') == self::CHR_LF)) + continue; if ($keyId == self::CHR_BACKSPACE) { @@ -407,7 +407,8 @@ abstract class CLI if (!$isHidden && self::$hasReadline) echo chr(self::CHR_BACK)." ".chr(self::CHR_BACK); } - else if ($keyId == self::CHR_LF) + // standalone \n or \r + else if ($keyId == self::CHR_LF || $keyId == self::CHR_CR) { $fields[$name] = $charBuff; break 2;