diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-06-04 19:51:56 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-06-04 19:51:56 -0700 |
| commit | b4bf9255453ae88ef54eddc00bd752a43b32ae26 (patch) | |
| tree | a4391d95c044372c652c09c8955f45294ca14c81 /ask.c | |
| parent | 9a151a0fb21eacac994e4260ef015b3ed3ed0e69 (diff) | |
Added password functionality, --help, and --version
Diffstat (limited to 'ask.c')
| -rw-r--r-- | ask.c | 37 |
1 files changed, 27 insertions, 10 deletions
@@ -16,10 +16,11 @@ #include "bterm.h" -static int password = 0, quickpick = 0, case_sensitive = 0, to_skip = 0; - #define LOWERCASE(c) ('A' <= (c) && (c) <= 'Z' ? ((c) + 'a' - 'A') : (c)) #define EQ(a, b) (case_sensitive ? (a) == (b) : LOWERCASE(a) == LOWERCASE(b)) +#define PASSWORD "-\\|/" + +static int password = 0, quickpick = 0, case_sensitive = 0, to_skip = 0; static inline void *memcheck(void *p) { @@ -121,15 +122,23 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init return best; picked = best; - if (best) { - draw_line(out, best, buf, &buf[b]); + if (password) { + if (best) fputs("\033[0;32m", out); + else if (nopts > 0) fputs("\033[0;31m", out); + else fputs("\033[0;2m", out); + fputc((PASSWORD)[strlen(buf) % strlen(PASSWORD)], out); + fputs("\033[0m", out); } else { - if (nopts > 0) - fprintf(out, "\033[0;31m%s\033[0m", buf); - else - fprintf(out, "\033[0m%s\033[0m", buf); - if (b < (int)strlen(buf)) - fprintf(out, "\033[%dD", (int)strlen(buf) - b); + if (best) { + draw_line(out, best, buf, &buf[b]); + } else { + if (nopts > 0) + fprintf(out, "\033[0;31m%s\033[0m", buf); + else + fprintf(out, "\033[0m%s\033[0m", buf); + if (b < (int)strlen(buf)) + fprintf(out, "\033[%dD", (int)strlen(buf) - b); + } } fflush(out); int key; @@ -241,10 +250,18 @@ int main(int argc, char *argv[]) password = 1; } else if (strcmp(argv[a], "-q") == 0 || strcmp(argv[a], "--quickpick") == 0) { quickpick = 1; + } else if (strcmp(argv[a], "-h") == 0 || strcmp(argv[a], "--help") == 0) { + printf("ask - A simple command line input tool.\n" + "Usage: ask [-q|--quickpick] [-p|--password] [-v|--version] [-h|--help] [prompt [initial [options...]]]\n"); + return 0; + } else if (strcmp(argv[a], "-v") == 0 || strcmp(argv[a], "--version") == 0) { + printf("ask v0.1\n"); + return 0; } else break; ++a; } if (!prompt && a < argc) prompt = argv[a++]; + if (!prompt) prompt = "> "; if (!initial && a < argc) initial = argv[a++]; while (a < argc) { |
