add feature which allows prompt width to be removed from items, with or

without arguments
This commit is contained in:
speedie 2023-03-11 13:24:20 +01:00
parent 705cb460bf
commit b24cf560a1
7 changed files with 37 additions and 32 deletions

View file

@ -40,10 +40,10 @@ See a list below for a list.
- spmenu -P - Hide characters
- spmenu -Ps symbol - Set the password symbol to symbol
- spmenu -p text - Set spmenu prompt text to text
- spmenu -ip - Indent items to prompt width
- spmenu -nip - Don't indent items to prompt width
- spmenu -a - Enable alpha
- spmenu -na - Disable alpha
- spmenu -cp - Color prompt
- spmenu -ncp - Don't color prompt
- spmenu -tp - Allow the user to type
- spmenu -nt - Don't allow typing, the user must select an option
- spmenu -x x offset - Offset spmenu x position by x offset

View file

@ -1,4 +1,5 @@
! spmenu default configuration in .Xresources format
spmenu.font: Noto Sans Mono 8
spmenu.col_itemnormfg: #bbbbbb
spmenu.col_itemnormbg: #222222
@ -56,7 +57,6 @@ spmenu.casesensitive: 0
spmenu.menuposition: 1
spmenu.menupaddingv: 0
spmenu.menupaddingh: 0
spmenu.colorprompt: 1
spmenu.preselected: 0
spmenu.type: 1
spmenu.class: spmenu
@ -71,6 +71,7 @@ spmenu.imageposition: 0
spmenu.generatecache: 1
spmenu.mode: 0
spmenu.fast: 0
spmenu.indentitems: 0
spmenu.hidematchcount: 0
spmenu.hidemode: 0
spmenu.hidelarrow: 0

View file

@ -81,10 +81,6 @@ readargs(int argc, char *argv[])
alpha = 0;
} else if (!strcmp(argv[i], "-a")) { /* alpha */
alpha = 1;
} else if (!strcmp(argv[i], "-cp")) { /* color prompt */
colorprompt = 1;
} else if (!strcmp(argv[i], "-ncp")) { /* no color prompt */
colorprompt = 0;
} else if (!strcmp(argv[i], "-tp")) { /* allow the user to type */
type = 1;
} else if (!strcmp(argv[i], "-nt")) { /* don't allow the user to type */
@ -123,6 +119,10 @@ readargs(int argc, char *argv[])
hideimage = 1;
} else if (!strcmp(argv[i], "-si")) { /* don't hide image */
hideimage = 0;
} else if (!strcmp(argv[i], "-ip")) { /* indent to prompt width */
indentitems = 1;
} else if (!strcmp(argv[i], "-nip")) { /* don't indent to prompt width */
indentitems = 0;
} else if (i + 1 == argc)
fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]);
@ -201,6 +201,11 @@ readargs(int argc, char *argv[])
if(sscanf(buf, "%dx%d", &imagewidth, &imageheight) == 1)
imageheight = imagewidth;
} else if (!strcmp(argv[i], "-w")) { /* embedding window id */
embed = argv[++i];
} else if (!strcmp(argv[i], "-n")) { /* preselected item */
preselected = atoi(argv[++i]);
/* spmenu colors */
} else if (!strcmp(argv[i], "-nif")) { /* normal item foreground color */
colors[SchemeItemNorm][ColFg] = argv[++i];
@ -256,7 +261,8 @@ readargs(int argc, char *argv[])
colors[SchemeRArrow][ColFg] = argv[++i];
} else if (!strcmp(argv[i], "-bc")) { /* border */
colors[SchemeBorder][ColBg] = argv[++i];
}
} else if (!strcmp(argv[i], "-cc")) /* caret color */
colors[SchemeCaret][ColFg] = argv[++i];
/* sgr colors */
else if (!strcmp(argv[i], "-sgr0")) textcolors[0] = argv[++i]; /* sgr color 0 */
@ -275,12 +281,6 @@ readargs(int argc, char *argv[])
else if (!strcmp(argv[i], "-sgr13")) textcolors[13] = argv[++i]; /* sgr color 13 */
else if (!strcmp(argv[i], "-sgr14")) textcolors[14] = argv[++i]; /* sgr color 14 */
else if (!strcmp(argv[i], "-sgr15")) textcolors[15] = argv[++i]; /* sgr color 15 */
else if (!strcmp(argv[i], "-cc")) /* caret color */
colors[SchemeCaret][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
else if (!strcmp(argv[i], "-n")) /* preselected item */
preselected = atoi(argv[++i]);
else
fprintf(stderr, "spmenu: Invalid argument: '%s'\n", argv[i]);
}
@ -302,10 +302,10 @@ usage(void)
"spmenu -P Hide characters\n"
"spmenu -Ps <symbol> Set the password symbol to <symbol>\n"
"spmenu -p <text> Set spmenu prompt text to <text>\n"
"spmenu -ip Indent items to prompt width\n"
"spmenu -nip Don't indent items to prompt width\n"
"spmenu -a Enable alpha\n"
"spmenu -na Disable alpha\n"
"spmenu -cp Color prompt\n"
"spmenu -ncp Don't color prompt\n"
"spmenu -tp Allow the user to type\n"
"spmenu -nt Don't allow typing, the user must select an option\n"
"spmenu -x <x offset> Offset spmenu x position by <x offset>\n"

View file

@ -168,9 +168,7 @@ drawmenu(void)
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
if (prompt && *prompt) {
if (colorprompt) {
drw_setscheme(drw, scheme[SchemePrompt]);
}
#if USEIMAGE
ox = x;
@ -208,24 +206,31 @@ drawmenu(void)
numberWidth = TEXTW(numbers);
}
/* draw stuff */
// draw items and image
if (lines > 0) {
int i = 0;
int xpad = 0;
/* draw image first */
// indent items to prompt width?
if (indentitems) {
xpad = 0; // x -= 0
} else {
xpad = promptw; // x -= prompt width so no indentation to prompt width
}
// draw image first
#if USEIMAGE
if (!hideimage && longestedge != 0) {
x = ox;
x += (imagegaps * 2) + imagewidth;
x += xpad;
}
#endif
/* draw grid */
int i = 0;
for (item = curr; item != next; item = item->right, i++)
drawitem(
item,
x + ((i / lines) * ((mw - x) / columns)),
x + ((i / lines) * ((mw - x) / columns)) - xpad,
y + (((i % lines) + 1) * bh),
(mw - x) / columns
);

View file

@ -100,12 +100,11 @@ ResourcePref resources[] = {
{ "menuposition", INTEGER, &menuposition },
{ "menupaddingv", INTEGER, &menupaddingv },
{ "menupaddingh", INTEGER, &menupaddingh },
{ "indentitems", INTEGER, &indentitems },
{ "accuratewidth", INTEGER, &accuratewidth },
{ "alpha", INTEGER, &alpha },
{ "type", INTEGER, &type },
{ "preselected", INTEGER, &preselected },
{ "colorprompt", INTEGER, &colorprompt },
{ "password", STRING, &password },
{ "prompt", STRING, &prompt },
{ "class", STRING, &class },

View file

@ -61,7 +61,7 @@ static unsigned int maxhist = 64; /* Max number of history entries */
static int histnodup = 1; /* If 0, record repeated histories */
/* Prompt options */
static int colorprompt = 1; /* Color prompt (0/1) */
static int indentitems = 0; /* Indent items to prompt width? (0/1) */
static char *prompt = NULL; /* Default prompt, set to NULL (nothing) */
/* Hide options */

View file

@ -72,14 +72,14 @@ spmenu -Ps symbol - Set the password symbol to symbol
.IP \[bu] 2
spmenu -p text - Set spmenu prompt text to text
.IP \[bu] 2
spmenu -ip - Indent items to prompt width
.IP \[bu] 2
spmenu -nip - Don\[cq]t indent items to prompt width
.IP \[bu] 2
spmenu -a - Enable alpha
.IP \[bu] 2
spmenu -na - Disable alpha
.IP \[bu] 2
spmenu -cp - Color prompt
.IP \[bu] 2
spmenu -ncp - Don\[cq]t color prompt
.IP \[bu] 2
spmenu -tp - Allow the user to type
.IP \[bu] 2
spmenu -nt - Don\[cq]t allow typing, the user must select an option