diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:11:03 -0500 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-02-25 22:11:03 -0500 |
commit | 3cc0e23d37354724f897dfaf74411c58c2b3bdea (patch) | |
tree | 85b2d2b4a023a7ea420ca57be124c564801222fa | |
parent | 494b7fe74a8dc334a5b0345c84814ec3d8316999 (diff) |
Apply password patch
-rwxr-xr-x | dmenu | bin | 0 -> 44544 bytes | |||
-rw-r--r-- | dmenu.1 | 5 | ||||
-rw-r--r-- | dmenu.c | 21 | ||||
-rwxr-xr-x | stest | bin | 0 -> 17680 bytes |
4 files changed, 21 insertions, 5 deletions
Binary files differ | |||
@@ -3,7 +3,7 @@ | |||
3 | dmenu \- dynamic menu | 3 | dmenu \- dynamic menu |
4 | .SH SYNOPSIS | 4 | .SH SYNOPSIS |
5 | .B dmenu | 5 | .B dmenu |
6 | .RB [ \-bfiv ] | 6 | .RB [ \-bfivP ] |
7 | .RB [ \-l | 7 | .RB [ \-l |
8 | .IR lines ] | 8 | .IR lines ] |
9 | .RB [ \-m | 9 | .RB [ \-m |
@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file. | |||
47 | .B \-i | 47 | .B \-i |
48 | dmenu matches menu items case insensitively. | 48 | dmenu matches menu items case insensitively. |
49 | .TP | 49 | .TP |
50 | .B \-P | ||
51 | dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. | ||
52 | .TP | ||
50 | .BI \-l " lines" | 53 | .BI \-l " lines" |
51 | dmenu lists items vertically, with the given number of lines. | 54 | dmenu lists items vertically, with the given number of lines. |
52 | .TP | 55 | .TP |
@@ -41,7 +41,7 @@ struct item { | |||
41 | static char text[BUFSIZ] = ""; | 41 | static char text[BUFSIZ] = ""; |
42 | static char *embed; | 42 | static char *embed; |
43 | static int bh, mw, mh; | 43 | static int bh, mw, mh; |
44 | static int inputw = 0, promptw; | 44 | static int inputw = 0, promptw, passwd = 0; |
45 | static int lrpad; /* sum of left and right padding */ | 45 | static int lrpad; /* sum of left and right padding */ |
46 | static size_t cursor; | 46 | static size_t cursor; |
47 | static struct item *items = NULL; | 47 | static struct item *items = NULL; |
@@ -198,6 +198,7 @@ drawmenu(void) | |||
198 | unsigned int curpos; | 198 | unsigned int curpos; |
199 | struct item *item; | 199 | struct item *item; |
200 | int x = 0, y = 0, w; | 200 | int x = 0, y = 0, w; |
201 | char *censort; | ||
201 | 202 | ||
202 | drw_setscheme(drw, scheme[SchemeNorm]); | 203 | drw_setscheme(drw, scheme[SchemeNorm]); |
203 | drw_rect(drw, 0, 0, mw, mh, 1, 1); | 204 | drw_rect(drw, 0, 0, mw, mh, 1, 1); |
@@ -209,7 +210,12 @@ drawmenu(void) | |||
209 | /* draw input field */ | 210 | /* draw input field */ |
210 | w = (lines > 0 || !matches) ? mw - x : inputw; | 211 | w = (lines > 0 || !matches) ? mw - x : inputw; |
211 | drw_setscheme(drw, scheme[SchemeNorm]); | 212 | drw_setscheme(drw, scheme[SchemeNorm]); |
212 | drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); | 213 | if (passwd) { |
214 | censort = ecalloc(1, sizeof(text)); | ||
215 | memset(censort, '.', strlen(text)); | ||
216 | drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); | ||
217 | free(censort); | ||
218 | } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); | ||
213 | 219 | ||
214 | curpos = TEXTW(text) - TEXTW(&text[cursor]); | 220 | curpos = TEXTW(text) - TEXTW(&text[cursor]); |
215 | if ((curpos += lrpad / 2 - 1) < w) { | 221 | if ((curpos += lrpad / 2 - 1) < w) { |
@@ -687,6 +693,11 @@ readstdin(void) | |||
687 | size_t i, junk, size = 0; | 693 | size_t i, junk, size = 0; |
688 | ssize_t len; | 694 | ssize_t len; |
689 | 695 | ||
696 | if(passwd){ | ||
697 | inputw = lines = 0; | ||
698 | return; | ||
699 | } | ||
700 | |||
690 | /* read each line from stdin and add it to the item list */ | 701 | /* read each line from stdin and add it to the item list */ |
691 | for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) { | 702 | for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) { |
692 | if (i + 1 >= size / sizeof *items) | 703 | if (i + 1 >= size / sizeof *items) |
@@ -847,7 +858,7 @@ setup(void) | |||
847 | static void | 858 | static void |
848 | usage(void) | 859 | usage(void) |
849 | { | 860 | { |
850 | die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" | 861 | die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" |
851 | " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); | 862 | " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); |
852 | } | 863 | } |
853 | 864 | ||
@@ -871,7 +882,9 @@ main(int argc, char *argv[]) | |||
871 | else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ | 882 | else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ |
872 | fstrncmp = strncasecmp; | 883 | fstrncmp = strncasecmp; |
873 | fstrstr = cistrstr; | 884 | fstrstr = cistrstr; |
874 | } else if (i + 1 == argc) | 885 | } else if (!strcmp(argv[i], "-P")) /* is the input a password */ |
886 | passwd = 1; | ||
887 | else if (i + 1 == argc) | ||
875 | usage(); | 888 | usage(); |
876 | /* these options take one argument */ | 889 | /* these options take one argument */ |
877 | else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ | 890 | else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ |
Binary files differ | |||