From dd2c176e769c4763db2e2432aabf8b433b89f138 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 5 Dec 2015 13:46:41 +0100 Subject: issue #2 on github solved, but not yet perfect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/passphrase.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/passphrase.c') diff --git a/src/passphrase.c b/src/passphrase.c index 032111b..2978c80 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #define PASSPHRASE_USE_DEPRECATED @@ -85,6 +86,9 @@ static void passcheck_start(struct passcheck_state* state, int flags) if (state->flags == 0) return; + if (state->flags & PASSPHRASE_READ_BELOW_FREE) + state->flags &= ~PASSPHRASE_READ_SCREEN_FREE; + command = getenv("LIBPASSPHRASE_METER"); if (!command || !*command) command = DEFAULT_PASSPHRASE_METER; @@ -163,6 +167,19 @@ static void passcheck_start(struct passcheck_state* state, int flags) goto fail; } + if (state->flags & PASSPHRASE_READ_SCREEN_FREE) + { + struct termios stty; + struct termios saved_stty; + tcgetattr(STDERR_FILENO, &stty); + saved_stty = stty; + stty.c_oflag &= (tcflag_t)~ONLCR; + tcsetattr(STDERR_FILENO, TCSAFLUSH, &stty); + fprintf(stderr, "\n\033[A"); + fflush(stderr); + tcsetattr(STDERR_FILENO, TCSAFLUSH, &saved_stty); + } + close(exec_rw[0]); state->pid = pid; return; @@ -195,7 +212,11 @@ rereap: if ((waitpid(state->pid, &_status, 0) == -1) && (errno == EINTR)) goto rereap; - /* TODO cleanup */ + if (state->flags & PASSPHRASE_READ_SCREEN_FREE) + fprintf(stderr, "\033[s\033[E\033[0K\033[u"); + else + fprintf(stderr, "\033[B\033[0K\033[A"); + fflush(stderr); state->flags = 0; } @@ -280,7 +301,11 @@ static void passcheck_update(struct passcheck_state* state, const char* passphra } strength_ptr = 0; - /* TODO */ + if (state->flags & PASSPHRASE_READ_SCREEN_FREE) + fprintf(stderr, "\033[s\033[E\033[0K%s%lli\033[u", /*TODO locale*/"Strength: ", value); + else + fprintf(stderr, "\033[B\033[s\033[0K%lli\033[u\033[A", value); + fflush(stderr); return; fail: @@ -404,7 +429,6 @@ char* passphrase_read2(int fdin, int flags) { #ifdef PASSPHRASE_METER passcheck_stop(&passcheck); - xflush(); #endif /* PASSPHRASE_METER */ break; } -- cgit v1.2.3-70-g09d2