Merged with tsv

This commit is contained in:
Andreev Gregory 2025-03-03 17:56:49 +03:00
commit b0bc7132e9

14
dmenu.c
View File

@ -29,6 +29,7 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
struct item { struct item {
char *text; char *text;
char *stext;
struct item *left, *right; struct item *left, *right;
int out; int out;
}; };
@ -139,7 +140,7 @@ drawitem(struct item *item, int x, int y, int w)
else else
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0); return drw_text(drw, x, y, w, bh, lrpad / 2, item->stext, 0);
} }
static void static void
@ -181,7 +182,7 @@ drawmenu(void)
} }
x += w; x += w;
for (item = curr; item != next; item = item->right) for (item = curr; item != next; item = item->right)
x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">"))); x = drawitem(item, x, 0, textw_clamp(item->stext, mw - x - TEXTW(">")));
if (next) { if (next) {
w = TEXTW(">"); w = TEXTW(">");
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
@ -548,7 +549,7 @@ paste(void)
static void static void
readstdin(void) readstdin(void)
{ {
char *line = NULL; char *line = NULL, *p;
size_t i, itemsiz = 0, linesiz = 0; size_t i, itemsiz = 0, linesiz = 0;
ssize_t len; ssize_t len;
@ -558,12 +559,15 @@ readstdin(void)
itemsiz += 256; itemsiz += 256;
if (!(items = realloc(items, itemsiz * sizeof(*items)))) if (!(items = realloc(items, itemsiz * sizeof(*items))))
die("cannot realloc %zu bytes:", itemsiz * sizeof(*items)); die("cannot realloc %zu bytes:", itemsiz * sizeof(*items));
} }
if (line[len - 1] == '\n') if (line[len - 1] == '\n')
line[len - 1] = '\0'; line[len - 1] = '\0';
if (!(items[i].text = strdup(line))) if (!(items[i].text = strdup(line)))
die("strdup:"); die("strdup:");
if ((p = strchr(line, '\t')))
*p = '\0';
if (!(items[i].stext = strdup(line)))
die("cannot strdup bytes:");
items[i].out = 0; items[i].out = 0;
} }
free(line); free(line);