diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-12-05 13:46:41 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-12-05 13:46:41 +0100 |
commit | dd2c176e769c4763db2e2432aabf8b433b89f138 (patch) | |
tree | 3ab8293d32b282a9b5b8154f45fe33d7baf1cbba /src/passphrase.c | |
parent | read input from passcheck (diff) | |
download | libpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.gz libpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.bz2 libpassphrase-dd2c176e769c4763db2e2432aabf8b433b89f138.tar.xz |
issue #2 on github solved, but not yet perfect
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/passphrase.c')
-rw-r--r-- | src/passphrase.c | 30 |
1 files changed, 27 insertions, 3 deletions
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 <fcntl.h> #include <errno.h> #include <limits.h> +#include <termios.h> #include <sys/wait.h> #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; } |