Adding highlighting of keywords matching lines.

This commit is contained in:
Martin Dvorak 2014-10-29 20:03:06 +01:00
parent f2ea910c7b
commit e0f194912c

View file

@ -452,10 +452,10 @@ unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
regmatch_t regexpMatch; regmatch_t regexpMatch;
char regexpErrorMessage[CMDLINE_LNG]; char regexpErrorMessage[CMDLINE_LNG];
bool regexpCompilationError=false; bool regexpCompilationError=false;
bool keywordsAllMatch; bool keywordsAllMatch;
char *keywordsSavePtr; char *keywordsSavePtr;
char *keywordsToken; char *keywordsToken;
char *keywordsParsedLine; char *keywordsParsedLine;
char *keywordsPointerToDelete; char *keywordsPointerToDelete;
for(i=0; i<count && selectionCount<maxSelectionCount; i++) { for(i=0; i<count && selectionCount<maxSelectionCount; i++) {
if(source[i]) { if(source[i]) {
@ -492,22 +492,21 @@ 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;
while (true) { while (true) {
keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr); keywordsToken = strtok_r(keywordsParsedLine, " ", &keywordsSavePtr);
keywordsParsedLine = NULL; keywordsParsedLine = NULL;
if (keywordsToken == NULL) { if (keywordsToken == NULL) {
break; break;
} }
if (strcasestr(source[i], keywordsToken) == NULL) { if (strcasestr(source[i], keywordsToken) == NULL) {
keywordsAllMatch = false; keywordsAllMatch = false;
} }
} }
if (keywordsAllMatch) { if (keywordsAllMatch) {
hstr->selection[selectionCount++]=source[i]; hstr->selection[selectionCount++]=source[i];
} }
free(keywordsPointerToDelete); free(keywordsPointerToDelete);
@ -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);