summaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2023-02-21 13:45:16 -0600
committerzachir <zachir@librem.one>2023-02-21 13:45:16 -0600
commit2e426cac046fdd057880eda259482db0e965aebd (patch)
tree286cc96a776b2139acdb21fbbba065c79a969f52 /dmenu.c
parentb31a684c71db67dfe9661a86364539822d4d439d (diff)
add separator patch
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/dmenu.c b/dmenu.c
index 7cf253b..a8eb321 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -30,12 +30,15 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
struct item {
char *text;
+ char *text_output;
struct item *left, *right;
int out;
};
static char text[BUFSIZ] = "";
static char *embed;
+static char separator, separator_reverse;
+static char * (*sepchr)(const char *, int);
static int bh, mw, mh;
static int inputw = 0, promptw;
static int lrpad; /* sum of left and right padding */
@@ -105,7 +108,7 @@ cleanup(void)
for (i = 0; i < SchemeLast; i++)
free(scheme[i]);
for (i = 0; items && items[i].text; ++i)
- free(items[i].text);
+ free(separator_reverse ? items[i].text_output : items[i].text);
free(items);
drw_free(drw);
XSync(dpy, False);
@@ -490,7 +493,7 @@ insert:
break;
case XK_Return:
case XK_KP_Enter:
- puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
+ puts((sel && !(ev->state & ShiftMask)) ? sel->text_output : text);
if (!(ev->state & ControlMask)) {
cleanup();
exit(0);
@@ -549,7 +552,7 @@ paste(void)
static void
readstdin(void)
{
- char *line = NULL;
+ char *p, *line = NULL;
size_t i, junk, size = 0;
ssize_t len;
@@ -561,6 +564,19 @@ readstdin(void)
if (line[len - 1] == '\n')
line[len - 1] = '\0';
items[i].text = line;
+
+ if (separator && (p = sepchr(items[i].text, separator)) != NULL) {
+ *p = '\0';
+ items[i].text_output = ++p;
+ } else {
+ items[i].text_output = items[i].text;
+ }
+ if (separator_reverse) {
+ p = items[i].text;
+ items[i].text = items[i].text_output;
+ items[i].text_output = p;
+ }
+
items[i].out = 0;
}
if (items)
@@ -711,7 +727,8 @@ static void
usage(void)
{
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
+ " [-d separator] [-D separator]");
}
int
@@ -753,6 +770,12 @@ main(int argc, char *argv[])
colors[SchemeSel][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
+ else if (!strcmp(argv[i], "-d") || /* field separator */
+ !strcmp(argv[i], "-D")) {
+ sepchr = argv[i][1] == 'D' ? strrchr : strchr;
+ separator = argv[++i][0];
+ separator_reverse = argv[i][1] == '|';
+ }
else
usage();