From 4b7d4b878647a290ce55fb7193d630b92e0a64b0 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 20:56:22 +0300 Subject: [PATCH] add mask input mode from orig commit 514b09c --- components/console/linenoise/linenoise.c | 23 +++++++++++++++++++++-- components/console/linenoise/linenoise.h | 4 ++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index 62b20be..e7aac74 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -122,6 +122,7 @@ static linenoiseCompletionCallback *completionCallback = NULL; static linenoiseHintsCallback *hintsCallback = NULL; static linenoiseFreeHintsCallback *freeHintsCallback = NULL; +static int maskmode = 0; /* for mask input mode */ static int mlmode = 0; /* Multi line mode. Default is single line. */ static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN; static int history_len = 0; @@ -189,6 +190,14 @@ FILE *lndebug_fp = NULL; /* ======================= Low level terminal handling ====================== */ +void linenoiseMaskModeEnable() { + maskmode = 1; +} + +void linenoiseMaskModeDisable() { + maskmode = 0; +} + /* Set if to use or not the multi line mode. */ void linenoiseSetMultiLine(int ml) { mlmode = ml; @@ -450,7 +459,12 @@ 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 */ @@ -504,7 +518,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) { + for (uint i = 0; i < l->len; i++) { + abAppend(&ab,"*",1); + } + } else + abAppend(&ab,l->buf,l->len); /* Show hits if any. */ refreshShowHints(&ab,l,plen); diff --git a/components/console/linenoise/linenoise.h b/components/console/linenoise/linenoise.h index 31a7d0f..cb37c69 100644 --- a/components/console/linenoise/linenoise.h +++ b/components/console/linenoise/linenoise.h @@ -67,6 +67,10 @@ void linenoiseClearScreen(void); void linenoiseSetMultiLine(int ml); void linenoisePrintKeyCodes(void); +void linenoiseMaskModeEnable(); +void linenoiseMaskModeDisable(); + + #ifdef __cplusplus } #endif