Skip to content

Commit 226461e

Browse files
committed
FIX: convert TAB in the terminal input to 4 spaces (posix)
1 parent cbad7a7 commit 226461e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/os/posix/host-readline.c

+28-6
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,35 @@ static struct termios Term_Attrs; // Initial settings, restored on exit
389389
**
390390
***********************************************************************/
391391
{
392+
int bytes;
392393
//printf("\r\nins pos: %d end: %d ==", term->pos, term->end);
393-
if (*cp < 32 && *cp != '\t') {
394-
// ignore not-printable characters except TAB
395-
Write_Char(BEL, 1); // bell
396-
return ++cp;
397-
}
398-
int bytes = 1 + trailingBytesForUTF8[*cp];
394+
395+
if(*cp == '\t') {
396+
// convert TAB to 4 spaces
397+
bytes = 4;
398+
*cp = ' ';
399+
if (term->end < TERM_BUF_LEN-bytes) {
400+
MOVE_MEM(
401+
term->buffer + term->pos + bytes,
402+
term->buffer + term->pos,
403+
bytes + term->end - term->pos
404+
);
405+
}
406+
do {
407+
WRITE_CHAR(cp);
408+
term->buffer[term->pos] = ' ';
409+
term->end++;
410+
term->pos++;
411+
} while (--bytes > 0);
412+
return ++cp;
413+
}
414+
else if (*cp < 32) {
415+
// ignore not-printable characters except TAB
416+
Write_Char(BEL, 1); // bell
417+
return ++cp;
418+
}
419+
420+
bytes = 1 + trailingBytesForUTF8[*cp];
399421
if (term->end < TERM_BUF_LEN-bytes) { // avoid buffer overrun
400422

401423
if (term->pos < term->end) { // open space for it:

0 commit comments

Comments
 (0)