From 7d1b58f43111a9ef43436103b1762e76aa078021 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 24 Jul 2023 15:18:03 +0200 Subject: [PATCH] Add support for pretext This commit adds support for text that can be displayed when there's no input text (tx.text) --- docs/docs.md | 9 +++++++++ docs/spmenu.conf | 7 +++++++ libs/argv.c | 5 +++++ libs/conf/config.c | 7 +++++++ libs/draw.c | 13 +++++++++---- libs/options.h | 13 +++++++++++-- libs/schemes.c | 2 ++ libs/theme/theme.c | 15 +++++++++++++++ spmenu.1 | 9 +++++++++ 9 files changed, 74 insertions(+), 6 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index 9b66723..87c6a7b 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -226,6 +226,9 @@ in the config files. `-hpr, --hide-prompt` : Hide prompt +`-hpt, --hide-pretext` +: Hide pretext + `-hip, --hide-input` : Hide input @@ -448,6 +451,12 @@ in the config files. `-ibg, --input-background color` : Set input background color +`-ptfg, --pretext-foreground color` +: Set pretext foreground color + +`-ptbg, --pretext-background color` +: Set pretext background color + `-mnbg, --menu-background color` : Set the menu background color diff --git a/docs/spmenu.conf b/docs/spmenu.conf index 63a46df..8da5565 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -40,6 +40,7 @@ spmenu = { rightarrow = ">"; // Right arrow text (text) password = "*"; // Password character (text) prompt = ""; // Prompt text (text) + pretext = ""; // Pretext text (text) input = ""; // Input text (text) normal = "Normal"; // Normal mode text (text) insert = "Insert"; // Insert mode text (text) @@ -63,6 +64,8 @@ spmenu = { itemselpribg = "#8e93c2"; // Selected priority item background color (#RRGGBB) inputfg = "#eeeeee"; // Input foreground color (#RRGGBB) inputbg = "#110f1f"; // Input background color (#RRGGBB) + pretextfg = "#999888"; // Pretext foreground color (#RRGGBB) + pretextbg = "#110f1f"; // Pretext background color (#RRGGBB) menu = "#110f1f"; // Menu color (#RRGGBB) promptfg = "#110f1f"; // Prompt foreground color (#RRGGBB) promptbg = "#c66e5b"; // Prompt background color (#RRGGBB) @@ -119,6 +122,8 @@ spmenu = { itemselpribg = 222; // Selected priority item background alpha (0-255) inputfg = 255; // Input foreground alpha (0-255) inputbg = 222; // Input background alpha (0-255) + pretextfg = 255; // Pretext foreground alpha (0-255) + pretextbg = 222; // Pretext background alpha (0-255) menu = 222; // Menu alpha (0-255) promptfg = 255; // Prompt foreground alpha (0-255) promptbg = 222; // Prompt background alpha (0-255) @@ -156,6 +161,7 @@ spmenu = { /* Hide options */ hide = ( { input = 0; // Hide input (0/1) + pretext = 0; // Hide pretext (0/1) larrow = 0; // Hide left arrow (0/1) rarrow = 0; // Hide right arrow (0/1) items = 0; // Hide items (0/1) @@ -247,6 +253,7 @@ spmenu = { pango = ( { item = 1; // Interpret Pango markup for items (0/1) prompt = 1; // Interpret Pango markup for the prompt (0/1) input = 1; // Interpret Pango markup for the input (0/1) + pretext = 1; // Interpret Pango markup for the pretext (0/1) leftarrow = 0; // Interpret Pango markup for the left arrow (0/1) rightarrow = 0; // Interpret Pango markup for the right arrow (0/1) numbers = 0; // Interpret Pango markup for the match count (0/1) diff --git a/libs/argv.c b/libs/argv.c index f9f5e9e..1d88320 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -214,6 +214,8 @@ void readargs(int argc, char *argv[]) { hiderarrow = 0; } else if (!strcmp(argv[i], "-hpr") || (!strcmp(argv[i], "--hide-prompt"))) { // hide prompt hideprompt = 1; + } else if (!strcmp(argv[i], "-hpt") || (!strcmp(argv[i], "--hide-pretext"))) { // hide pretext + hideprompt = 1; } else if (!strcmp(argv[i], "-hpl") || (!strcmp(argv[i], "--hide-powerline"))) { // hide powerline hidepowerline = 1; } else if (!strcmp(argv[i], "-hin") || (!strcmp(argv[i], "--hide-input"))) { // hide input @@ -668,6 +670,7 @@ void usage(int status) { "spmenu -hra, --hide-right-arrow Hide right arrow\n" "spmenu -hit, --hide-item Hide items\n" "spmenu -hpr, --hide-prompt Hide prompt\n" + "spmenu -hpt, --hide-pretext Hide pretext\n" "spmenu -hip, --hide-input Hide input\n" "spmenu -hpl, --hide-powerline Hide powerline\n" "spmenu -hc, --hide-caret, --hide-cursor Hide caret\n" @@ -755,6 +758,8 @@ void usage(int status) { "spmenu -pbg, --prompt-background Set the prompt background color\n" "spmenu -ifg, --input-foreground Set input foreground color\n" "spmenu -ibg, --input-background Set input background color\n" + "spmenu -ptfg, --pretext-foreground Set pretext foreground color\n" + "spmenu -ptbg, --pretext-background Set pretext background color\n" "spmenu -mnbg, --menu-background Set the menu background color\n" "spmenu -nhf, --normal-highlight-foreground Set the normal highlight foreground color\n" "spmenu -nhb, --normal-highlight-background Set the normal highlight background color\n" diff --git a/libs/conf/config.c b/libs/conf/config.c index 412ab6f..ea72ff2 100644 --- a/libs/conf/config.c +++ b/libs/conf/config.c @@ -365,6 +365,9 @@ void conf_init(void) { if (config_setting_lookup_string(conf, "prompt", &dest)) prompt = strdup(dest); + if (config_setting_lookup_string(conf, "pretext", &dest)) + pretext = strdup(dest); + if (config_setting_lookup_string(conf, "capslockon", &dest)) capslockontext = strdup(dest); @@ -417,6 +420,8 @@ void conf_init(void) { config_setting_lookup_int(conf, "inputfg", &alpha_inputfg); // spmenu.alpha.inputfg config_setting_lookup_int(conf, "inputbg", &alpha_inputbg); // spmenu.alpha.inputbg + config_setting_lookup_int(conf, "pretextfg", &alpha_pretextfg); // spmenu.alpha.pretextfg + config_setting_lookup_int(conf, "pretextbg", &alpha_pretextbg); // spmenu.alpha.pretextbg config_setting_lookup_int(conf, "menu", &alpha_menu); // spmenu.alpha.menu @@ -777,6 +782,7 @@ void conf_init(void) { // look up config_setting_lookup_int(conf, "input", &hideinput); // spmenu.hide.input + config_setting_lookup_int(conf, "pretext", &hidepretext); // spmenu.hide.pretext config_setting_lookup_int(conf, "larrow", &hidelarrow); // spmenu.hide.larrow config_setting_lookup_int(conf, "rarrow", &hiderarrow); // spmenu.hide.rarrow config_setting_lookup_int(conf, "prompt", &hideprompt); // spmenu.hide.prompt @@ -801,6 +807,7 @@ void conf_init(void) { config_setting_lookup_int(conf, "item", &pango_item); // spmenu.pango.input config_setting_lookup_int(conf, "prompt", &pango_prompt); // spmenu.pango.rarrow config_setting_lookup_int(conf, "input", &pango_input); // spmenu.pango.input + config_setting_lookup_int(conf, "pretext", &pango_pretext); // spmenu.pango.pretext config_setting_lookup_int(conf, "leftarrow", &pango_leftarrow); // spmenu.pango.leftarrow config_setting_lookup_int(conf, "rightarrow", &pango_rightarrow); // spmenu.pango.rightarrow config_setting_lookup_int(conf, "numbers", &pango_numbers); // spmenu.pango.numbers diff --git a/libs/draw.c b/libs/draw.c index 0986f3b..6ca8de7 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -447,7 +447,7 @@ int drawprompt(int x, int y, int w) { } int drawinput(int x, int y, int w) { - char *censort; // censor text (password) + char *censort; unsigned int curpos = 0; int fh = caretheight; int fw = MAX(2, caretwidth); @@ -470,10 +470,15 @@ int drawinput(int x, int y, int w) { free(censort); } else if (!passwd) { - apply_fribidi(tx.text); - draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : tx.text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); + if (strlen(tx.text)) { + apply_fribidi(tx.text); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : tx.text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); - curpos = TEXTW(tx.text) - TEXTW(&tx.text[sp.cursor]); + curpos = TEXTW(tx.text) - TEXTW(&tx.text[sp.cursor]); + } else if (!hidepretext) { + apply_fribidi(pretext); + draw_text(draw, x + fw, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : pretext, 0, pango_pretext ? True : False, col_pretextfg, col_pretextbg, alpha_pretextfg, alpha_pretextbg); + } } if ((curpos += sp.lrpad / 2 - 1) < w && !hidecaret) { diff --git a/libs/options.h b/libs/options.h index eb91193..d31e6ec 100644 --- a/libs/options.h +++ b/libs/options.h @@ -89,6 +89,7 @@ static char *rightarrow = ">"; /* Right arrow, used to indicate y static char *password = "*"; /* Password character, when the -P argument is active this will replace all characters typed */ static char *prompt = NULL; /* Default prompt */ static char *input = NULL; /* Default input text */ +static char *pretext = NULL; /* Default pretext */ /* Match options */ static int type = 1; /* Allow typing into spmenu or only allow keybinds. */ @@ -122,6 +123,7 @@ static int caretpadding = 0; /* Caret padding (px) */ /* Hide options */ static int hideinput = 0; /* Hide input (0/1) */ +static int hidepretext = 0; /* Hide pretext (0/1) */ static int hidelarrow = 0; /* Hide left arrow (0/1) */ static int hiderarrow = 0; /* Hide right arrow (0/1) */ static int hideitem = 0; /* Hide item (0/1) */ @@ -151,8 +153,12 @@ static char col_itemselprifg[] = "#110f1f"; /* Selected foreground item static char col_itemselpribg[] = "#8e93c2"; /* Selected background item (high priority) color */ /* Input colors */ -static char col_inputbg[] = "#110f1f"; /* Input field background color */ static char col_inputfg[] = "#eeeeee"; /* Input field foreground color */ +static char col_inputbg[] = "#110f1f"; /* Input field background color */ + +/* Pretext colors */ +static char col_pretextfg[] = "#999888"; /* Pretext foreground color */ +static char col_pretextbg[] = "#110f1f"; /* Pretext background color */ /* Menu colors */ static char col_menu[] = "#110f1f"; /* Menu background color */ @@ -227,6 +233,8 @@ static int alpha_itemselprifg = 255; /* Alpha for selected priority ite static int alpha_itemselpribg = 222; /* Alpha for selected priority item background (0-255) */ static int alpha_inputfg = 255; /* Alpha for input foreground (0-255) */ static int alpha_inputbg = 222; /* Alpha for input background (0-255) */ +static int alpha_pretextfg = 255; /* Alpha for pretext foreground (0-255) */ +static int alpha_pretextbg = 222; /* Alpha for pretext background (0-255) */ static int alpha_menu = 222; /* Alpha for menu background (0-255) */ static int alpha_promptfg = 255; /* Alpha for prompt foreground (0-255) */ static int alpha_promptbg = 222; /* Alpha for prompt background (0-255) */ @@ -252,7 +260,8 @@ static int alpha_capsbg = 222; /* Alpha for the caps lock indicat static int pango_item = 1; /* Enable support for pango markup for the items */ static int pango_prompt = 1; /* Enable support for pango markup for the prompt */ static int pango_caps = 1; /* Enable support for pango markup for the caps lock indicator */ -static int pango_input = 1; /* Enable support for pango markup for user input */ +static int pango_input = 1; /* Enable support for pango markup for the user input */ +static int pango_pretext = 1; /* Enable support for pango markup for the pretext */ static int pango_leftarrow = 0; /* Enable support for pango markup for the left arrow */ static int pango_rightarrow = 0; /* Enable support for pango markup for the right arrow */ static int pango_numbers = 0; /* Enable support for pango markup for the match count */ diff --git a/libs/schemes.c b/libs/schemes.c index bbb1d4e..5201523 100644 --- a/libs/schemes.c +++ b/libs/schemes.c @@ -24,6 +24,8 @@ void init_appearance(void) { alpha_itemselpribg = 255; alpha_inputfg = 255; alpha_inputbg = 255; + alpha_pretextfg = 255; + alpha_pretextbg = 255; alpha_menu = 255; alpha_promptfg = 255; alpha_promptbg = 255; diff --git a/libs/theme/theme.c b/libs/theme/theme.c index 2baf18f..744fd7b 100644 --- a/libs/theme/theme.c +++ b/libs/theme/theme.c @@ -144,6 +144,9 @@ void theme_load(void) { if (config_setting_lookup_string(conf, "prompt", &dest)) prompt = strdup(dest); + if (config_setting_lookup_string(conf, "pretext", &dest)) + pretext = strdup(dest); + if (config_setting_lookup_string(conf, "capslockon", &dest)) capslockontext = strdup(dest); @@ -191,6 +194,9 @@ void theme_load(void) { config_setting_lookup_int(conf, "inputfg", &alpha_inputfg); // theme.alpha.inputfg config_setting_lookup_int(conf, "inputbg", &alpha_inputbg); // theme.alpha.inputbg + config_setting_lookup_int(conf, "pretextfg", &alpha_pretextfg); // theme.alpha.pretextfg + config_setting_lookup_int(conf, "pretextbg", &alpha_pretextbg); // theme.alpha.pretextbg + config_setting_lookup_int(conf, "menu", &alpha_menu); // theme.alpha.menu config_setting_lookup_int(conf, "promptfg", &alpha_promptfg); // theme.alpha.promptfg @@ -281,6 +287,13 @@ void theme_load(void) { if (config_setting_lookup_string(conf, "inputbg", &dest)) sp_strncpy(col_inputbg, strdup(dest), sizeof(col_inputbg)); + // pretext + if (config_setting_lookup_string(conf, "pretextfg", &dest)) + sp_strncpy(col_pretextfg, strdup(dest), sizeof(col_pretextfg)); + + if (config_setting_lookup_string(conf, "pretextbg", &dest)) + sp_strncpy(col_pretextbg, strdup(dest), sizeof(col_pretextbg)); + // menu if (config_setting_lookup_string(conf, "menu", &dest)) sp_strncpy(col_menu, strdup(dest), sizeof(col_menu)); @@ -438,6 +451,7 @@ void theme_load(void) { // look up config_setting_lookup_int(conf, "input", &hideinput); // theme.hide.input + config_setting_lookup_int(conf, "pretext", &hidepretext); // theme.hide.pretext config_setting_lookup_int(conf, "larrow", &hidelarrow); // theme.hide.larrow config_setting_lookup_int(conf, "rarrow", &hiderarrow); // theme.hide.rarrow config_setting_lookup_int(conf, "prompt", &hideprompt); // theme.hide.prompt @@ -462,6 +476,7 @@ void theme_load(void) { config_setting_lookup_int(conf, "item", &pango_item); // theme.pango.input config_setting_lookup_int(conf, "prompt", &pango_prompt); // theme.pango.rarrow config_setting_lookup_int(conf, "input", &pango_input); // theme.pango.input + config_setting_lookup_int(conf, "pretext", &pango_pretext); // theme.pango.pretext config_setting_lookup_int(conf, "leftarrow", &pango_leftarrow); // theme.pango.leftarrow config_setting_lookup_int(conf, "rightarrow", &pango_rightarrow); // theme.pango.rightarrow config_setting_lookup_int(conf, "numbers", &pango_numbers); // theme.pango.numbers diff --git a/spmenu.1 b/spmenu.1 index 9a7c691..f4bc605 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -254,6 +254,9 @@ Hide right arrow \f[V]-hpr, --hide-prompt\f[R] Hide prompt .TP +\f[V]-hpt, --hide-pretext\f[R] +Hide pretext +.TP \f[V]-hip, --hide-input\f[R] Hide input .TP @@ -481,6 +484,12 @@ Set input foreground color \f[V]-ibg, --input-background color\f[R] Set input background color .TP +\f[V]-ptfg, --pretext-foreground color\f[R] +Set pretext foreground color +.TP +\f[V]-ptbg, --pretext-background color\f[R] +Set pretext background color +.TP \f[V]-mnbg, --menu-background color\f[R] Set the menu background color .TP