parent
963a677631
commit
15d7c7bcc2
5 changed files with 30 additions and 5 deletions
|
@ -6,7 +6,7 @@ wmenu - dynamic menu for Wayland
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
*wmenu* [-biv] \
|
*wmenu* [-biPv] \
|
||||||
[-f _font_] \
|
[-f _font_] \
|
||||||
[-l _lines_] \
|
[-l _lines_] \
|
||||||
[-o _output_] \
|
[-o _output_] \
|
||||||
|
@ -35,6 +35,10 @@ $PATH and runs the result.
|
||||||
*-i*
|
*-i*
|
||||||
wmenu matches menu items case insensitively.
|
wmenu matches menu items case insensitively.
|
||||||
|
|
||||||
|
*-P*
|
||||||
|
wmenu will not directly display the keyboard input, but instead replace it
|
||||||
|
with asterisks. All data from stdin will be ignored.
|
||||||
|
|
||||||
*-v*
|
*-v*
|
||||||
prints version information to stdout, then exits.
|
prints version information to stdout, then exits.
|
||||||
|
|
||||||
|
|
5
menu.c
5
menu.c
|
@ -89,7 +89,7 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
||||||
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
|
"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "bhivf:l:o:p:N:n:M:m:S:s:")) != -1) {
|
while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'b':
|
case 'b':
|
||||||
menu->bottom = true;
|
menu->bottom = true;
|
||||||
|
@ -97,6 +97,9 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
|
||||||
case 'i':
|
case 'i':
|
||||||
menu->strncmp = strncasecmp;
|
menu->strncmp = strncasecmp;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
menu->passwd = true;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
puts("wmenu " VERSION);
|
puts("wmenu " VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
2
menu.h
2
menu.h
|
@ -30,6 +30,8 @@ struct menu {
|
||||||
bool bottom;
|
bool bottom;
|
||||||
// The function used to match menu items
|
// The function used to match menu items
|
||||||
int (*strncmp)(const char *, const char *, size_t);
|
int (*strncmp)(const char *, const char *, size_t);
|
||||||
|
// Whether the input is a password
|
||||||
|
bool passwd;
|
||||||
// The font used to display the menu
|
// The font used to display the menu
|
||||||
char *font;
|
char *font;
|
||||||
// The number of lines to list items vertically
|
// The number of lines to list items vertically
|
||||||
|
|
18
render.c
18
render.c
|
@ -79,8 +79,22 @@ static void render_prompt(struct menu *menu, cairo_t *cairo) {
|
||||||
|
|
||||||
// Renders the input text.
|
// Renders the input text.
|
||||||
static void render_input(struct menu *menu, cairo_t *cairo) {
|
static void render_input(struct menu *menu, cairo_t *cairo) {
|
||||||
render_text(menu, cairo, menu->input, menu->promptw, 0, 0,
|
char *censort = NULL;
|
||||||
0, menu->normalfg, menu->padding, menu->padding);
|
|
||||||
|
if (menu->passwd) {
|
||||||
|
censort = calloc(1, sizeof(menu->input));
|
||||||
|
if (!censort) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memset(censort, '*', strlen(menu->input));
|
||||||
|
}
|
||||||
|
|
||||||
|
render_text(menu, cairo, menu->passwd ? censort : menu->input,
|
||||||
|
menu->promptw, 0, 0, 0, menu->normalfg, menu->padding, menu->padding);
|
||||||
|
|
||||||
|
if (censort) {
|
||||||
|
free(censort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renders a cursor for the input field.
|
// Renders a cursor for the input field.
|
||||||
|
|
2
wmenu.c
2
wmenu.c
|
@ -19,7 +19,9 @@ static void read_items(struct menu *menu) {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
struct menu *menu = menu_create();
|
struct menu *menu = menu_create();
|
||||||
menu_getopts(menu, argc, argv);
|
menu_getopts(menu, argc, argv);
|
||||||
|
if (!menu->passwd) {
|
||||||
read_items(menu);
|
read_items(menu);
|
||||||
|
}
|
||||||
int status = menu_run(menu);
|
int status = menu_run(menu);
|
||||||
menu_destroy(menu);
|
menu_destroy(menu);
|
||||||
return status;
|
return status;
|
||||||
|
|
Loading…
Add table
Reference in a new issue