tSearch directly for string in text UI - sacc - sacc (saccomys): simple gopher … | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 859b7150efb9e4ae7b0040a36a8e337f36062f48 | |
parent 65bb62ab632f7bbc5eda03595ca58d0f67805ae6 | |
Author: Quentin Rameau <[email protected]> | |
Date: Mon, 23 Oct 2017 19:25:36 +0200 | |
Search directly for string in text UI | |
Diffstat: | |
ui_txt.c | 17 ++++++++++------- | |
1 file changed, 10 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/ui_txt.c b/ui_txt.c | |
t@@ -171,7 +171,7 @@ searchinline(const char *searchstr, Item *entry) | |
Dir *dir; | |
size_t i; | |
- if (!(dir = entry->dat)) | |
+ if (!searchstr || !*searchstr || !(dir = entry->dat)) | |
return; | |
for (i = 0; i < dir->nitems; ++i) | |
t@@ -184,7 +184,7 @@ uiselectitem(Item *entry) | |
{ | |
Dir *dir; | |
static char c; | |
- char buf[BUFSIZ], nl, *searchstr; | |
+ char buf[BUFSIZ], *sstr, nl; | |
int item, nitems, lines; | |
if (!entry || !(dir = entry->dat)) | |
t@@ -210,6 +210,12 @@ uiselectitem(Item *entry) | |
} else if (!strcmp(buf+1, "\n")) { | |
item = -1; | |
c = *buf; | |
+ } else if (*buf == '/') { | |
+ for (sstr = buf+1; *sstr && *sstr != '\n'; ++sstr) | |
+ ; | |
+ *sstr = '\0'; | |
+ sstr = buf+1; | |
+ c = *buf; | |
} else if (isdigit(*(buf+1))) { | |
nl = '\0'; | |
if (sscanf(buf+1, "%d%c", &item, &nl) != 2 || nl != '\… | |
t@@ -255,11 +261,8 @@ uiselectitem(Item *entry) | |
printuri(&dir->items[item-1], item); | |
continue; | |
case '/': | |
- if ((searchstr = uiprompt("Search for: ")) && | |
- searchstr[0]) | |
- searchinline(searchstr, entry); | |
- free(searchstr); | |
- searchstr = NULL; | |
+ if (*sstr) | |
+ searchinline(sstr, entry); | |
continue; | |
case 'h': | |
case '?': |