sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dmenu-separator-e35976f.diff (3270B)


      1 diff --git a/dmenu.1 b/dmenu.1
      2 index 323f93c..d511148 100644
      3 --- a/dmenu.1
      4 +++ b/dmenu.1
      5 @@ -22,6 +22,10 @@ dmenu \- dynamic menu
      6  .IR color ]
      7  .RB [ \-w
      8  .IR windowid ]
      9 +.RB [ \-d
     10 +.IR separator ]
     11 +.RB [ \-D
     12 +.IR separator ]
     13  .P
     14  .BR dmenu_run " ..."
     15  .SH DESCRIPTION
     16 @@ -80,6 +84,14 @@ prints version information to stdout, then exits.
     17  .TP
     18  .BI \-w " windowid"
     19  embed into windowid.
     20 +.TP
     21 +.BI \-d " separator"
     22 +separate the input into two halves on the first occurrence of the given charcter.
     23 +Display only the first half in dmenu and print the second half to stdout upon selection.
     24 +Appending '|' to the separator reverses the display/printing order.
     25 +.TP
     26 +.BI \-D " separator"
     27 +same as \-d but separate based on the last occurrence.
     28  .SH USAGE
     29  dmenu is completely controlled by the keyboard.  Items are selected using the
     30  arrow keys, page up, page down, home, and end.
     31 diff --git a/dmenu.c b/dmenu.c
     32 index 571bc35..f2add3b 100644
     33 --- a/dmenu.c
     34 +++ b/dmenu.c
     35 @@ -30,12 +30,15 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
     36  
     37  struct item {
     38  	char *text;
     39 +	char *text_output;
     40  	struct item *left, *right;
     41  	int out;
     42  };
     43  
     44  static char text[BUFSIZ] = "";
     45  static char *embed;
     46 +static char separator, separator_reverse;
     47 +static char * (*sepchr)(const char *, int);
     48  static int bh, mw, mh;
     49  static int inputw = 0, promptw;
     50  static int lrpad; /* sum of left and right padding */
     51 @@ -105,7 +108,7 @@ cleanup(void)
     52  	for (i = 0; i < SchemeLast; i++)
     53  		free(scheme[i]);
     54  	for (i = 0; items && items[i].text; ++i)
     55 -		free(items[i].text);
     56 +		free(separator_reverse ? items[i].text_output : items[i].text);
     57  	free(items);
     58  	drw_free(drw);
     59  	XSync(dpy, False);
     60 @@ -490,7 +493,7 @@ insert:
     61  		break;
     62  	case XK_Return:
     63  	case XK_KP_Enter:
     64 -		puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
     65 +		puts((sel && !(ev->state & ShiftMask)) ? sel->text_output : text);
     66  		if (!(ev->state & ControlMask)) {
     67  			cleanup();
     68  			exit(0);
     69 @@ -561,6 +564,17 @@ readstdin(void)
     70  			*p = '\0';
     71  		if (!(items[i].text = strdup(buf)))
     72  			die("cannot strdup %zu bytes:", strlen(buf) + 1);
     73 +		if (separator && (p = sepchr(items[i].text, separator)) != NULL) {
     74 +			*p = '\0';
     75 +			items[i].text_output = ++p;
     76 +		} else {
     77 +			items[i].text_output = items[i].text;
     78 +		}
     79 +		if (separator_reverse) {
     80 +			p = items[i].text;
     81 +			items[i].text = items[i].text_output;
     82 +			items[i].text_output = p;
     83 +		}
     84  		items[i].out = 0;
     85  	}
     86  	if (items)
     87 @@ -711,7 +725,8 @@ static void
     88  usage(void)
     89  {
     90  	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     91 -	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
     92 +	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
     93 +	      "             [-d separator] [-D separator]\n", stderr);
     94  	exit(1);
     95  }
     96  
     97 @@ -754,6 +769,12 @@ main(int argc, char *argv[])
     98  			colors[SchemeSel][ColFg] = argv[++i];
     99  		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
    100  			embed = argv[++i];
    101 +		else if (!strcmp(argv[i], "-d") || /* field separator */
    102 +		         !strcmp(argv[i], "-D")) {
    103 +			sepchr = argv[i][1] == 'D' ? strrchr : strchr;
    104 +			separator = argv[++i][0];
    105 +			separator_reverse = argv[i][1] == '|';
    106 +		}
    107  		else
    108  			usage();
    109