From eaef60a582d88fc5ec08f6cc93ab25901fb8cfcb Mon Sep 17 00:00:00 2001 From: synqa Date: Sat, 24 Jan 2026 12:06:59 +0900 Subject: [PATCH] Fix password input handling on Linux The password input handling on Linux to match the behavior on Windows. It allows deleting characters using the Backspace, Delete, and Left arrow keys, and correctly handles other input sequences are handling correctly. --- src/Cedar/Console.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Cedar/Console.c b/src/Cedar/Console.c index 45bab426..b95d1930 100644 --- a/src/Cedar/Console.c +++ b/src/Cedar/Console.c @@ -1938,6 +1938,7 @@ bool PasswordPrompt(char *password, UINT size) c = _getch(); #else // OS_WIN32 c = getc(stdin); +PROCESS_CH: #endif // OS_WIN32 if (c >= 0x20 && c <= 0x7E) @@ -1952,6 +1953,7 @@ bool PasswordPrompt(char *password, UINT size) else if (c == 0x03) { // Break + RestoreConsole(console); exit(0); } else if (c == 0x04 || c == 0x1a || c == 0x0D || c==0x0A) @@ -1977,7 +1979,47 @@ bool PasswordPrompt(char *password, UINT size) goto BACKSPACE; } } - else if (c == 0x08) +#ifdef OS_UNIX // OS_UNIX + else if (c == 0x1B) + { + c = getc(stdin); + if (c != 0x5B && c != 0x4F) + { + // ESC key + goto PROCESS_CH; + } + + c = getc(stdin); + if (c == 0x44) + { + // Left arrow key + goto BACKSPACE; + } + else if (c == 0x33) + { + c = getc(stdin); + if (c == 0x7E) + { + // Delete key + goto BACKSPACE; + } + } + + // Drain remaining sequence bytes (most are <= 6) + for (int i = 0; i < 6; i++) + { + if (c >= 0x40 && c <= 0x7E) + { + // End of sequence + break; + } + c = getc(stdin); + } + + continue; + } +#endif // OS_UNIX + else if (c == 0x08 || c == 0x7F) { BACKSPACE: // Backspace