From 9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 8 Sep 2015 07:30:01 -0700 Subject: linenoise: expand tabs to spaces instead of ^I. * linenoise/linenoise.c (LINENOISE_MAX_LINE): Reduced to 1024. (LINENOISE_MAX_DISP): Now 8 times LINENOISE_MAX_LINE because the worst case is that the line contains only tabs, which expand to eight spaces. (sync_data_to_buf): Use character constants instead of hard coded values. Check for tab, and expand to spaces up to the next modulo 8 tab position. --- linenoise/linenoise.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 8436f278..0fcd89fb 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -56,8 +56,8 @@ #include "linenoise.h" #define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100 -#define LINENOISE_MAX_LINE 4096 -#define LINENOISE_MAX_DISP (LINENOISE_MAX_LINE * 2) +#define LINENOISE_MAX_LINE 1024 +#define LINENOISE_MAX_DISP (LINENOISE_MAX_LINE * 8) /* The lino_state structure represents the state during line editing. * We pass this state to functions implementing specific editing @@ -419,9 +419,15 @@ static void sync_data_to_buf(lino_t *l) if (*dptr) { char ch = *dptr++; - if (ch < 32) { + if (ch == TAB) { + int pos = bptr - l->buf; + do { + *bptr++ = ' '; + pos++; + } while (pos % 8 != 0); + } else if (ch < ' ') { *bptr++ = '^'; - *bptr++ = 64 + ch; + *bptr++ = '@' + ch; } else if (ch == 127) { *bptr++ = '^'; *bptr++ = '?'; -- cgit v1.2.3