diff --git a/docs/docs.md b/docs/docs.md index d9314b0..55d7a4b 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -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 diff --git a/docs/example.Xresources b/docs/example.Xresources index 539a068..6626af6 100644 --- a/docs/example.Xresources +++ b/docs/example.Xresources @@ -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 diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 8d0436c..fc21e7c 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -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) diff --git a/libs/arg.c b/libs/arg.c index 8bfd66d..e718381 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -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 { diff --git a/libs/argv.c b/libs/argv.c index 278ce62..1e805ae 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -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 Set max image cache size to \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" diff --git a/libs/conf/config.c b/libs/conf/config.c index d712e99..688a7c9 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -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) { diff --git a/libs/stream.c b/libs/stream.c index 6de24c3..25c912e 100644 --- a/libs/stream.c +++ b/libs/stream.c @@ -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:"))) { diff --git a/libs/xresources.h b/libs/xresources.h index a4ca613..e3019f1 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -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 }, diff --git a/options.h b/options.h index e3d5a54..09f28ee 100644 --- a/options.h +++ b/options.h @@ -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. */ diff --git a/spmenu.1 b/spmenu.1 index 21c19aa..ada2d1a 100644 --- a/spmenu.1 +++ b/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 diff --git a/spmenu.c b/spmenu.c index 2d7aebc..3b17ba4 100644 --- a/spmenu.c +++ b/spmenu.c @@ -164,6 +164,7 @@ struct item { char *ex; struct item *left, *right; int hp; + int index; double distance; }; diff --git a/spmenu.html b/spmenu.html index 31170ed..dff1b87 100644 --- a/spmenu.html +++ b/spmenu.html @@ -223,6 +223,14 @@ Enable relative input 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