diff options
author | pgen <p.gen.progs@gmail.com> | 2019-03-14 00:42:36 +0100 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2019-03-17 20:46:10 +0100 |
commit | 19bde1e0802685a390ceb9a2a109fdf09e5759ee (patch) | |
tree | 28d709bff3b410facfbc508b2d95357107a78e12 | |
parent | 5f28bf71537c6b632f0114d17662bdd799efb0d8 (diff) |
Allow to change the message (title) appearance
-rw-r--r-- | smenu.1 | 6 | ||||
-rw-r--r-- | smenu.c | 67 | ||||
-rw-r--r-- | smenu.h | 1 | ||||
-rw-r--r-- | tests/message/t0001.good | 2 | ||||
-rw-r--r-- | tests/message/t0003.good | 2 | ||||
-rw-r--r-- | tests/message/t0004.good | 6 | ||||
-rw-r--r-- | tests/message/t0005.good | 2 | ||||
-rw-r--r-- | tests/message/t0006.good | 4 | ||||
-rw-r--r-- | tests/message/t0006.tst | 2 | ||||
-rw-r--r-- | tests/message/t0008.good | 19 | ||||
l--------- | tests/message/t0008.in | 1 | ||||
-rw-r--r-- | tests/message/t0008.tst | 5 | ||||
-rw-r--r-- | tests/utf8/t0003.good | 2 | ||||
-rw-r--r-- | tests/utf8/t0004.good | 2 |
14 files changed, 98 insertions, 23 deletions
@@ -8,7 +8,8 @@ and outputs the selection to stdout. [\fB-n\fP [\fIlines\fP]] [\fB-t\fP [\fIcols\fP]] [\fB-k\fP] \\ [\fB-s\fP \fIpattern\fP] [\fB-m\fP \fImessage\fP] [\fB-w\fP] \\ [\fB-d\fP] [\fB-M\fP] [\fB-c\fP] [\fB-l\fP] [\fB-r\fP] [\fB-b\fP] \\ - [\fB-a\fP (i|e|c|b|s|t|ct|sf|st|mf|mt|sfe|ste|mfe|mte|da):\fIATTR\fP]... \\ + [\fB-a\fP \ +(i|e|c|b|si|m|t|ct|sf|st|mf|mt|sfe|ste|mfe|mte|da):\fIATTR\fP]... \\ [\fB-i\fP \fIregex\fP] [\fB-e\fP \fIregex\fP] \\ [\fB-C\fP \ [\fIi\fP|\fIe\fP]<col selectors>] \\ @@ -396,6 +397,7 @@ allowed: cursor=0/2 ; cursor attributes cursor_on_tag=0/2,u ; cursor on tag attributes shift=6,b ; shift symbol attributes + message=0/3 ; message (title) attributes bar = 7/4,b ; scroll bar attributes search_field = 0/6 ; search field attributes search_text = 7,bu ; search text attributes @@ -611,6 +613,8 @@ cursor. scroll bar. .IP \fIs\fP shift indicator. +.IP \fIm\fP +message (title). .IP \fIt\fP tagged words. .IP \fIct\fP @@ -165,7 +165,7 @@ short_usage(void) fprintf(stderr, " [-/ prefix|substring|fuzzy] [--] [input_file]\n\n"); fprintf(stderr, " <col selectors> ::= col1[-col2]...|<RE>...\n"); fprintf(stderr, " <row selectors> ::= row1[-row2]...|<RE>...\n"); - fprintf(stderr, " <prefix> ::= i|e|c|b|s|t|ct|sf|st|mf|mt|"); + fprintf(stderr, " <prefix> ::= i|e|c|b|s|m|t|ct|sf|st|mf|mt|"); fprintf(stderr, "sfe|ste|mfe|mte|da\n"); fprintf(stderr, " <arg> ::= [l|r:<char>]|[a:l|r]|[p:i|a]|"); fprintf(stderr, "[w:<size>]|\n"); @@ -691,6 +691,7 @@ ini_cb(win_t * win, term_t * term, limits_t * limits, timers_t * timers, CHECK_ATTR(cursor) CHECK_ATTR(bar) CHECK_ATTR(shift) + CHECK_ATTR(message) CHECK_ATTR(search_field) CHECK_ATTR(search_text) CHECK_ATTR(match_field) @@ -3527,17 +3528,18 @@ disp_message(ll_t * message_lines_list, long message_max_width, node = message_lines_list->head; buf = xmalloc(message_max_len + 1); - if (term->has_bold) - tputs(TPARM1(enter_bold_mode), 1, outch); - /* Follow the message lines list and display each line */ /* """"""""""""""""""""""""""""""""""""""""""""""""""" */ while (node != NULL) { + long i; + line = node->data; len = utf8_strlen(line); w = utf8_strtowcs(line); + /* Adjust size and len if the terminal is not large enough */ + /* """"""""""""""""""""""""""""""""""""""""""""""""""""""" */ size = wcswidth(w, len); while (len > 0 && size > term->ncolumns) size = wcswidth(w, --len); @@ -3549,24 +3551,38 @@ disp_message(ll_t * message_lines_list, long message_max_width, offset = (term->ncolumns - message_max_width - 3) / 2; if (win->center && offset > 0) - { - long i; - for (i = 0; i < offset; i++) fputc(' ', stdout); - } + + apply_attr(term, win->message_attr); /* Only print the start of a line if the screen width if too small */ /* """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */ utf8_strprefix(buf, line, len, &size); - puts(buf); + + /* Print the line without the ending \n */ + /* '''''''''''''''''''''''''''''''''''' */ + printf("%s", buf); + + /* Complete the short line with spaces until it reach the */ + /* message max size */ + /* '''''''''''''''''''''''''''''''''''''''''''''''''''''' */ + for (i = size; i < message_max_width; i++) + { + if (i + (offset < 0 ? 0 : offset) >= term->ncolumns) + break; + fputc(' ', stdout); + } + + /* Drop the attributes and print a \n */ + /* '''''''''''''''''''''''''''''''''' */ + tputs(TPARM1(exit_attribute_mode), 1, outch); + puts(""); node = node->next; win->message_lines++; } - tputs(TPARM1(exit_attribute_mode), 1, outch); - free(buf); /* Re-arm the periodic timer */ @@ -5086,6 +5102,7 @@ main(int argc, char * argv[]) win.cursor_on_tag_attr = init_attr; win.bar_attr = init_attr; win.shift_attr = init_attr; + win.message_attr = init_attr; win.search_field_attr = init_attr; win.search_text_attr = init_attr; win.search_err_field_attr = init_attr; @@ -5644,6 +5661,7 @@ main(int argc, char * argv[]) int cur_attr_set = 0; /* highlighted word (cursor) */ int bar_attr_set = 0; /* scroll bar */ int shift_attr_set = 0; /* hor. scrolling arrows */ + int message_attr_set = 0; /* message (title) */ int tag_attr_set = 0; /* selected (tagged) words */ int cursor_on_tag_attr_set = 0; /* selected words under the cursor */ int sf_attr_set = 0; /* currently searched field color */ @@ -5674,6 +5692,8 @@ main(int argc, char * argv[]) &bar_attr_set, "b:", 2 }, { &win.shift_attr, "The shift attribute is already set -- ", &shift_attr_set, "s:", 2 }, + { &win.message_attr, "The message attribute is already set -- ", + &message_attr_set, "m:", 2 }, { &win.tag_attr, "The tag attribute is already set -- ", &tag_attr_set, "t:", 2 }, { &win.cursor_on_tag_attr, @@ -6482,6 +6502,21 @@ main(int argc, char * argv[]) win.shift_attr.is_set = SET; } + if (!win.message_attr.is_set) + { + if (term.has_bold) + win.message_attr.bold = 1; + else if (term.has_reverse) + win.message_attr.reverse = 1; + else + { + win.message_attr.fg = 0; + win.message_attr.bg = 7; + } + + win.message_attr.is_set = SET; + } + if (!win.search_field_attr.is_set) { win.search_field_attr.bg = 5; @@ -6610,6 +6645,16 @@ main(int argc, char * argv[]) win.shift_attr.is_set = SET; } + if (!win.message_attr.is_set) + { + if (term.has_bold) + win.message_attr.bold = 1; + else if (term.has_reverse) + win.message_attr.reverse = 1; + + win.message_attr.is_set = SET; + } + if (!win.search_field_attr.is_set) { if (term.has_reverse) @@ -512,6 +512,7 @@ struct win_s attr_t cursor_on_tag_attr; /* current cursor on tag attributes */ attr_t bar_attr; /* scrollbar attributes */ attr_t shift_attr; /* shift indicator attributes */ + attr_t message_attr; /* message (title) attributes */ attr_t search_field_attr; /* search mode field attributes */ attr_t search_text_attr; /* search mode text attributes */ attr_t search_err_field_attr; /* bad search mode field attributes */ diff --git a/tests/message/t0001.good b/tests/message/t0001.good index 157cbea..0f98a08 100644 --- a/tests/message/t0001.good +++ b/tests/message/t0001.good @@ -1,7 +1,7 @@ $ OUT=$(smenu -m xx -n 10 -M t0001.in) xx -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 +37:01 38:01 1 2 3 4 5 6 7 8 9 10 36:07 $ diff --git a/tests/message/t0003.good b/tests/message/t0003.good index 74cec74..b81d6f0 100644 --- a/tests/message/t0003.good +++ b/tests/message/t0003.good @@ -1,7 +1,7 @@ $ OUT=$(smenu -M -l -m test t0003.in) test -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 +36:01 37:01 38:01 39:01 123456789 123456789 123456789 123456789 123456789 123456789 123456789→ 0:01 1:07 2:07 3:07 4:07 5:07 6:07 7:07 8:07 9:07 70:01 $ diff --git a/tests/message/t0004.good b/tests/message/t0004.good index 4aceaf4..26ff664 100644 --- a/tests/message/t0004.good +++ b/tests/message/t0004.good @@ -2,10 +2,10 @@ $ OUT=$(smenu -M -m 'xx > yyyy' t0004.in) - xx -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 + xx +36:01 37:01 38:01 39:01 yyyy -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 +36:01 37:01 38:01 39:01 1 2 3 4 5 6 7 8 9 10 28:07 $ diff --git a/tests/message/t0005.good b/tests/message/t0005.good index 190cb51..97f3916 100644 --- a/tests/message/t0005.good +++ b/tests/message/t0005.good @@ -1,7 +1,7 @@ $ OUT=$(smenu -M -m yyyy t0005.in) yyyy -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 +36:01 37:01 38:01 39:01 1 2 3 4 5 6 7 8 9 10 28:07 $ diff --git a/tests/message/t0006.good b/tests/message/t0006.good index 4e60200..216d6f9 100644 --- a/tests/message/t0006.good +++ b/tests/message/t0006.good @@ -1,9 +1,9 @@ -$ OUT=$(smenu -M -m "123456789 123456789 123456789 123456789 \ +$ OUT=$(smenu -a m:r -M -m "123456789 123456789 123456789 123456789 \ > 123456789 123456789 123456789 123456789 123456789" t0006.in) 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 40:01 41:01 42:01 43:01 44:01 45:01 46:01 47:01 48:01 49:01 50:01 51:01 52:01 53:01 54:01 55:01 56:01 57:01 58:01 59:01 60:01 61:01 62:01 63:01 64:01 65:01 66:01 67:01 68:01 69:01 70:01 71:01 72:01 73:01 74:01 75:01 76:01 77:01 78:01 79:01 +0:07 1:07 2:07 3:07 4:07 5:07 6:07 7:07 8:07 9:07 10:07 11:07 12:07 13:07 14:07 15:07 16:07 17:07 18:07 19:07 20:07 21:07 22:07 23:07 24:07 25:07 26:07 27:07 28:07 29:07 30:07 31:07 32:07 33:07 34:07 35:07 36:07 37:07 38:07 39:07 40:07 41:07 42:07 43:07 44:07 45:07 46:07 47:07 48:07 49:07 50:07 51:07 52:07 53:07 54:07 55:07 56:07 57:07 58:07 59:07 60:07 61:07 62:07 63:07 64:07 65:07 66:07 67:07 68:07 69:07 70:07 71:07 72:07 73:07 74:07 75:07 76:07 77:07 78:07 79:07 1 2 3 4 5 6 7 8 9 10 28:07 $ diff --git a/tests/message/t0006.tst b/tests/message/t0006.tst index 6ca61b6..039db5f 100644 --- a/tests/message/t0006.tst +++ b/tests/message/t0006.tst @@ -1,4 +1,4 @@ -\S[150]\s[10]OUT=$(smenu -M -m "123456789 123456789 123456789 123456789 \\ +\S[150]\s[10]OUT=$(smenu -a m:r -M -m "123456789 123456789 123456789 123456789 \\ 123456789 123456789 123456789 123456789 123456789" t0006.in) \S[150]\s[150]\r \S[150]\s[10]echo ":$\s[10]OUT:" diff --git a/tests/message/t0008.good b/tests/message/t0008.good new file mode 100644 index 0000000..b958f7a --- /dev/null +++ b/tests/message/t0008.good @@ -0,0 +1,19 @@ +$ OUT=$(smenu -a m:7/5 -M \ + +> -m '=\uefbcb4\uefbca5\uefbcb3\uefbcb4= + +> =test=' t0008.in) + + =TEST= +33:252d 34:252d 35:252d 36:252d 37:252d 38:252d + =test= +33:252d 34:252d 35:252d 36:252d 37:252d 38:252d 39:252d 40:252d 41:252d 42:252d + 1 2 3 4 5 6 7 8 9 10 +28:07 +$ + +$ echo ":$OUT:" + +:1: + +$ exit 0 diff --git a/tests/message/t0008.in b/tests/message/t0008.in new file mode 120000 index 0000000..0abc8f1 --- /dev/null +++ b/tests/message/t0008.in @@ -0,0 +1 @@ +data1
\ No newline at end of file diff --git a/tests/message/t0008.tst b/tests/message/t0008.tst new file mode 100644 index 0000000..5ee3bd2 --- /dev/null +++ b/tests/message/t0008.tst @@ -0,0 +1,5 @@ +\S[150]\s[10]OUT=$(smenu -a m:7/5 -M \\ +-m '=\\uefbcb4\\uefbca5\\uefbcb3\\uefbcb4=\n=test=' t0008.in) +\S[150]\s[150]\r +\S[150]\s[10]echo ":$\s[10]OUT:" +exit 0 diff --git a/tests/utf8/t0003.good b/tests/utf8/t0003.good index 0e24b6f..4c3237e 100644 --- a/tests/utf8/t0003.good +++ b/tests/utf8/t0003.good @@ -1,7 +1,7 @@ $ OUT=$(LC_ALL=C smenu -M -m «←→» t0003.in) .... -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 +36:01 37:01 38:01 39:01 ... ... ... 33:07 34:07 35:07 $ diff --git a/tests/utf8/t0004.good b/tests/utf8/t0004.good index 90f8fde..7054993 100644 --- a/tests/utf8/t0004.good +++ b/tests/utf8/t0004.good @@ -1,7 +1,7 @@ $ OUT=$(LC_ALL=en_US.UTF-8 smenu -M -m «←→» t0003.in) «←→» -0:01 1:01 2:01 3:01 4:01 5:01 6:01 7:01 8:01 9:01 10:01 11:01 12:01 13:01 14:01 15:01 16:01 17:01 18:01 19:01 20:01 21:01 22:01 23:01 24:01 25:01 26:01 27:01 28:01 29:01 30:01 31:01 32:01 33:01 34:01 35:01 36:01 37:01 38:01 39:01 +36:01 37:01 38:01 39:01 éé€ éé€ é€é 33:07 34:07 35:07 $ |