From 56e1e89ff4cd19f037b7069e67350c9b6fcfe4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=93=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D1=88=D0=BA=D0=BE?= Date: Wed, 22 Nov 2023 18:01:36 +0300 Subject: [PATCH] add dump mode functions --- components/linenoise-async/linenoise-async.c | 38 ++++++-------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/components/linenoise-async/linenoise-async.c b/components/linenoise-async/linenoise-async.c index 6588e85..7a859ab 100644 --- a/components/linenoise-async/linenoise-async.c +++ b/components/linenoise-async/linenoise-async.c @@ -137,6 +137,7 @@ static void refreshLineWithFlags(struct linenoiseState *l, int flags); static int maskmode = 0; /* Show "***" instead of input. For passwords. */ static int rawmode = 0; /* For atexit() function to check if restore is needed*/ static int mlmode = 0; /* Multi line mode. Default is single line. */ +static int dumbmode = 0; /* Dumb mode where line editing is disabled. Off by default */ static int atexit_registered = 0; /* Register atexit just 1 time. */ static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN; static int history_len = 0; @@ -171,25 +172,6 @@ int linenoiseHistoryAdd(const char *line); #define REFRESH_ALL (REFRESH_CLEAN|REFRESH_WRITE) // Do both. static void refreshLine(struct linenoiseState *l); -/* Debugging macro. */ -#if 0 -FILE *lndebug_fp = NULL; -#define lndebug(...) \ - do { \ - if (lndebug_fp == NULL) { \ - lndebug_fp = fopen("/tmp/lndebug.txt","a"); \ - fprintf(lndebug_fp, \ - "[%d %d %d] p: %d, rows: %d, rpos: %d, max: %d, oldmax: %d\n", \ - (int)l->len,(int)l->pos,(int)l->oldpos,plen,rows,rpos, \ - (int)l->oldrows,old_rows); \ - } \ - fprintf(lndebug_fp, ", " __VA_ARGS__); \ - fflush(lndebug_fp); \ - } while (0) -#else -#define lndebug(fmt, ...) -#endif - /* ======================= Low level terminal handling ====================== */ /* Enable "mask mode". When it is enabled, instead of the input that @@ -210,6 +192,16 @@ void linenoiseSetMultiLine(int ml) { mlmode = ml; } +/* Set if terminal does not recognize escape sequences */ +void linenoiseSetDumbMode(int set) { + dumbmode = set; +} + +/* Returns whether the current mode is dumbmode or not. */ +bool linenoiseIsDumbMode(void) { + return dumbmode; +} + /* Return true if the terminal name is in the list of terminals we know are * not able to understand basic escape sequences. */ static int isUnsupportedTerm(void) { @@ -672,14 +664,12 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) { if (flags & REFRESH_CLEAN) { if (old_rows-rpos > 0) { - lndebug("go down %d", old_rows-rpos); snprintf(seq,64,"\x1b[%dB", old_rows-rpos); abAppend(&ab,seq,strlen(seq)); } /* Now for every row clear it, go up. */ for (j = 0; j < old_rows-1; j++) { - lndebug("clear+up"); snprintf(seq,64,"\r\x1b[0K\x1b[1A"); abAppend(&ab,seq,strlen(seq)); } @@ -687,7 +677,6 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) { if (flags & REFRESH_ALL) { /* Clean the top line. */ - lndebug("clear"); snprintf(seq,64,"\r\x1b[0K"); abAppend(&ab,seq,strlen(seq)); } @@ -711,7 +700,6 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) { l->pos == l->len && (l->pos+plen) % l->cols == 0) { - lndebug(""); abAppend(&ab,"\n",1); snprintf(seq,64,"\r"); abAppend(&ab,seq,strlen(seq)); @@ -721,18 +709,15 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) { /* Move cursor to right position. */ rpos2 = (plen+l->pos+l->cols)/l->cols; /* Current cursor relative row */ - lndebug("rpos2 %d", rpos2); /* Go up till we reach the expected positon. */ if (rows-rpos2 > 0) { - lndebug("go-up %d", rows-rpos2); snprintf(seq,64,"\x1b[%dA", rows-rpos2); abAppend(&ab,seq,strlen(seq)); } /* Set column. */ col = (plen+(int)l->pos) % (int)l->cols; - lndebug("set col %d", 1+col); if (col) snprintf(seq,64,"\r\x1b[%dC", col); else @@ -740,7 +725,6 @@ static void refreshMultiLine(struct linenoiseState *l, int flags) { abAppend(&ab,seq,strlen(seq)); } - lndebug("\n"); l->oldpos = l->pos; if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */