add ability to print item number rather than the item itself
This commit is contained in:
parent
c58542c2b9
commit
5ff1abc849
|
@ -54,6 +54,12 @@ You may use long, descriptive arguments or the shorter arguments.
|
|||
`-nrw, --no-relative-width`
|
||||
: Disable relative input width
|
||||
|
||||
`-ix, --print-index`
|
||||
: Print index instead of actual text
|
||||
|
||||
`-nix, --no-print-index`
|
||||
: Don't print index instead of actual text
|
||||
|
||||
`-f, --fast`
|
||||
: Grabs keyboard before reading stdin
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ spmenu.dockproperty: 1
|
|||
spmenu.fast: 0
|
||||
spmenu.managed: 0
|
||||
spmenu.mon: -1
|
||||
spmenu.printindex: 0
|
||||
spmenu.coloritems: 1
|
||||
spmenu.sgr: 1
|
||||
|
||||
|
|
|
@ -199,6 +199,10 @@ spmenu = {
|
|||
password = 0; // Don't read standard input and replace all characters with the password character (0/1)
|
||||
} );
|
||||
|
||||
/* Output options */
|
||||
output = ( { printindex = 0; // Print index instead of actual text (0/1)
|
||||
} );
|
||||
|
||||
/* Mode options */
|
||||
mode = ( { default = 0; // Mode to start spmenu in (0: Normal mode, 1: Insert mode)
|
||||
normal_text = "Normal"; // Normal mode text (text)
|
||||
|
|
|
@ -252,6 +252,14 @@ void backspace(Arg *arg) {
|
|||
void selectitem(Arg *arg) {
|
||||
char *selection;
|
||||
|
||||
// print index
|
||||
if (printindex && sel && arg->i) {
|
||||
fprintf(stdout, "%d\n", sel->index);
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// selected item or input?
|
||||
if (sel && arg->i && !hideitem) {
|
||||
selection = sel->text;
|
||||
} else {
|
||||
|
|
|
@ -94,6 +94,10 @@ void readargs(int argc, char *argv[]) {
|
|||
fuzzy = 1;
|
||||
} else if (!strcmp(argv[i], "-NF") || (!strcmp(argv[i], "--no-fuzzy"))) { // no fuzzy matching
|
||||
fuzzy = 0;
|
||||
} else if (!strcmp(argv[i], "-ix") || (!strcmp(argv[i], "--print-index"))) { // print index
|
||||
printindex = 1;
|
||||
} else if (!strcmp(argv[i], "-nix") || (!strcmp(argv[i], "--no-print-index"))) { // no print index
|
||||
printindex = 0;
|
||||
} else if (!strcmp(argv[i], "-s") || (!strcmp(argv[i], "--case-sensitive")) || (!strcmp(argv[i], "--sensitive"))) { // case-sensitive item matching
|
||||
casesensitive = 1;
|
||||
} else if (!strcmp(argv[i], "-ns") || (!strcmp(argv[i], "--case-insensitive")) || (!strcmp(argv[i], "--insensitive"))) { // case-insensitive item matching
|
||||
|
@ -448,6 +452,8 @@ void usage(void) {
|
|||
"spmenu -mc --max-cache <size> Set max image cache size to <size>\n"
|
||||
"spmenu -rw, --relative-width Enable relative input width\n"
|
||||
"spmenu -nrw, --no-relative-width Disable relative input width\n"
|
||||
"spmenu -ix, --print-index Print index instead of actual text\n"
|
||||
"spmenu -nix, --no-print-index Don't print index instead of actual text\n"
|
||||
"spmenu -f, --fast Grabs keyboard before reading stdin\n"
|
||||
"spmenu -F, --fuzzy Enable fuzzy matching\n"
|
||||
"spmenu -NF, --no-fuzzy Disable fuzzy matching\n"
|
||||
|
|
|
@ -400,6 +400,17 @@ void conf_init(void) {
|
|||
}
|
||||
}
|
||||
|
||||
// load options spmenu.output
|
||||
config_setting_t *output_setting = config_lookup(&cfg, "spmenu.output");
|
||||
if (output_setting != NULL) {
|
||||
for (unsigned int i = 0; i < config_setting_length(output_setting); ++i) {
|
||||
config_setting_t *conf = config_setting_get_elem(output_setting, i);
|
||||
|
||||
// look up
|
||||
config_setting_lookup_int(conf, "printindex", &printindex); // spmenu.output.printindex
|
||||
}
|
||||
}
|
||||
|
||||
// load options spmenu.mode
|
||||
config_setting_t *mode_setting = config_lookup(&cfg, "spmenu.mode");
|
||||
if (mode_setting != NULL) {
|
||||
|
|
|
@ -30,6 +30,8 @@ void readstdin(void) {
|
|||
imax = i;
|
||||
}
|
||||
|
||||
items[i].index = i;
|
||||
|
||||
// parse image markup
|
||||
#if USEIMAGE
|
||||
if(!strncmp("IMG:", items[i].text, strlen("IMG:"))) {
|
||||
|
|
|
@ -146,6 +146,7 @@ ResourcePref resources[] = {
|
|||
{ "managed", INTEGER, &managed },
|
||||
{ "mon", INTEGER, &mon },
|
||||
{ "sortmatches", INTEGER, &sortmatches },
|
||||
{ "printindex", INTEGER, &printindex },
|
||||
{ "fuzzy", INTEGER, &fuzzy },
|
||||
{ "pango_item", INTEGER, &pango_item },
|
||||
{ "pango_prompt", INTEGER, &pango_prompt },
|
||||
|
|
|
@ -225,6 +225,7 @@ static int pango_mode = 0; /* Enable support for pango markup f
|
|||
static int pango_password = 0; /* Enable support for pango markup for the password text */
|
||||
|
||||
/* Misc */
|
||||
static int coloritems = 1; /* Color items or not */
|
||||
static int sgr = 1; /* Support SGR sequences or not */
|
||||
static char *worddelimiters = " "; /* Word delimiters used for keybinds that change words, " " is default. */
|
||||
static int printindex = 0; /* Print index instead of the text itself (0/1) */
|
||||
static int coloritems = 1; /* Color items (0/1) */
|
||||
static int sgr = 1; /* Support SGR sequences (0/1) */
|
||||
static char *worddelimiters = " "; /* Word delimiters used for keybinds that change words, Space is default. */
|
||||
|
|
6
spmenu.1
6
spmenu.1
|
@ -74,6 +74,12 @@ Enable relative input width
|
|||
\f[V]-nrw, --no-relative-width\f[R]
|
||||
Disable relative input width
|
||||
.TP
|
||||
\f[V]-ix, --print-index\f[R]
|
||||
Print index instead of actual text
|
||||
.TP
|
||||
\f[V]-nix, --no-print-index\f[R]
|
||||
Don\[cq]t print index instead of actual text
|
||||
.TP
|
||||
\f[V]-f, --fast\f[R]
|
||||
Grabs keyboard before reading stdin
|
||||
.TP
|
||||
|
|
1
spmenu.c
1
spmenu.c
|
@ -164,6 +164,7 @@ struct item {
|
|||
char *ex;
|
||||
struct item *left, *right;
|
||||
int hp;
|
||||
int index;
|
||||
double distance;
|
||||
};
|
||||
|
||||
|
|
|
@ -223,6 +223,14 @@ Enable relative input width
|
|||
<dd>
|
||||
Disable relative input width
|
||||
</dd>
|
||||
<dt><code>-ix, --print-index</code></dt>
|
||||
<dd>
|
||||
Print index instead of actual text
|
||||
</dd>
|
||||
<dt><code>-nix, --no-print-index</code></dt>
|
||||
<dd>
|
||||
Don’t print index instead of actual text
|
||||
</dd>
|
||||
<dt><code>-f, --fast</code></dt>
|
||||
<dd>
|
||||
Grabs keyboard before reading stdin
|
||||
|
|
Loading…
Reference in a new issue