mirror of
https://github.com/dvorka/hstr.git
synced 2025-01-06 15:08:13 +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;
|
break;
|
||||||
case HH_MATCH_KEYWORDS:
|
case HH_MATCH_KEYWORDS:
|
||||||
// TODO: differentiate between case-sensitive and insensitive
|
// TODO differentiate between case-sensitive and insensitive
|
||||||
keywordsParsedLine = strdup(prefix);
|
keywordsParsedLine = strdup(prefix);
|
||||||
keywordsAllMatch = true;
|
keywordsAllMatch = true;
|
||||||
keywordsPointerToDelete = keywordsParsedLine;
|
keywordsPointerToDelete = keywordsParsedLine;
|
||||||
|
@ -502,7 +502,6 @@ unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
|
||||||
if (keywordsToken == NULL) {
|
if (keywordsToken == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasestr(source[i], keywordsToken) == NULL) {
|
if (strcasestr(source[i], keywordsToken) == NULL) {
|
||||||
keywordsAllMatch = false;
|
keywordsAllMatch = false;
|
||||||
}
|
}
|
||||||
|
@ -561,6 +560,11 @@ void print_selection_row(char *text, int y, int width, char *pattern)
|
||||||
if(pattern && strlen(pattern)) {
|
if(pattern && strlen(pattern)) {
|
||||||
color_attr_on(A_BOLD);
|
color_attr_on(A_BOLD);
|
||||||
char *p;
|
char *p;
|
||||||
|
bool keywordsAllMatch;
|
||||||
|
char *keywordsSavePtr;
|
||||||
|
char *keywordsToken;
|
||||||
|
char *keywordsParsedLine;
|
||||||
|
char *keywordsPointerToDelete;
|
||||||
|
|
||||||
switch(hstr->historyMatch) {
|
switch(hstr->historyMatch) {
|
||||||
case HH_MATCH_SUBSTRING:
|
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);
|
mvprintw(y, 1+(p-text), "%s", pattern);
|
||||||
break;
|
break;
|
||||||
case HH_MATCH_KEYWORDS:
|
case HH_MATCH_KEYWORDS:
|
||||||
p=strstr(text, pattern);
|
// TODO MD split pattern using space and highlight each segment
|
||||||
mvprintw(y, 1+(p-text), "%s", pattern);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
color_attr_off(A_BOLD);
|
color_attr_off(A_BOLD);
|
||||||
|
|
Loading…
Reference in a new issue