From c0b27bf6e2350a5eb543966a81d2930275ae8b67 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 22 Nov 2013 10:52:55 +0100 Subject: add option to print * for each char MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/passphrase.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/passphrase.c b/src/passphrase.c index 43f1431..94922e4 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -64,6 +64,18 @@ char* passphrase_read(void) break; if (c != 0) { +#ifdef PASSPHRASE_STAR + if ((c == 8) || (c == 127)) + { + if (len == 0) + continue; + printf("\033[D \033[D"); + fflush(stdout); + *(rc + --len) = 0; + continue; + } + putchar('*'); +#endif *(rc + len++) = c; if (len == size) if ((rc = realloc(rc, (size <<= 1L) * sizeof(char))) == NULL) @@ -92,6 +104,9 @@ void passphrase_disable_echo(void) tcgetattr(STDIN_FILENO, &stty); saved_stty = stty; stty.c_lflag &= ~ECHO; +#ifdef PASSPHRASE_STAR + stty.c_lflag &= ~ICANON; +#endif tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty); #endif } -- cgit v1.2.3-70-g09d2