~adnano/wmenu-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] port dmenu password patch

Details
Message ID
<20240310150050.18029-1-sewn@disroot.org>
DKIM signature
pass
Download raw message
Patch: +30 -6
---
 docs/wmenu.1.scd |  6 +++++-
 menu.c           | 13 ++++++++++---
 menu.h           |  2 ++
 render.c         | 15 +++++++++++++--
 4 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/docs/wmenu.1.scd b/docs/wmenu.1.scd
index 0117aa1..407da9f 100644
--- a/docs/wmenu.1.scd
+++ b/docs/wmenu.1.scd
@@ -6,7 +6,7 @@ wmenu - dynamic menu for Wayland

# SYNOPSIS

*wmenu* [-biv] \
*wmenu* [-biPv] \
  [-f _font_] \
  [-l _lines_] \
  [-o _output_] \
@@ -30,6 +30,10 @@ to those matching the tokens in the input.
*-i*
	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*
	prints version information to stdout, then exits.

diff --git a/menu.c b/menu.c
index 0acfcab..07df149 100644
--- a/menu.c
+++ b/menu.c
@@ -89,11 +89,11 @@ static bool parse_color(const char *color, uint32_t *result) {
// Parse menu options from command line arguments.
void menu_getopts(struct menu *menu, int argc, char *argv[]) {
	const char *usage =
		"Usage: wmenu [-biv] [-f font] [-l lines] [-o output] [-p prompt]\n"
		"Usage: wmenu [-biPv] [-f font] [-l lines] [-o output] [-p prompt]\n"
		"\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";

	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) {
		case 'b':
			menu->bottom = true;
@@ -101,6 +101,9 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
		case 'i':
			menu->strncmp = strncasecmp;
			break;
		case 'P':
			menu->passwd = true;
			break;
		case 'v':
			puts("wmenu " VERSION);
			exit(EXIT_SUCCESS);
@@ -335,8 +338,12 @@ static void match_items(struct menu *menu) {

// Read menu items from standard input.
void read_menu_items(struct menu *menu) {
	char buf[sizeof menu->input];
	if (menu->passwd) {
		menu->inputw = menu->lines = 0;
		return;
	}

	char buf[sizeof menu->input];
	struct item **next = &menu->items;
	while (fgets(buf, sizeof buf, stdin)) {
		char *p = strchr(buf, '\n');
diff --git a/menu.h b/menu.h
index 4c62d3f..9e2757b 100644
--- a/menu.h
+++ b/menu.h
@@ -59,6 +59,8 @@ struct menu {
	int lines;
	// The name of the output to display on
	char *output_name;
	// Whether the input is only viewed as asterisks
	bool passwd;
	// The prompt displayed to the left of the input field
	char *prompt;
	// Normal colors
diff --git a/render.c b/render.c
index 135d51f..50ecdf8 100644
--- a/render.c
+++ b/render.c
@@ -72,8 +72,19 @@ static void render_prompt(struct menu *menu, cairo_t *cairo) {

// Renders the input text.
static void render_input(struct menu *menu, cairo_t *cairo) {
	render_text(menu, cairo, menu->input, menu->promptw, 0, 0,
		0, menu->normalfg, menu->padding, menu->padding);
	char *censort = NULL;

	if (menu->passwd) {
		if (!(censort = calloc(1, sizeof(menu->input))))
			return;
		memset(censort, '*', strlen(menu->input));
	}

	render_text(menu, cairo, !menu->passwd ? menu->input : censort,
		menu->promptw, 0, 0, 0, menu->normalfg, menu->padding, menu->padding);

	if (censort)
		free(censort);
}

// Renders a cursor for the input field.
-- 
2.44.0
Details
Message ID
<CZVZUU7D3VU5.18JE00LK11H0L@maolood.com>
In-Reply-To
<20240310150050.18029-1-sewn@disroot.org> (view parent)
DKIM signature
pass
Download raw message
I applied this with some minor fixes and style changes.

Thanks!

To git@git.sr.ht:~adnano/wmenu
   2856ddd..1c6c9c1  master -> master
Reply to thread Export thread (mbox)