Introduction
Introduction Statistics Contact Development Disclaimer Help
dmenu-separator-5.2.patch - sites - public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log
Files
Refs
---
dmenu-separator-5.2.patch (3681B)
---
1 From db596234b244382e984228791e840190d82967ea Mon Sep 17 00:00:00 2001
2 From: NRK <[email protected]>
3 Date: Fri, 3 Sep 2021 11:11:14 +0600
4 Subject: [PATCH] patch: seperator
5
6 ---
7 dmenu.1 | 12 ++++++++++++
8 dmenu.c | 31 +++++++++++++++++++++++++++----
9 2 files changed, 39 insertions(+), 4 deletions(-)
10
11 diff --git a/dmenu.1 b/dmenu.1
12 index 323f93c..d511148 100644
13 --- a/dmenu.1
14 +++ b/dmenu.1
15 @@ -22,6 +22,10 @@ dmenu \- dynamic menu
16 .IR color ]
17 .RB [ \-w
18 .IR windowid ]
19 +.RB [ \-d
20 +.IR separator ]
21 +.RB [ \-D
22 +.IR separator ]
23 .P
24 .BR dmenu_run " ..."
25 .SH DESCRIPTION
26 @@ -80,6 +84,14 @@ prints version information to stdout, then exits.
27 .TP
28 .BI \-w " windowid"
29 embed into windowid.
30 +.TP
31 +.BI \-d " separator"
32 +separate the input into two halves on the first occurrence of the given…
33 +Display only the first half in dmenu and print the second half to stdou…
34 +Appending '|' to the separator reverses the display/printing order.
35 +.TP
36 +.BI \-D " separator"
37 +same as \-d but separate based on the last occurrence.
38 .SH USAGE
39 dmenu is completely controlled by the keyboard. Items are selected usi…
40 arrow keys, page up, page down, home, and end.
41 diff --git a/dmenu.c b/dmenu.c
42 index 7cf253b..a8eb321 100644
43 --- a/dmenu.c
44 +++ b/dmenu.c
45 @@ -30,12 +30,15 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast …
46
47 struct item {
48 char *text;
49 + char *text_output;
50 struct item *left, *right;
51 int out;
52 };
53
54 static char text[BUFSIZ] = "";
55 static char *embed;
56 +static char separator, separator_reverse;
57 +static char * (*sepchr)(const char *, int);
58 static int bh, mw, mh;
59 static int inputw = 0, promptw;
60 static int lrpad; /* sum of left and right padding */
61 @@ -105,7 +108,7 @@ cleanup(void)
62 for (i = 0; i < SchemeLast; i++)
63 free(scheme[i]);
64 for (i = 0; items && items[i].text; ++i)
65 - free(items[i].text);
66 + free(separator_reverse ? items[i].text_output : items[i…
67 free(items);
68 drw_free(drw);
69 XSync(dpy, False);
70 @@ -490,7 +493,7 @@ insert:
71 break;
72 case XK_Return:
73 case XK_KP_Enter:
74 - puts((sel && !(ev->state & ShiftMask)) ? sel->text : te…
75 + puts((sel && !(ev->state & ShiftMask)) ? sel->text_outp…
76 if (!(ev->state & ControlMask)) {
77 cleanup();
78 exit(0);
79 @@ -549,7 +552,7 @@ paste(void)
80 static void
81 readstdin(void)
82 {
83 - char *line = NULL;
84 + char *p, *line = NULL;
85 size_t i, junk, size = 0;
86 ssize_t len;
87
88 @@ -561,6 +564,19 @@ readstdin(void)
89 if (line[len - 1] == '\n')
90 line[len - 1] = '\0';
91 items[i].text = line;
92 +
93 + if (separator && (p = sepchr(items[i].text, separator))…
94 + *p = '\0';
95 + items[i].text_output = ++p;
96 + } else {
97 + items[i].text_output = items[i].text;
98 + }
99 + if (separator_reverse) {
100 + p = items[i].text;
101 + items[i].text = items[i].text_output;
102 + items[i].text_output = p;
103 + }
104 +
105 items[i].out = 0;
106 }
107 if (items)
108 @@ -711,7 +727,8 @@ static void
109 usage(void)
110 {
111 die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m…
112 - " [-nb color] [-nf color] [-sb color] [-sf colo…
113 + " [-nb color] [-nf color] [-sb color] [-sf colo…
114 + " [-d separator] [-D separator]");
115 }
116
117 int
118 @@ -753,6 +770,12 @@ main(int argc, char *argv[])
119 colors[SchemeSel][ColFg] = argv[++i];
120 else if (!strcmp(argv[i], "-w")) /* embedding window …
121 embed = argv[++i];
122 + else if (!strcmp(argv[i], "-d") || /* field separator */
123 + !strcmp(argv[i], "-D")) {
124 + sepchr = argv[i][1] == 'D' ? strrchr : strchr;
125 + separator = argv[++i][0];
126 + separator_reverse = argv[i][1] == '|';
127 + }
128 else
129 usage();
130
131 --
132 2.35.1
133
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.