xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit d1cdbad2cb9969ceb521c0cc39148be906fae697

Fixed #145 and fixed #146 by changing color scheme to work for both black/white background terminals + removed inverse highlighting for monochromatic color scheme to make it readable again.
Author: Martin Dvorak
Author date (UTC): 2015-05-09 19:28
Committer name: Martin Dvorak
Committer date (UTC): 2015-05-09 19:28
Parent(s): 07ec0dc65835b9ac5769fb7aa88ed5685d9beabc
Signing key:
Tree: c3d6362444cf96c1c77c3279b4dcb25882e71f72
File Lines added Lines deleted
src/hstr.c 39 37
File src/hstr.c changed (mode: 100644) (index e57f6ff..f33c624)
75 75 #define K_BACKSPACE 127 #define K_BACKSPACE 127
76 76 #define K_ENTER 10 #define K_ENTER 10
77 77
78 #define HH_THEME_MONO 0
79 #define HH_THEME_COLOR 1<<7
80 #define HH_THEME_LIGHT 1|HH_THEME_COLOR
81 #define HH_THEME_DARK 2|HH_THEME_COLOR
82
78 83 #define HH_COLOR_NORMAL 1 #define HH_COLOR_NORMAL 1
79 84 #define HH_COLOR_HIROW 2 #define HH_COLOR_HIROW 2
80 85 #define HH_COLOR_INFO 2 #define HH_COLOR_INFO 2
 
85 90 #define HH_ENV_VAR_CONFIG "HH_CONFIG" #define HH_ENV_VAR_CONFIG "HH_CONFIG"
86 91 #define HH_ENV_VAR_PROMPT "HH_PROMPT" #define HH_ENV_VAR_PROMPT "HH_PROMPT"
87 92
88 #define HH_CONFIG_MONO "monochromatic"
89 #define HH_CONFIG_HICOLOR "hicolor"
93 #define HH_CONFIG_THEME_MONOCHROMATIC "monochromatic"
94 #define HH_CONFIG_THEME_HICOLOR "hicolor"
90 95 #define HH_CONFIG_CASE "casesensitive" #define HH_CONFIG_CASE "casesensitive"
91 96 #define HH_CONFIG_REGEXP "regexp" #define HH_CONFIG_REGEXP "regexp"
92 97 #define HH_CONFIG_SUBSTRING "substring" #define HH_CONFIG_SUBSTRING "substring"
 
95 100 #define HH_CONFIG_FAVORITES "favorites" #define HH_CONFIG_FAVORITES "favorites"
96 101 #define HH_CONFIG_DEBUG "debug" #define HH_CONFIG_DEBUG "debug"
97 102 #define HH_CONFIG_WARN "warning" #define HH_CONFIG_WARN "warning"
98 #define HH_CONFIG_BIG_KEYS_SKIP "bigkeysskip"
99 #define HH_CONFIG_BIG_KEYS_FLOOR "bigkeysfloor"
100 #define HH_CONFIG_BIG_KEYS_EXIT "bigkeysexit"
103 #define HH_CONFIG_BIG_KEYS_SKIP "big-keys-skip"
104 #define HH_CONFIG_BIG_KEYS_FLOOR "big-keys-floor"
105 #define HH_CONFIG_BIG_KEYS_EXIT "big-keys-exit"
101 106
102 107 #define HH_DEBUG_LEVEL_NONE 0 #define HH_DEBUG_LEVEL_NONE 0
103 108 #define HH_DEBUG_LEVEL_WARN 1 #define HH_DEBUG_LEVEL_WARN 1
 
142 147 #define LOGSELECTION(Y,SCREEN,MODEL) #define LOGSELECTION(Y,SCREEN,MODEL)
143 148 #endif #endif
144 149
145 void logstring(char* str){
146 FILE *f = fopen("/home/tbabej/hh.log", "a");
147 if (f == NULL)
148 {
149 perror("fopen");
150 printf("Error opening file!\n");
151 exit(1);
152 }
153 fprintf(f, "Debug: %s \n", str);
154 fclose(f);
155 }
156
157 150 static const char *HH_VIEW_LABELS[]={ static const char *HH_VIEW_LABELS[]={
158 151 "ranking", "ranking",
159 152 "history", "history",
 
... ... typedef struct {
243 236
244 237 bool interactive; bool interactive;
245 238
246 bool hicolor;
239 unsigned char theme;
247 240 int bigKeys; int bigKeys;
248 241 int debugLevel; int debugLevel;
249 242
 
... ... void hstr_init(Hstr *hstr)
266 259
267 260 hstr->interactive=true; hstr->interactive=true;
268 261
269 hstr->hicolor=FALSE;
262 hstr->theme=HH_THEME_MONO;
270 263 hstr->bigKeys=RADIX_BIG_KEYS_SKIP; hstr->bigKeys=RADIX_BIG_KEYS_SKIP;
271 264 hstr->debugLevel=HH_DEBUG_LEVEL_NONE; hstr->debugLevel=HH_DEBUG_LEVEL_NONE;
272 265
 
... ... void hstr_get_env_configuration(Hstr *hstr)
278 271 { {
279 272 char *hstr_config=getenv(HH_ENV_VAR_CONFIG); char *hstr_config=getenv(HH_ENV_VAR_CONFIG);
280 273 if(hstr_config && strlen(hstr_config)>0) { if(hstr_config && strlen(hstr_config)>0) {
281 if(strstr(hstr_config,HH_CONFIG_HICOLOR)) {
282 hstr->hicolor=TRUE;
274 if(strstr(hstr_config,HH_CONFIG_THEME_MONOCHROMATIC)) {
275 hstr->theme=HH_THEME_MONO;
276 } else {
277 if(strstr(hstr_config,HH_CONFIG_THEME_HICOLOR)) {
278 hstr->theme=HH_THEME_DARK;
279 }
283 280 } }
284 281 if(strstr(hstr_config,HH_CONFIG_CASE)) { if(strstr(hstr_config,HH_CONFIG_CASE)) {
285 282 hstr->caseSensitive=HH_CASE_SENSITIVE; hstr->caseSensitive=HH_CASE_SENSITIVE;
 
... ... int print_prompt(Hstr *hstr)
326 323 { {
327 324 int xoffset = 0, promptLength; int xoffset = 0, promptLength;
328 325
329 if(hstr->hicolor) {
326 if(hstr->theme & HH_THEME_COLOR) {
330 327 color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT)); color_attr_on(COLOR_PAIR(HH_COLOR_PROMPT));
331 328 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
332 329 } }
 
... ... int print_prompt(Hstr *hstr)
345 342 free(hostname); free(hostname);
346 343 } }
347 344
348 if(hstr->hicolor) {
345 if(hstr->theme & HH_THEME_COLOR) {
349 346 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
350 347 color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT)); color_attr_off(COLOR_PAIR(HH_COLOR_PROMPT));
351 348 } }
 
... ... void print_cmd_deleted_label(const char *cmd, int occurences, Hstr *hstr)
367 364 char screenLine[CMDLINE_LNG]; char screenLine[CMDLINE_LNG];
368 365 snprintf(screenLine, getmaxx(stdscr), "History item '%s' deleted (%d occurrence%s)", cmd, occurences, (occurences==1?"":"s")); snprintf(screenLine, getmaxx(stdscr), "History item '%s' deleted (%d occurrence%s)", cmd, occurences, (occurences==1?"":"s"));
369 366 // TODO make this function // TODO make this function
370 if(hstr->hicolor) {
367 if(hstr->theme & HH_THEME_COLOR) {
371 368 color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); color_attr_on(COLOR_PAIR(HH_COLOR_DELETE));
372 369 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
373 370 } }
374 371 mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine); mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine);
375 if(hstr->hicolor) {
372 if(hstr->theme & HH_THEME_COLOR) {
376 373 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
377 374 color_attr_on(COLOR_PAIR(1)); color_attr_on(COLOR_PAIR(1));
378 375 } }
 
... ... void print_regexp_error(const char *errorMessage)
384 381 { {
385 382 char screenLine[CMDLINE_LNG]; char screenLine[CMDLINE_LNG];
386 383 snprintf(screenLine, getmaxx(stdscr), "%s", errorMessage); snprintf(screenLine, getmaxx(stdscr), "%s", errorMessage);
387 if(hstr->hicolor) {
384 if(hstr->theme & HH_THEME_COLOR) {
388 385 color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); color_attr_on(COLOR_PAIR(HH_COLOR_DELETE));
389 386 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
390 387 } }
391 388 mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine); mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine);
392 if(hstr->hicolor) {
389 if(hstr->theme & HH_THEME_COLOR) {
393 390 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
394 391 color_attr_on(COLOR_PAIR(1)); color_attr_on(COLOR_PAIR(1));
395 392 } }
 
... ... void print_cmd_added_favorite_label(const char *cmd, Hstr *hstr)
401 398 { {
402 399 char screenLine[CMDLINE_LNG]; char screenLine[CMDLINE_LNG];
403 400 snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd); snprintf(screenLine, getmaxx(stdscr), "Command '%s' added to favorites (C-/ to show favorites)", cmd);
404 if(hstr->hicolor) {
401 if(hstr->theme & HH_THEME_COLOR) {
405 402 color_attr_on(COLOR_PAIR(HH_COLOR_INFO)); color_attr_on(COLOR_PAIR(HH_COLOR_INFO));
406 403 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
407 404 } }
408 405 mvprintw(Y_OFFSET_HELP, 0, screenLine); mvprintw(Y_OFFSET_HELP, 0, screenLine);
409 if(hstr->hicolor) {
406 if(hstr->theme & HH_THEME_COLOR) {
410 407 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
411 408 color_attr_on(COLOR_PAIR(1)); color_attr_on(COLOR_PAIR(1));
412 409 } }
 
... ... void print_history_label(Hstr *hstr)
431 428 for (i=0; i < width; i++) { for (i=0; i < width; i++) {
432 429 strcat(screenLine, "-"); strcat(screenLine, "-");
433 430 } }
434 if(hstr->hicolor) {
431 if(hstr->theme & HH_THEME_COLOR) {
435 432 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
436 433 } }
437 434 color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
438 435 mvprintw(Y_OFFSET_HISTORY, 0, "%s", screenLine); mvprintw(Y_OFFSET_HISTORY, 0, "%s", screenLine);
439 436 color_attr_off(A_REVERSE); color_attr_off(A_REVERSE);
440 if(hstr->hicolor) {
437 if(hstr->theme & HH_THEME_COLOR) {
441 438 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
442 439 } }
443 440 refresh(); refresh();
 
... ... void print_selection_row(char *text, int y, int width, char *pattern)
613 610
614 611 if(pattern && strlen(pattern)) { if(pattern && strlen(pattern)) {
615 612 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
616 color_attr_on(COLOR_PAIR(HH_COLOR_MATCH));
613 if(hstr->theme & HH_THEME_COLOR) {
614 color_attr_on(COLOR_PAIR(HH_COLOR_MATCH));
615 }
617 616 char *p; char *p;
618 617 char *keywordsSavePtr; char *keywordsSavePtr;
619 618 char *keywordsToken; char *keywordsToken;
 
... ... void print_selection_row(char *text, int y, int width, char *pattern)
654 653
655 654 break; break;
656 655 } }
657 color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));
656 if(hstr->theme & HH_THEME_COLOR) {
657 color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));
658 }
658 659 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
659 660 } }
660 661 } }
 
... ... void print_selection_row(char *text, int y, int width, char *pattern)
662 663 void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hstr) void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hstr)
663 664 { {
664 665 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
665 if(hstr->hicolor) {
666 if(hstr->theme & HH_THEME_COLOR) {
666 667 color_attr_on(COLOR_PAIR(2)); color_attr_on(COLOR_PAIR(2));
667 668 } else { } else {
668 669 color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
 
... ... void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hs
672 673 "%s%s" SPACE_PADDING SPACE_PADDING SPACE_PADDING, "%s%s" SPACE_PADDING SPACE_PADDING SPACE_PADDING,
673 674 (terminal_has_colors()?" ":">"), text); (terminal_has_colors()?" ":">"), text);
674 675 mvprintw(y, 0, "%s", screenLine); mvprintw(y, 0, "%s", screenLine);
675 if(hstr->hicolor) {
676 if(hstr->theme & HH_THEME_COLOR) {
676 677 color_attr_on(COLOR_PAIR(1)); color_attr_on(COLOR_PAIR(1));
677 678 } else { } else {
678 679 color_attr_off(A_REVERSE); color_attr_off(A_REVERSE);
 
... ... void loop_to_select(Hstr *hstr)
811 812 hstr_curses_start(); hstr_curses_start();
812 813 // TODO move the code below to hstr_curses // TODO move the code below to hstr_curses
813 814 color_init_pair(HH_COLOR_NORMAL, -1, -1); color_init_pair(HH_COLOR_NORMAL, -1, -1);
814 if(hstr->hicolor) {
815 if(hstr->theme & HH_THEME_COLOR) {
815 816 color_init_pair(HH_COLOR_HIROW, COLOR_WHITE, COLOR_GREEN); color_init_pair(HH_COLOR_HIROW, COLOR_WHITE, COLOR_GREEN);
816 817 color_init_pair(HH_COLOR_PROMPT, COLOR_BLUE, -1); color_init_pair(HH_COLOR_PROMPT, COLOR_BLUE, -1);
817 818 color_init_pair(HH_COLOR_DELETE, COLOR_WHITE, COLOR_RED); color_init_pair(HH_COLOR_DELETE, COLOR_WHITE, COLOR_RED);
818 color_init_pair(HH_COLOR_MATCH, COLOR_YELLOW, -1);
819
820 color_init_pair(HH_COLOR_MATCH, COLOR_RED, -1);
819 821 } }
820 822
821 823 color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL)); color_attr_on(COLOR_PAIR(HH_COLOR_NORMAL));
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master