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 bee3cdd95810508db1d684dbbb6f412fa1b6dc32

Moving prompt to the first row @ screen + hicolor mode constants.
Author: Martin Dvorak
Author date (UTC): 2014-01-27 07:44
Committer name: Martin Dvorak
Committer date (UTC): 2014-01-27 07:44
Parent(s): 25cc46c9c6d3b9a2d5e3c97bfb755ede15cd145f
Signing key:
Tree: b28a4c646895c5be91b475b3b6e808f695cd62c9
File Lines added Lines deleted
src/hstr.c 48 9
File src/hstr.c changed (mode: 100644) (index ffee038..0e29fac)
30 30 #define CMDLINE_LNG 250 #define CMDLINE_LNG 250
31 31
32 32 #define Y_OFFSET_PROMPT 0 #define Y_OFFSET_PROMPT 0
33 #define Y_OFFSET_HELP 2
34 #define Y_OFFSET_HISTORY 3
35 #define Y_OFFSET_ITEMS 4
33 #define Y_OFFSET_HELP 1
34 #define Y_OFFSET_HISTORY 2
35 #define Y_OFFSET_ITEMS 3
36 36
37 37 #define K_CTRL_A 1 #define K_CTRL_A 1
38 38 #define K_CTRL_E 5 #define K_CTRL_E 5
 
53 53 #define K_BACKSPACE 127 #define K_BACKSPACE 127
54 54 #define K_ENTER 10 #define K_ENTER 10
55 55
56 #define HH_COLOR_NORMAL 1
57 #define HH_COLOR_HIGHROW 2
58 #define HH_COLOR_PROMPT 3
59 #define HH_COLOR_DELETE 4
60
56 61 #ifdef DEBUG_KEYS #ifdef DEBUG_KEYS
57 62 #define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol() #define LOGKEYS(Y,KEY) mvprintw(Y, 0, "Key: '%3d' / Char: '%c'", KEY, KEY); clrtoeol()
58 63 #else #else
 
... ... static char **selection=NULL;
93 98 static unsigned selectionSize=0; static unsigned selectionSize=0;
94 99 static bool caseSensitive=FALSE; static bool caseSensitive=FALSE;
95 100 static bool defaultOrder=FALSE; static bool defaultOrder=FALSE;
101 static bool hicolor=FALSE;
96 102 static char screenLine[1000]; static char screenLine[1000];
97 103 static char cmdline[CMDLINE_LNG]; static char cmdline[CMDLINE_LNG];
98 104
 
... ... int print_prompt()
100 106 { {
101 107 char *hostname = get_hostname(); char *hostname = get_hostname();
102 108 char *user = getenv(ENV_VAR_USER); char *user = getenv(ENV_VAR_USER);
103 int xoffset = 1;
109 int xoffset = 0;
104 110
105 mvprintw(xoffset, Y_OFFSET_PROMPT, "%s@%s$ ", user, hostname);
111 if(hicolor) {
112 color_attr_on(COLOR_PAIR(3));
113 }
114 mvprintw(Y_OFFSET_PROMPT, xoffset, "%s@%s$ ", user, hostname);
115 if(hicolor) {
116 color_attr_on(COLOR_PAIR(1));
117 }
106 118 refresh(); refresh();
107 119
108 return xoffset+strlen(user)+1+strlen(hostname)+1;
120 return strlen(user)+1+strlen(hostname)+1+1;
109 121 } }
110 122
111 123 void print_help_label() void print_help_label()
 
... ... void print_help_label()
118 130 void print_cmd_deleted_label(char *cmd, int occurences) void print_cmd_deleted_label(char *cmd, int occurences)
119 131 { {
120 132 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"));
133 if(hicolor) {
134 color_attr_on(COLOR_PAIR(4));
135 color_attr_on(A_BOLD);
136 }
121 137 mvprintw(Y_OFFSET_HELP, 0, screenLine); mvprintw(Y_OFFSET_HELP, 0, screenLine);
138 if(hicolor) {
139 color_attr_off(A_BOLD);
140 color_attr_on(COLOR_PAIR(1));
141 }
122 142 clrtoeol(); clrtoeol();
123 143 refresh(); refresh();
124 144 } }
 
... ... void print_history_label(HistoryItems *history)
140 160 for (i=0; i < width; i++) { for (i=0; i < width; i++) {
141 161 strcat(screenLine, "-"); strcat(screenLine, "-");
142 162 } }
163 if(hicolor) {
164 color_attr_on(A_BOLD);
165 }
143 166 color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
144 167 mvprintw(Y_OFFSET_HISTORY, 0, screenLine); mvprintw(Y_OFFSET_HISTORY, 0, screenLine);
145 168 color_attr_off(A_REVERSE); color_attr_off(A_REVERSE);
169 if(hicolor) {
170 color_attr_off(A_BOLD);
171 }
146 172 refresh(); refresh();
147 173 } }
148 174
 
... ... void print_selection_row(char *text, int y, int width, char *prefix) {
240 266 } }
241 267
242 268 void print_highlighted_selection_row(char *text, int y, int width) { void print_highlighted_selection_row(char *text, int y, int width) {
243 color_attr_on(A_REVERSE);
244 269 color_attr_on(A_BOLD); color_attr_on(A_BOLD);
270 if(hicolor) {
271 color_attr_on(COLOR_PAIR(2));
272 } else {
273 color_attr_on(A_REVERSE);
274 }
245 275 snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminal_has_colors()?" ":">"), text); snprintf(screenLine, getmaxx(stdscr), "%s%s", (terminal_has_colors()?" ":">"), text);
246 276 mvprintw(y, 0, "%s", screenLine); mvprintw(y, 0, "%s", screenLine);
277 if(hicolor) {
278 color_attr_on(COLOR_PAIR(1));
279 } else {
280 color_attr_off(A_REVERSE);
281 }
247 282 color_attr_off(A_BOLD); color_attr_off(A_BOLD);
248 color_attr_off(A_REVERSE);
249 283 } }
250 284
251 285 char *print_selection(unsigned maxHistoryItems, char *prefix, HistoryItems *history) char *print_selection(unsigned maxHistoryItems, char *prefix, HistoryItems *history)
 
... ... void loop_to_select(HistoryItems *history)
330 364 noecho(); noecho();
331 365 color_start(); color_start();
332 366 color_init_pair(1, COLOR_WHITE, COLOR_BLACK); color_init_pair(1, COLOR_WHITE, COLOR_BLACK);
367 if(hicolor) {
368 color_init_pair(2, COLOR_WHITE, COLOR_GREEN);
369 color_init_pair(3, COLOR_CYAN, COLOR_BLACK);
370 color_init_pair(4, COLOR_WHITE, COLOR_RED);
371 }
333 372 color_attr_on(COLOR_PAIR(1)); color_attr_on(COLOR_PAIR(1));
334 373
335 374 print_history_label(history); print_history_label(history);
 
... ... void loop_to_select(HistoryItems *history)
340 379
341 380 bool done=FALSE, skip=TRUE, executeResult=FALSE, lowercase=TRUE; bool done=FALSE, skip=TRUE, executeResult=FALSE, lowercase=TRUE;
342 381 int basex=print_prompt(stdscr); int basex=print_prompt(stdscr);
343 int x=basex, y=1, c, cursorX=0, cursorY=0, maxHistoryItems, deleteOccurences;
382 int x=basex, y=0, c, cursorX=0, cursorY=0, maxHistoryItems, deleteOccurences;
344 383 int width=getmaxx(stdscr); int width=getmaxx(stdscr);
345 384 int selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT; int selectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
346 385 int previousSelectionCursorPosition=SELECTION_CURSOR_IN_PROMPT; int previousSelectionCursorPosition=SELECTION_CURSOR_IN_PROMPT;
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