summaryrefslogtreecommitdiffstats
path: root/linenoise
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-23 06:23:47 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-23 06:23:47 -0700
commitf499f85402235dfea7346770761e5352985cb0cd (patch)
treeb4036f8def813138bda623ad0c5eff1d23a2f98f /linenoise
parent0642a9d229fd3e478c2aa0decea91b3a9bef2024 (diff)
downloadtxr-f499f85402235dfea7346770761e5352985cb0cd.tar.gz
txr-f499f85402235dfea7346770761e5352985cb0cd.tar.bz2
txr-f499f85402235dfea7346770761e5352985cb0cd.zip
linenoise: correct tab alignment in multi-line mode.
* linenoise/linenoise.c (sync_data_to_buf): Maintain a colum variable which is reset when a new line is put out and takes into account the prompt length; use this for tabs.
Diffstat (limited to 'linenoise')
-rw-r--r--linenoise/linenoise.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 1fb7e831..221b8487 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -742,10 +742,12 @@ static void ab_free(struct abuf *ab) {
static void sync_data_to_buf(lino_t *l)
{
char *dptr = l->data, *bptr = l->buf;
+ int col = strlen(l->prompt);
- if (l->mlmode)
+ if (l->mlmode) {
bptr += snprintf(l->buf, sizeof l->buf, "%s",
l->prompt);
+ }
while (bptr - l->buf < (ptrdiff_t) sizeof l->buf - 1) {
size_t dpos = dptr - l->data;
@@ -762,22 +764,25 @@ static void sync_data_to_buf(lino_t *l)
char ch = *dptr++;
if (ch == TAB) {
- int pos = bptr - l->buf;
do {
*bptr++ = ' ';
- pos++;
- } while (pos % 8 != 0);
+ col++;
+ } while (col % 8 != 0);
} else if (l->mlmode && ch == '\r') {
*bptr++ = '\r';
*bptr++ = '\n';
+ col = 0;
} else if (ch < ' ') {
*bptr++ = '^';
*bptr++ = '@' + ch;
+ col += 2;
} else if (ch == 127) {
*bptr++ = '^';
*bptr++ = '?';
+ col += 2;
} else {
*bptr++ = ch;
+ col++;
}
continue;