This commit is contained in:
Thibault Charbonnier 2024-02-25 14:13:10 -07:00 committed by GitHub
commit d58b72ceef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 15 deletions

View file

@ -854,8 +854,8 @@ unsigned hstr_make_selection(char* prefix, HistoryItems* history, unsigned maxSe
count=history->rawCount;
break;
case HSTR_VIEW_FAVORITES:
source=hstr->favorites->items;
count=hstr->favorites->count;
source=hstr->favorites->itemsView;
count=hstr->favorites->countView;
break;
case HSTR_VIEW_RANKING:
default:

View file

@ -22,6 +22,8 @@
void favorites_init(FavoriteItems* favorites)
{
favorites->itemsView=NULL;
favorites->countView=0;
favorites->items=NULL;
favorites->count=0;
favorites->loaded=false;
@ -83,18 +85,26 @@ void favorites_get(FavoriteItems* favorites)
}
favorites->items = malloc(sizeof(char*) * favorites->count);
favorites->itemsView = malloc(sizeof(char*) * favorites->count);
favorites->count = 0;
char* pb=fileContent, *pe, *s;
pe=strchr(fileContent, '\n');
while(pe!=NULL) {
*pe=0;
if(!hashset_contains(favorites->set,pb)) {
if(!favorites->skipComments || !(strlen(pb) && pb[0]=='#')) {
s=hstr_strdup(pb);
favorites->items[favorites->count++]=s;
hashset_add(favorites->set,s);
}
if(!strlen(pb)) {
goto next;
}
s=hstr_strdup(pb);
favorites->items[favorites->count++]=s;
if(pb[0]=='#' && favorites->skipComments) {
goto next;
}
if(!hashset_contains(favorites->set,pb)) {
s=hstr_strdup(pb);
favorites->itemsView[favorites->countView++]=s;
hashset_add(favorites->set,s);
}
next:
pb=pe+1;
pe=strchr(pb, '\n');
}
@ -206,7 +216,11 @@ void favorites_destroy(FavoriteItems* favorites)
for(i=0; i<favorites->count; i++) {
free(favorites->items[i]);
}
for(i=0; i<favorites->countView; i++) {
free(favorites->itemsView[i]);
}
free(favorites->items);
free(favorites->itemsView);
hashset_destroy(favorites->set, false);
free(favorites->set);
free(favorites);

View file

@ -21,13 +21,6 @@
#include <getopt.h>
#include <locale.h>
#ifdef __APPLE__
#include <curses.h>
#elif defined(__FreeBSD__)
#include <ncurses.h>
#else
#include <ncursesw/curses.h>
#endif
#include <readline/chardefs.h>
#include <signal.h>
#include <termios.h>

View file

@ -27,7 +27,9 @@
typedef struct {
char** items;
char** itemsView;
unsigned count;
unsigned countView;
bool loaded;
bool reorderOnChoice;
bool skipComments;