mirror of
https://github.com/dvorka/hstr.git
synced 2025-01-04 14:12:01 +08:00
Adding highlighting of keywords matching lines.
This commit is contained in:
parent
f2ea910c7b
commit
e0f194912c
1 changed files with 28 additions and 11 deletions
25
src/hstr.c
25
src/hstr.c
|
@ -492,7 +492,7 @@ unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
|
|||
}
|
||||
break;
|
||||
case HH_MATCH_KEYWORDS:
|
||||
// TODO: differentiate between case-sensitive and insensitive
|
||||
// TODO differentiate between case-sensitive and insensitive
|
||||
keywordsParsedLine = strdup(prefix);
|
||||
keywordsAllMatch = true;
|
||||
keywordsPointerToDelete = keywordsParsedLine;
|
||||
|
@ -502,7 +502,6 @@ unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
|
|||
if (keywordsToken == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (strcasestr(source[i], keywordsToken) == NULL) {
|
||||
keywordsAllMatch = false;
|
||||
}
|
||||
|
@ -561,6 +560,11 @@ void print_selection_row(char *text, int y, int width, char *pattern)
|
|||
if(pattern && strlen(pattern)) {
|
||||
color_attr_on(A_BOLD);
|
||||
char *p;
|
||||
bool keywordsAllMatch;
|
||||
char *keywordsSavePtr;
|
||||
char *keywordsToken;
|
||||
char *keywordsParsedLine;
|
||||
char *keywordsPointerToDelete;
|
||||
|
||||
switch(hstr->historyMatch) {
|
||||
case HH_MATCH_SUBSTRING:
|
||||
|
@ -581,8 +585,21 @@ void print_selection_row(char *text, int y, int width, char *pattern)
|
|||
mvprintw(y, 1+(p-text), "%s", pattern);
|
||||
break;
|
||||
case HH_MATCH_KEYWORDS:
|
||||
p=strstr(text, pattern);
|
||||
mvprintw(y, 1+(p-text), "%s", pattern);
|
||||
// TODO MD split pattern using space and highlight each segment
|
||||
keywordsParsedLine = strdup(pattern);
|
||||
keywordsAllMatch = true;
|
||||
keywordsPointerToDelete = keywordsParsedLine;
|
||||
while (true) {
|
||||
keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr);
|
||||
keywordsParsedLine = NULL;
|
||||
if (keywordsToken == NULL) {
|
||||
break;
|
||||
}
|
||||
p=strstr(text, keywordsToken);
|
||||
mvprintw(y, 1+(p-text), "%s", keywordsToken);
|
||||
}
|
||||
free(keywordsPointerToDelete);
|
||||
|
||||
break;
|
||||
}
|
||||
color_attr_off(A_BOLD);
|
||||
|
|
Loading…
Reference in a new issue