sites

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

dmenu-tsv-20220305-e73651f.diff (1504B)


      1 From 7f578b2ba3d6f3eb687181aed23fafd0f92d3f28 Mon Sep 17 00:00:00 2001
      2 From: prenev <an2qzavok@gmail.com>
      3 Date: Tue, 5 Apr 2022 15:26:36 +0300
      4 Subject: [PATCH] tab-separate input lines and only display first parts
      5 
      6 ---
      7  dmenu.c | 9 +++++++--
      8  1 file changed, 7 insertions(+), 2 deletions(-)
      9 
     10 diff --git a/dmenu.c b/dmenu.c
     11 index 839f6cc..3eb196e 100644
     12 --- a/dmenu.c
     13 +++ b/dmenu.c
     14 @@ -30,6 +30,7 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
     15  
     16  struct item {
     17  	char *text;
     18 +	char *stext;
     19  	struct item *left, *right;
     20  	int out;
     21  };
     22 @@ -140,7 +141,7 @@ drawitem(struct item *item, int x, int y, int w)
     23  	else
     24  		drw_setscheme(drw, scheme[SchemeNorm]);
     25  
     26 -	return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
     27 +	return drw_text(drw, x, y, w, bh, lrpad / 2, item->stext, 0);
     28  }
     29  
     30  static void
     31 @@ -182,7 +183,7 @@ drawmenu(void)
     32  		}
     33  		x += w;
     34  		for (item = curr; item != next; item = item->right)
     35 -			x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
     36 +			x = drawitem(item, x, 0, textw_clamp(item->stext, mw - x - TEXTW(">")));
     37  		if (next) {
     38  			w = TEXTW(">");
     39  			drw_setscheme(drw, scheme[SchemeNorm]);
     40 @@ -561,6 +562,10 @@ readstdin(void)
     41  			*p = '\0';
     42  		if (!(items[i].text = strdup(buf)))
     43  			die("cannot strdup %zu bytes:", strlen(buf) + 1);
     44 +		if ((p = strchr(buf, '\t')))
     45 +			*p = '\0';
     46 +		if (!(items[i].stext = strdup(buf)))
     47 +			die("cannot strdup %zu bytes:", strlen(buf) + 1);
     48  		items[i].out = 0;
     49  	}
     50  	if (items)
     51 -- 
     52 2.35.1
     53