File src/hstr.c changed (mode: 100644) (index 26e21e2..374c4d5) |
38 |
38 |
|
|
39 |
39 |
#define K_CTRL_A 1 |
#define K_CTRL_A 1 |
40 |
40 |
#define K_CTRL_E 5 |
#define K_CTRL_E 5 |
|
41 |
|
#define K_CTRL_F 6 |
41 |
42 |
#define K_CTRL_G 7 |
#define K_CTRL_G 7 |
42 |
43 |
#define K_CTRL_H 8 |
#define K_CTRL_H 8 |
43 |
44 |
#define K_CTRL_L 12 |
#define K_CTRL_L 12 |
|
... |
... |
unsigned make_selection(char *prefix, HistoryItems *history, int maxSelectionCou |
258 |
259 |
count=history->rawCount; |
count=history->rawCount; |
259 |
260 |
break; |
break; |
260 |
261 |
case HH_VIEW_FAVORITES: |
case HH_VIEW_FAVORITES: |
261 |
|
source=history->favorites; |
|
262 |
|
count=history->favoritesCount; |
|
|
262 |
|
source=history->favorites->items; |
|
263 |
|
count=history->favorites->count; |
263 |
264 |
break; |
break; |
264 |
265 |
} |
} |
265 |
266 |
|
|
|
... |
... |
void loop_to_select(HistoryItems *history) |
497 |
498 |
print_history_label(history); |
print_history_label(history); |
498 |
499 |
selectionCursorPosition=0; |
selectionCursorPosition=0; |
499 |
500 |
break; |
break; |
|
501 |
|
case K_CTRL_F: |
|
502 |
|
if(selectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) { |
|
503 |
|
result=selection[selectionCursorPosition]; |
|
504 |
|
|
|
505 |
|
if(historyView==HH_VIEW_FAVORITES) { |
|
506 |
|
favorites_choose(history->favorites, result); |
|
507 |
|
} else { |
|
508 |
|
favorites_add(history->favorites, result); |
|
509 |
|
} |
|
510 |
|
result=print_selection(maxHistoryItems, pattern, history); |
|
511 |
|
selectionCursorPosition=0; |
|
512 |
|
} |
|
513 |
|
break; |
500 |
514 |
case KEY_RESIZE: |
case KEY_RESIZE: |
501 |
515 |
print_history_label(history); |
print_history_label(history); |
502 |
516 |
result=print_selection(maxHistoryItems, pattern, history); |
result=print_selection(maxHistoryItems, pattern, history); |
File src/hstr_favorites.c changed (mode: 100644) (index 1dbfd81..905ee57) |
7 |
7 |
============================================================================ |
============================================================================ |
8 |
8 |
*/ |
*/ |
9 |
9 |
|
|
|
10 |
|
#include <stdbool.h> |
10 |
11 |
#include <string.h> |
#include <string.h> |
11 |
12 |
#include "include/hstr_favorites.h" |
#include "include/hstr_favorites.h" |
12 |
13 |
|
|
|
... |
... |
void favorites_load(FavoriteItems *favorites) |
31 |
32 |
|
|
32 |
33 |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
33 |
34 |
{ |
{ |
34 |
|
favorites->items=realloc(favorites->items, sizeof(char *)*favorites->count); |
|
35 |
|
favorites->items[favorites->count++]=newFavorite; |
|
|
35 |
|
favorites->items=realloc(favorites->items, sizeof(char *) * ++favorites->count); |
|
36 |
|
favorites->items[favorites->count-1]=newFavorite; |
|
37 |
|
|
|
38 |
|
favorites_choose(favorites, newFavorite); |
|
39 |
|
favorites_save(favorites); |
|
40 |
|
} |
|
41 |
|
|
|
42 |
|
void favorites_choose(FavoriteItems *favorites, char *choice) |
|
43 |
|
{ |
|
44 |
|
if(favorites->count && choice) { |
|
45 |
|
int i; |
|
46 |
|
char *b=0, *next; |
|
47 |
|
for(i=0; i<favorites->count; i++) { |
|
48 |
|
if(!strcmp(favorites->items[i],choice)) { |
|
49 |
|
favorites->items[0]=favorites->items[i]; |
|
50 |
|
if(b) { |
|
51 |
|
favorites->items[i]=b; |
|
52 |
|
} |
|
53 |
|
return; |
|
54 |
|
} |
|
55 |
|
next=favorites->items[i]; |
|
56 |
|
favorites->items[i]=b; |
|
57 |
|
b=next; |
|
58 |
|
} |
|
59 |
|
} |
|
60 |
|
favorites_save(favorites); |
|
61 |
|
} |
|
62 |
|
|
|
63 |
|
void favorites_remove(FavoriteItems *favorites, char *almostDead) |
|
64 |
|
{ |
|
65 |
|
// TODO: keept slot you have, just change count |
36 |
66 |
|
|
37 |
67 |
favorites_save(favorites); |
favorites_save(favorites); |
38 |
68 |
} |
} |
|
... |
... |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
40 |
70 |
void favorites_save(FavoriteItems *favorites) |
void favorites_save(FavoriteItems *favorites) |
41 |
71 |
{ |
{ |
42 |
72 |
} |
} |
|
73 |
|
|
|
74 |
|
void favorites_destroy(FavoriteItems *favorites) |
|
75 |
|
{ |
|
76 |
|
if(favorites) { |
|
77 |
|
int i; |
|
78 |
|
for(i=0; i<favorites->count; i++) { |
|
79 |
|
free(favorites->items[i]); |
|
80 |
|
} |
|
81 |
|
free(favorites); |
|
82 |
|
} |
|
83 |
|
} |
File src/hstr_history.c changed (mode: 100644) (index 2d4b2ca..536292f) |
11 |
11 |
#include <limits.h> |
#include <limits.h> |
12 |
12 |
#include <readline/history.h> |
#include <readline/history.h> |
13 |
13 |
#include "include/hstr_history.h" |
#include "include/hstr_history.h" |
14 |
|
#include "include/hstr_favorites.h" |
|
15 |
14 |
|
|
16 |
15 |
#define NDEBUG |
#define NDEBUG |
17 |
16 |
#include <assert.h> |
#include <assert.h> |
|
... |
... |
HistoryItems *get_prioritized_history() |
152 |
151 |
radixsort_destroy(&rs); |
radixsort_destroy(&rs); |
153 |
152 |
|
|
154 |
153 |
|
|
155 |
|
FavoriteItems favoriteItems; |
|
156 |
|
favorites_init(&favoriteItems); |
|
157 |
|
favorites_load(&favoriteItems); |
|
158 |
|
prioritizedHistory->favorites=favoriteItems.items; |
|
159 |
|
prioritizedHistory->favoritesCount=favoriteItems.count; |
|
|
154 |
|
FavoriteItems *favoriteItems=malloc(sizeof(FavoriteItems)); |
|
155 |
|
favorites_init(favoriteItems); |
|
156 |
|
favorites_load(favoriteItems); |
|
157 |
|
prioritizedHistory->favorites=favoriteItems; |
160 |
158 |
|
|
161 |
159 |
return prioritizedHistory; |
return prioritizedHistory; |
162 |
160 |
} else { |
} else { |
|
... |
... |
HistoryItems *get_prioritized_history() |
167 |
165 |
void free_prioritized_history() |
void free_prioritized_history() |
168 |
166 |
{ |
{ |
169 |
167 |
free(prioritizedHistory->items); |
free(prioritizedHistory->items); |
170 |
|
if(prioritizedHistory->favorites) { |
|
171 |
|
int i; |
|
172 |
|
for(i=0; i<prioritizedHistory->favoritesCount; i++) { |
|
173 |
|
free(prioritizedHistory->favorites[i]); |
|
174 |
|
} |
|
175 |
|
free(prioritizedHistory->favorites); |
|
176 |
|
} |
|
|
168 |
|
favorites_destroy(prioritizedHistory->favorites); |
177 |
169 |
free(prioritizedHistory); |
free(prioritizedHistory); |
178 |
170 |
} |
} |
179 |
171 |
|
|
File src/include/hstr_favorites.h changed (mode: 100644) (index d6aeb6e..b134f9f) |
... |
... |
typedef struct { |
22 |
22 |
void favorites_init(FavoriteItems *favorites); |
void favorites_init(FavoriteItems *favorites); |
23 |
23 |
void favorites_load(FavoriteItems *favorites); |
void favorites_load(FavoriteItems *favorites); |
24 |
24 |
void favorites_add(FavoriteItems *favorites, char *favorite); |
void favorites_add(FavoriteItems *favorites, char *favorite); |
|
25 |
|
void favorites_choose(FavoriteItems *favorites, char *choice); |
|
26 |
|
void favorites_remove(FavoriteItems *favorites, char *almostDead); |
25 |
27 |
void favorites_save(FavoriteItems *favorites); |
void favorites_save(FavoriteItems *favorites); |
|
28 |
|
void favorites_destroy(FavoriteItems *favorites); |
26 |
29 |
|
|
27 |
30 |
#endif |
#endif |