diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-08 07:30:01 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-08 07:30:01 -0700 |
commit | 9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb (patch) | |
tree | 8b3b4b5377ae935b69c57543014f9b208160032c /linenoise/linenoise.c | |
parent | ab29ab49cc6f3a5227e0b961a8d2e91a42c44c54 (diff) | |
download | txr-9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb.tar.gz txr-9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb.tar.bz2 txr-9b2b5892cbcd6b78e3a96678581f0c8c24f7d6bb.zip |
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.
Diffstat (limited to 'linenoise/linenoise.c')
-rw-r--r-- | linenoise/linenoise.c | 14 |
1 files 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++ = '?'; |