Allow to backspace with 'Delete' (and some optimization)

This commit is contained in:
Oliver
2025-11-02 19:59:34 +01:00
committed by Oliver Schmidt
parent 778bc5bc22
commit 759884ddd4

View File

@@ -38,7 +38,7 @@ char* __fastcall__ cgets (char* buffer, int size)
/* Actually just the last column! */ /* Actually just the last column! */
--w; --w;
cursor (1); cursor (1);
for (buffer[i] = '\0', --size; i < size; ) { for (--size; i < size; ) {
c = cgetc (); c = cgetc ();
/* Handle CR/LF */ /* Handle CR/LF */
if (strchr (CRLF, c)) { if (strchr (CRLF, c)) {
@@ -47,10 +47,14 @@ char* __fastcall__ cgets (char* buffer, int size)
break; break;
} }
/* Handle backspace */ /* Handle backspace */
if (c == '\b') { if (c == '\b'
#ifdef CH_DEL
|| c == CH_DEL
#endif
) {
if (i > 0) { if (i > 0) {
/* Remove the character */ /* Remove the character */
buffer[--i] = '\0'; --i;
/* Logic to account for line wrapping */ /* Logic to account for line wrapping */
y = wherey (); y = wherey ();
x = wherex (); x = wherex ();
@@ -64,11 +68,11 @@ char* __fastcall__ cgets (char* buffer, int size)
/* Handle regular characters */ /* Handle regular characters */
} else if (isprint (c)) { } else if (isprint (c)) {
cputc (c); cputc (c);
buffer[i] = c; buffer[i++] = c;
buffer[++i] = '\0';
} }
} }
cursor (0); cursor (0);
buffer[i] = '\0';
} }
/* Done */ /* Done */