forked from test34/can_wizard
add mask input mode
from orig commit 514b09c
This commit is contained in:
parent
33296225b5
commit
4b7d4b8786
2 changed files with 25 additions and 2 deletions
|
@ -122,6 +122,7 @@ static linenoiseCompletionCallback *completionCallback = NULL;
|
||||||
static linenoiseHintsCallback *hintsCallback = NULL;
|
static linenoiseHintsCallback *hintsCallback = NULL;
|
||||||
static linenoiseFreeHintsCallback *freeHintsCallback = 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 mlmode = 0; /* Multi line mode. Default is single line. */
|
||||||
static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN;
|
static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN;
|
||||||
static int history_len = 0;
|
static int history_len = 0;
|
||||||
|
@ -189,6 +190,14 @@ FILE *lndebug_fp = NULL;
|
||||||
|
|
||||||
/* ======================= Low level terminal handling ====================== */
|
/* ======================= Low level terminal handling ====================== */
|
||||||
|
|
||||||
|
void linenoiseMaskModeEnable() {
|
||||||
|
maskmode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void linenoiseMaskModeDisable() {
|
||||||
|
maskmode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set if to use or not the multi line mode. */
|
/* Set if to use or not the multi line mode. */
|
||||||
void linenoiseSetMultiLine(int ml) {
|
void linenoiseSetMultiLine(int ml) {
|
||||||
mlmode = ml;
|
mlmode = ml;
|
||||||
|
@ -450,7 +459,12 @@ static void refreshSingleLine(struct linenoiseState *l) {
|
||||||
abAppend(&ab,seq,strlen(seq));
|
abAppend(&ab,seq,strlen(seq));
|
||||||
/* Write the prompt and the current buffer content */
|
/* Write the prompt and the current buffer content */
|
||||||
abAppend(&ab,l->prompt,strlen(l->prompt));
|
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. */
|
/* Show hits if any. */
|
||||||
refreshShowHints(&ab,l,plen);
|
refreshShowHints(&ab,l,plen);
|
||||||
/* Erase to right */
|
/* Erase to right */
|
||||||
|
@ -504,7 +518,12 @@ static void refreshMultiLine(struct linenoiseState *l) {
|
||||||
|
|
||||||
/* Write the prompt and the current buffer content */
|
/* Write the prompt and the current buffer content */
|
||||||
abAppend(&ab,l->prompt,strlen(l->prompt));
|
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. */
|
/* Show hits if any. */
|
||||||
refreshShowHints(&ab,l,plen);
|
refreshShowHints(&ab,l,plen);
|
||||||
|
|
|
@ -67,6 +67,10 @@ void linenoiseClearScreen(void);
|
||||||
void linenoiseSetMultiLine(int ml);
|
void linenoiseSetMultiLine(int ml);
|
||||||
void linenoisePrintKeyCodes(void);
|
void linenoisePrintKeyCodes(void);
|
||||||
|
|
||||||
|
void linenoiseMaskModeEnable();
|
||||||
|
void linenoiseMaskModeDisable();
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue