Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
linenoise update to the latest version keep our local changes
Baptiste Daroussin committed 3 years ago
commit 8160d689a03d192131a68031c3fc44d54cb5155b
parent 7713640
2 files changed +29 -3
modified external/linenoise/linenoise.c
@@ -125,6 +125,7 @@ static linenoiseHintsCallback *hintsCallback = NULL;
static linenoiseFreeHintsCallback *freeHintsCallback = NULL;

static struct termios orig_termios; /* In order to restore at exit.*/
+
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 atexit_registered = 0; /* Register atexit just 1 time. */
@@ -197,6 +198,19 @@ FILE *lndebug_fp = NULL;

/* ======================= Low level terminal handling ====================== */

+
/* Enable "mask mode". When it is enabled, instead of the input that
+
 * the user is typing, the terminal will just display a corresponding
+
 * number of asterisks, like "****". This is useful for passwords and other
+
 * secrets that should not be displayed. */
+
void linenoiseMaskModeEnable(void) {
+
    maskmode = 1;
+
}
+

+
/* Disable mask mode. */
+
void linenoiseMaskModeDisable(void) {
+
    maskmode = 0;
+
}
+

/* Set if to use or not the multi line mode. */
void linenoiseSetMultiLine(int ml) {
    mlmode = ml;
@@ -525,7 +539,11 @@ static void refreshSingleLine(struct linenoiseState *l) {
    abAppend(&ab,seq,strlen(seq));
    /* Write the prompt and the current buffer content */
    abAppend(&ab,l->prompt,strlen(l->prompt));
-
    abAppend(&ab,buf,len);
+
    if (maskmode == 1) {
+
        while (len--) abAppend(&ab,"*",1);
+
    } else {
+
        abAppend(&ab,buf,len);
+
    }
    /* Show hits if any. */
    refreshShowHints(&ab,l,plen);
    /* Erase to right */
@@ -579,7 +597,12 @@ static void refreshMultiLine(struct linenoiseState *l) {

    /* Write the prompt and the current buffer content */
    abAppend(&ab,l->prompt,strlen(l->prompt));
-
    abAppend(&ab,l->buf,l->len);
+
    if (maskmode == 1) {
+
        unsigned int i;
+
        for (i = 0; i < l->len; i++) abAppend(&ab,"*",1);
+
    } else {
+
        abAppend(&ab,l->buf,l->len);
+
    }

    /* Show hits if any. */
    refreshShowHints(&ab,l,plen);
@@ -647,7 +670,8 @@ int linenoiseEditInsert(struct linenoiseState *l, char c) {
            if ((!mlmode && l->plen+l->len < l->cols && !hintsCallback)) {
                /* Avoid a full update of the line in the
                 * trivial case. */
-
                if (write(l->ofd,&c,1) == -1) return -1;
+
                char d = (maskmode==1) ? '*' : c;
+
                if (write(l->ofd,&d,1) == -1) return -1;
            } else {
                refreshLine(l);
            }
modified external/linenoise/linenoise.h
@@ -65,6 +65,8 @@ int linenoiseHistoryLoad(const char *filename);
void linenoiseClearScreen(void);
void linenoiseSetMultiLine(int ml);
void linenoisePrintKeyCodes(void);
+
void linenoiseMaskModeEnable(void);
+
void linenoiseMaskModeDisable(void);

#ifdef __cplusplus
}