sites

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

dmenu-tsv-20221023-1d2b462.diff (1454B)


      1 From 3f37b2fc545b90e80658c6489846cca23d936939 Mon Sep 17 00:00:00 2001
      2 From: prenev <an2qzavok@gmail.com>
      3 Date: Sun, 23 Oct 2022 02:16:54 +0300
      4 Subject: [PATCH] tab-separate input lines and only display first parts
      5 
      6 ---
      7  dmenu.c | 8 +++++---
      8  1 file changed, 5 insertions(+), 3 deletions(-)
      9 
     10 diff --git a/dmenu.c b/dmenu.c
     11 index 7cf253b..8eed38a 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 @@ -560,7 +561,8 @@ readstdin(void)
     41  				die("cannot realloc %zu bytes:", size);
     42  		if (line[len - 1] == '\n')
     43  			line[len - 1] = '\0';
     44 -		items[i].text = line;
     45 +		items[i].text = strdup(line);
     46 +		items[i].stext = strsep(&line, "\t");
     47  		items[i].out = 0;
     48  	}
     49  	if (items)
     50 -- 
     51 2.37.3
     52