File src/hstr.c changed (mode: 100644) (index 946df91..aacea3a) |
... |
... |
static const char *HELP_STRING= |
119 |
119 |
"\n"; |
"\n"; |
120 |
120 |
|
|
121 |
121 |
static const char *LABEL_HELP= |
static const char *LABEL_HELP= |
122 |
|
"Type to filter, UP/DOWN to move, DEL to remove, TAB to select, C-g to cancel"; |
|
|
122 |
|
"Type to filter, UP/DOWN move, DEL remove, TAB select, C-f add favorite, C-g cancel"; |
123 |
123 |
|
|
124 |
124 |
static char **selection=NULL; |
static char **selection=NULL; |
125 |
125 |
static unsigned selectionSize=0; |
static unsigned selectionSize=0; |
|
... |
... |
void print_cmd_deleted_label(char *cmd, int occurences) |
200 |
200 |
refresh(); |
refresh(); |
201 |
201 |
} |
} |
202 |
202 |
|
|
|
203 |
|
void print_cmd_added_favorite_label(char *cmd) |
|
204 |
|
{ |
|
205 |
|
snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd); |
|
206 |
|
if(hicolor) { |
|
207 |
|
color_attr_on(COLOR_PAIR(4)); |
|
208 |
|
color_attr_on(A_BOLD); |
|
209 |
|
} |
|
210 |
|
mvprintw(Y_OFFSET_HELP, 0, screenLine); |
|
211 |
|
if(hicolor) { |
|
212 |
|
color_attr_off(A_BOLD); |
|
213 |
|
color_attr_on(COLOR_PAIR(1)); |
|
214 |
|
} |
|
215 |
|
clrtoeol(); |
|
216 |
|
refresh(); |
|
217 |
|
} |
|
218 |
|
|
203 |
219 |
void print_history_label(HistoryItems *history) |
void print_history_label(HistoryItems *history) |
204 |
220 |
{ |
{ |
205 |
221 |
int width=getmaxx(stdscr); |
int width=getmaxx(stdscr); |
206 |
|
snprintf(screenLine, width, "- HISTORY - case:%s (C-t) - view:%s (C-/) - %d/%d ", |
|
|
222 |
|
snprintf(screenLine, width, "- HISTORY - match:%s (C-t) - view:%s (C-/) - %d/%d ", |
207 |
223 |
(caseSensitive?"sensitive":"insensitive"), |
(caseSensitive?"sensitive":"insensitive"), |
208 |
224 |
HH_VIEW_LABELS[historyView], |
HH_VIEW_LABELS[historyView], |
209 |
225 |
history->count, |
history->count, |
|
... |
... |
void highlight_selection(int selectionCursorPosition, int previousSelectionCurso |
404 |
420 |
void selection_remove(char *cmd, HistoryItems *history) |
void selection_remove(char *cmd, HistoryItems *history) |
405 |
421 |
{ |
{ |
406 |
422 |
if(historyView==HH_VIEW_FAVORITES) { |
if(historyView==HH_VIEW_FAVORITES) { |
407 |
|
if(history->favorites->count) { |
|
408 |
|
|
|
409 |
|
selection must be remade & shown OR move the favorites remove code to here |
|
410 |
|
|
|
411 |
|
int i, w; |
|
412 |
|
for(i=0, w=0; i<history->count; i++) { |
|
413 |
|
if(strcmp(history->items[i], cmd)) { |
|
414 |
|
history->items[w]=history->items[i]; |
|
415 |
|
w++; |
|
416 |
|
} |
|
417 |
|
} |
|
418 |
|
history->count=w; |
|
419 |
|
|
|
420 |
|
} |
|
|
423 |
|
favorites_remove(history->favorites, cmd); |
421 |
424 |
} else { |
} else { |
422 |
425 |
if(history->count) { |
if(history->count) { |
423 |
426 |
int i, w; |
int i, w; |
|
... |
... |
void loop_to_select(HistoryItems *history) |
477 |
480 |
print_selection(get_max_history_items(stdscr), NULL, history); |
print_selection(get_max_history_items(stdscr), NULL, history); |
478 |
481 |
color_attr_off(COLOR_PAIR(HH_COLOR_NORMAL)); |
color_attr_off(COLOR_PAIR(HH_COLOR_NORMAL)); |
479 |
482 |
|
|
480 |
|
bool done=FALSE, skip=TRUE, executeResult=FALSE, lowercase=TRUE, justDeleted=FALSE; |
|
|
483 |
|
bool done=FALSE, skip=TRUE, executeResult=FALSE, lowercase=TRUE, printDefaultLabel=FALSE; |
481 |
484 |
int basex=print_prompt(stdscr); |
int basex=print_prompt(stdscr); |
482 |
485 |
int x=basex, y=0, c, cursorX=0, cursorY=0, maxHistoryItems, deleteOccurences; |
int x=basex, y=0, c, cursorX=0, cursorY=0, maxHistoryItems, deleteOccurences; |
483 |
486 |
int width=getmaxx(stdscr); |
int width=getmaxx(stdscr); |
|
... |
... |
void loop_to_select(HistoryItems *history) |
506 |
509 |
continue; |
continue; |
507 |
510 |
} |
} |
508 |
511 |
|
|
509 |
|
if(justDeleted) { |
|
|
512 |
|
if(printDefaultLabel) { |
510 |
513 |
print_help_label(); |
print_help_label(); |
511 |
|
justDeleted=FALSE; |
|
|
514 |
|
printDefaultLabel=FALSE; |
512 |
515 |
} |
} |
513 |
516 |
|
|
514 |
517 |
switch (c) { |
switch (c) { |
|
... |
... |
void loop_to_select(HistoryItems *history) |
522 |
525 |
result=print_selection(maxHistoryItems, pattern, history); |
result=print_selection(maxHistoryItems, pattern, history); |
523 |
526 |
print_cmd_deleted_label(msg, deleteOccurences); |
print_cmd_deleted_label(msg, deleteOccurences); |
524 |
527 |
move(y, basex+strlen(pattern)); |
move(y, basex+strlen(pattern)); |
525 |
|
justDeleted=TRUE; |
|
|
528 |
|
printDefaultLabel=TRUE; |
526 |
529 |
} |
} |
527 |
530 |
print_history_label(history); |
print_history_label(history); |
528 |
531 |
break; |
break; |
|
... |
... |
void loop_to_select(HistoryItems *history) |
546 |
549 |
favorites_choose(history->favorites, result); |
favorites_choose(history->favorites, result); |
547 |
550 |
} else { |
} else { |
548 |
551 |
favorites_add(history->favorites, result); |
favorites_add(history->favorites, result); |
|
552 |
|
print_cmd_added_favorite_label(result); |
|
553 |
|
printDefaultLabel=TRUE; |
549 |
554 |
} |
} |
550 |
555 |
result=print_selection(maxHistoryItems, pattern, history); |
result=print_selection(maxHistoryItems, pattern, history); |
551 |
556 |
selectionCursorPosition=0; |
selectionCursorPosition=0; |
File src/hstr_favorites.c changed (mode: 100644) (index f5bc85b..bdfd272) |
... |
... |
void favorites_get(FavoriteItems *favorites) |
82 |
82 |
} |
} |
83 |
83 |
} |
} |
84 |
84 |
|
|
|
85 |
|
void favorites_save(FavoriteItems *favorites) |
|
86 |
|
{ |
|
87 |
|
char *fileName=favorites_get_filename(); |
|
88 |
|
|
|
89 |
|
if(favorites->count) { |
|
90 |
|
FILE *output_file = fopen(fileName, "wb"); |
|
91 |
|
rewind(output_file); |
|
92 |
|
int i; |
|
93 |
|
for(i=0; i<favorites->count; i++) { |
|
94 |
|
if(fwrite(favorites->items[i], sizeof(char), strlen(favorites->items[i]), output_file)==-1) { |
|
95 |
|
exit(EXIT_FAILURE); |
|
96 |
|
} |
|
97 |
|
if(fwrite("\n", sizeof(char), strlen("\n"), output_file)==-1) { |
|
98 |
|
exit(EXIT_FAILURE); |
|
99 |
|
} |
|
100 |
|
} |
|
101 |
|
fclose(output_file); |
|
102 |
|
} else { |
|
103 |
|
if(access(fileName, F_OK) != -1) { |
|
104 |
|
FILE *output_file = fopen(fileName, "wb"); |
|
105 |
|
fclose(output_file); |
|
106 |
|
} |
|
107 |
|
} |
|
108 |
|
|
|
109 |
|
free(fileName); |
|
110 |
|
} |
|
111 |
|
|
85 |
112 |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
86 |
113 |
{ |
{ |
87 |
114 |
if(favorites->count) { |
if(favorites->count) { |
|
... |
... |
void favorites_choose(FavoriteItems *favorites, char *choice) |
118 |
145 |
favorites_save(favorites); |
favorites_save(favorites); |
119 |
146 |
} |
} |
120 |
147 |
|
|
121 |
|
int favorites_remove(FavoriteItems *favorites, char *almostDead) |
|
122 |
|
{ |
|
123 |
|
int i, j=0; |
|
124 |
|
for(i=0; i<favorites->count && j<favorites->count; i++) { |
|
125 |
|
if(j) { |
|
126 |
|
favorites->items[i]=favorites->items[j++]; |
|
127 |
|
} else { |
|
128 |
|
if(favorites->items[i] == almostDead) { |
|
129 |
|
j=i+1; |
|
130 |
|
} |
|
131 |
|
} |
|
132 |
|
} |
|
133 |
|
|
|
134 |
|
favorites_save(favorites); |
|
135 |
|
return 1; // true or false |
|
136 |
|
} |
|
137 |
|
|
|
138 |
|
void favorites_save(FavoriteItems *favorites) |
|
|
148 |
|
bool favorites_remove(FavoriteItems *favorites, char *almostDead) |
139 |
149 |
{ |
{ |
140 |
|
char *fileName=favorites_get_filename(); |
|
141 |
|
|
|
142 |
150 |
if(favorites->count) { |
if(favorites->count) { |
143 |
|
FILE *output_file = fopen(fileName, "wb"); |
|
144 |
|
rewind(output_file); |
|
145 |
|
int i; |
|
146 |
|
for(i=0; i<favorites->count; i++) { |
|
147 |
|
if(fwrite(favorites->items[i], sizeof(char), strlen(favorites->items[i]), output_file)==-1) { |
|
148 |
|
exit(EXIT_FAILURE); |
|
149 |
|
} |
|
150 |
|
if(fwrite("\n", sizeof(char), strlen("\n"), output_file)==-1) { |
|
151 |
|
exit(EXIT_FAILURE); |
|
|
151 |
|
int i, j; |
|
152 |
|
for(i=0, j=0; i<favorites->count && j<favorites->count; i++, j++) { |
|
153 |
|
if(!strcmp(favorites->items[i], almostDead)) { |
|
154 |
|
j=i+1; |
|
155 |
|
favorites->count--; |
|
156 |
|
} else { |
|
157 |
|
if(j>i) { |
|
158 |
|
favorites->items[i]=favorites->items[j]; |
|
159 |
|
} |
152 |
160 |
} |
} |
153 |
161 |
} |
} |
154 |
|
fclose(output_file); |
|
|
162 |
|
favorites_save(favorites); |
|
163 |
|
return true; |
155 |
164 |
} else { |
} else { |
156 |
|
if(access(fileName, F_OK) != -1) { |
|
157 |
|
FILE *output_file = fopen(fileName, "wb"); |
|
158 |
|
fclose(output_file); |
|
159 |
|
} |
|
|
165 |
|
return false; |
160 |
166 |
} |
} |
161 |
|
|
|
162 |
|
free(fileName); |
|
163 |
167 |
} |
} |
164 |
168 |
|
|
165 |
169 |
void favorites_destroy(FavoriteItems *favorites) |
void favorites_destroy(FavoriteItems *favorites) |