summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2021-04-08 23:35:32 +0200
committerpgen <p.gen.progs@gmail.com>2021-04-08 23:35:32 +0200
commit9a0889f1be9d9c946113e40ae6900ec4cd6c0819 (patch)
tree8820b6f516425a9e7c53ab69f4ad6935fd517a76
parent5f580b0d7c685276dffffabe49d768952afb10a6 (diff)
Consider spec. levels when printing searched words
Words corresponding to regular expressions introduced by the -1, -2, ... options now retain their attributes when displayed and only parts of their strings match the search sequence.
-rw-r--r--smenu.c47
-rw-r--r--tests/search/t0028.good25
l---------tests/search/t0028.in1
-rw-r--r--tests/search/t0028.tst4
4 files changed, 60 insertions, 17 deletions
diff --git a/smenu.c b/smenu.c
index 6c6f5e0..9366386 100644
--- a/smenu.c
+++ b/smenu.c
@@ -3125,11 +3125,10 @@ build_metadata(term_t * term, long count, win_t * win)
return last;
}
-/* ==================================================================== */
-/* Helper function used by disp_word to print a matching word under the */
-/* cursor when not in search mode with the matching characters of the */
-/* word highlighted. */
-/* ==================================================================== */
+/* ======================================================================= */
+/* Helper function used by disp_word to print the cursor with the matching */
+/* characters of the word highlighted. */
+/* ======================================================================= */
void
disp_cursor_word(long pos, win_t * win, term_t * term, int err)
{
@@ -3194,28 +3193,37 @@ disp_cursor_word(long pos, win_t * win, term_t * term, int err)
}
}
-/* ==================================================================== */
-/* Helper function used by disp_word to print a matching word NOT under */
-/* the cursor with the matching characters of the word highlighted. */
-/* ==================================================================== */
+/* ========================================================== */
+/* Helper function used by disp_word to print a matching word */
+/* with the matching characters of the word highlighted. */
+/* ========================================================== */
void
-disp_matching_word(long pos, win_t * win, term_t * term, int is_cursor, int err)
+disp_matching_word(long pos, win_t * win, term_t * term, int is_current,
+ int err)
{
size_t i;
int att_set = 0;
char * p = word_a[pos].str + daccess.flength;
char * np;
+ long level = 0;
+
+ level = word_a[pos].special_level;
/* Set the search cursor attribute. */
/* """""""""""""""""""""""""""""""" */
tputs(TPARM1(exit_attribute_mode), 1, outch);
- if (is_cursor)
+ if (!is_current)
{
if (err)
apply_attr(term, win->match_err_field_attr);
else
- apply_attr(term, win->match_field_attr);
+ {
+ if (level > 0)
+ apply_attr(term, win->special_attr[level - 1]);
+ else
+ apply_attr(term, win->match_field_attr);
+ }
}
else
{
@@ -3239,7 +3247,7 @@ disp_matching_word(long pos, win_t * win, term_t * term, int is_cursor, int err)
/* Set the buffer display attribute. */
/* """"""""""""""""""""""""""""""""" */
tputs(TPARM1(exit_attribute_mode), 1, outch);
- if (is_cursor)
+ if (!is_current)
{
if (err)
apply_attr(term, win->match_err_text_attr);
@@ -3262,12 +3270,17 @@ disp_matching_word(long pos, win_t * win, term_t * term, int is_cursor, int err)
/* Set the search cursor attribute. */
/* """""""""""""""""""""""""""""""" */
tputs(TPARM1(exit_attribute_mode), 1, outch);
- if (is_cursor)
+ if (!is_current)
{
if (err)
apply_attr(term, win->match_err_field_attr);
else
- apply_attr(term, win->match_field_attr);
+ {
+ if (level > 0)
+ apply_attr(term, win->special_attr[level - 1]);
+ else
+ apply_attr(term, win->match_field_attr);
+ }
}
else
{
@@ -3369,7 +3382,7 @@ disp_word(long pos, search_mode_t search_mode, search_data_t * search_data,
else
apply_attr(term, win->search_field_attr);
- disp_matching_word(pos, win, term, 0, search_data->fuzzy_err);
+ disp_matching_word(pos, win, term, 1, search_data->fuzzy_err);
}
}
else
@@ -3463,7 +3476,7 @@ disp_word(long pos, search_mode_t search_mode, search_data_t * search_data,
apply_attr(term, win->include_attr);
if (word_a[pos].is_matching)
- disp_matching_word(pos, win, term, 1, search_data->fuzzy_err);
+ disp_matching_word(pos, win, term, 0, search_data->fuzzy_err);
else
{
if (word_a[pos].is_tagged)
diff --git a/tests/search/t0028.good b/tests/search/t0028.good
new file mode 100644
index 0000000..a076f8c
--- /dev/null
+++ b/tests/search/t0028.good
@@ -0,0 +1,25 @@
+$ OUT=$(smenu -3 a -n 20 -T, t0028.in)
+
+abccb aaacc cbaba acbaa baabc cabac ccaac abaca cabac acbac bacbc cacbb acaca
+0:21 1:21 2:21 3:21 4:21 6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 30:21 31:21 32:21 33:21 34:21 36:21 37:21 38:21 39:21 40:21 42:040723 43:040723 44:040723 45:040723 46:0407 48:21 49:21 50:21 51:21 52:21 54:0423 55:0421 56:0423 57:0423 58:0423 60:21 61:21 62:21 63:21 64:21 66:21 67:21 68:21 69:21 70:21 72:21 73:21 74:21 75:21 76:21
+bbaaa aabcc acccb abacc cacac bccbc cccaa abcbc bcccc babab cacba bacbb cbcba
+0:21 1:21 2:21 3:21 4:21 6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:0423 19:0423 20:0423 21:0423 22:0421 24:21 25:21 26:21 27:21 28:21 36:21 37:21 38:21 39:21 40:21 42:21 43:21 44:21 45:21 46:21 54:21 55:21 56:21 57:21 58:21 60:21 61:21 62:21 63:21 64:21 66:21 67:21 68:21 69:21 70:21 72:21 73:21 74:21 75:21 76:21
+aaabc bcbba cabbb caaac acacb abbaa acaab ccaab caabc bcacc baabb abaca abaac
+0:21 1:21 2:21 3:21 4:21 6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 30:21 31:21 32:21 33:21 34:21 36:21 37:21 38:21 39:21 40:21 42:21 43:21 44:21 45:21 46:21 48:21 49:21 50:21 51:21 52:21 54:21 55:21 56:21 57:21 58:21 60:21 61:21 62:21 63:21 64:21 66:0423 67:0423 68:0423 69:0423 70:0421 72:0423 73:0423 74:0421 75:0423 76:0423
+cccba bccac bbcca bccac caccb cbbab cbacc cccac abaac bbbcb cbbba bcbcb acbac
+0:21 1:21 2:21 3:21 4:21 6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 30:21 31:21 32:21 33:21 34:21 36:21 37:21 38:21 39:21 40:21 42:21 43:21 44:21 45:21 46:21 48:0423 49:0423 50:0421 51:0423 52:0423 60:21 61:21 62:21 63:21 64:21 72:0423 73:0421 74:0423 75:0423 76:0423
+bcbbb caaca accbc bbccc aacca bbcbc cbbcc ccaaa aaacb caacc accaa cabab accca
+6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 24:21 25:21 26:21 27:21 28:21 42:21 43:21 44:21 45:21 46:21 48:21 49:21 50:21 51:21 52:21 54:21 55:21 56:21 57:21 58:21 60:21 61:21 62:21 63:21 64:21 66:21 67:21 68:21 69:21 70:21 72:21 73:21 74:21 75:21 76:21
+bcbbb babcc ccabb cacba abbaa cbcab caccc ababc babba ccbca abcba aabca acaac
+6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 30:21 31:21 32:21 33:21 34:21 36:21 37:21 38:21 39:21 40:21 42:0423 43:0423 44:0423 45:0421 46:0423 48:21 49:21 50:21 51:21 52:21 54:21 55:21 56:21 57:21 58:21 60:21 61:21 62:21 63:21 64:21 66:21 67:21 68:21 69:21 70:21 72:21 73:21 74:21 75:21 76:21
+accab abacc aabaa aaaca aabaa babcc acbac caacb ccbcc bbacc aabaa aabcb ccaab
+0:21 1:21 2:21 3:21 4:21 6:0423 7:0423 8:0423 9:0423 10:0421 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 30:21 31:21 32:21 33:21 34:21 36:0423 37:0421 38:0423 39:0423 40:0423 42:21 43:21 44:21 45:21 46:21 54:21 55:21 56:21 57:21 58:21 60:21 61:21 62:21 63:21 64:21 66:21 67:21 68:21 69:21 70:21 72:21 73:21 74:21 75:21 76:21
+cbbbb abcab bcaab babbc babab ccbcc accbc aabac cbaab
+6:21 7:21 8:21 9:21 10:21 12:21 13:21 14:21 15:21 16:21 18:21 19:21 20:21 21:21 22:21 24:21 25:21 26:21 27:21 28:21 36:21 37:21 38:21 39:21 40:21 42:0423 43:0421 44:0423 45:0423 46:0423 48:21 49:21 50:21 51:21 52:21
+$
+
+$ echo ":$OUT:"
+
+:abaca,acbac,abacc,abaca,abaac,abaac,acbac,ababc,abacc,acbac,aabac:
+
+$ exit 0
diff --git a/tests/search/t0028.in b/tests/search/t0028.in
new file mode 120000
index 0000000..fee93d1
--- /dev/null
+++ b/tests/search/t0028.in
@@ -0,0 +1 @@
+data2 \ No newline at end of file
diff --git a/tests/search/t0028.tst b/tests/search/t0028.tst
new file mode 100644
index 0000000..4b182d4
--- /dev/null
+++ b/tests/search/t0028.tst
@@ -0,0 +1,4 @@
+\S[150]\s[10]OUT=$(smenu -3 a -n 20 -T, t0028.in)
+\S[150]\s[150]~abac\CA\rT\r
+\S[150]\s[10]echo ":$\s[10]OUT:"
+exit 0