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 53b33464b8e66cdee090191a1f2859fb55f6b3b0

Fixed #78 by making hstr a structure and code re-entrant.
Author: Martin Dvorak
Author date (UTC): 2014-04-27 06:05
Committer name: Martin Dvorak
Committer date (UTC): 2014-04-27 06:05
Parent(s): bd0d2f34d9eeb1c817bf8ecf58b8a809cbc68abb
Signing key:
Tree: eccbe07cda08920aea1523e55aa94b40bd76e755
File Lines added Lines deleted
src/hstr.c 7 1
File src/hstr.c changed (mode: 100644) (index eb5183c..9bcaeab)
... ... static const char *LABEL_HELP=
155 155 "Type to filter, UP/DOWN move, DEL remove, TAB select, C-f add favorite, C-g cancel"; "Type to filter, UP/DOWN move, DEL remove, TAB select, C-f add favorite, C-g cancel";
156 156
157 157 // TODO makes hstr.c non-reentrant // TODO makes hstr.c non-reentrant
158 static char screenLine[CMDLINE_LNG];
158 //static char screenLine[CMDLINE_LNG];
159 159
160 160 typedef struct { typedef struct {
161 161 HistoryItems *history; HistoryItems *history;
 
... ... int print_prompt(Hstr *hstr)
255 255
256 256 void print_help_label() void print_help_label()
257 257 { {
258 char screenLine[CMDLINE_LNG];
258 259 snprintf(screenLine, getmaxx(stdscr), "%s", LABEL_HELP); snprintf(screenLine, getmaxx(stdscr), "%s", LABEL_HELP);
259 260 mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine); clrtoeol(); mvprintw(Y_OFFSET_HELP, 0, "%s", screenLine); clrtoeol();
260 261 refresh(); refresh();
 
... ... void print_help_label()
262 263
263 264 void print_cmd_deleted_label(char *cmd, int occurences, Hstr *hstr) void print_cmd_deleted_label(char *cmd, int occurences, Hstr *hstr)
264 265 { {
266 char screenLine[CMDLINE_LNG];
265 267 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"));
266 268 if(hstr->hicolor) { if(hstr->hicolor) {
267 269 color_attr_on(COLOR_PAIR(HH_COLOR_DELETE)); color_attr_on(COLOR_PAIR(HH_COLOR_DELETE));
 
... ... void print_cmd_deleted_label(char *cmd, int occurences, Hstr *hstr)
278 280
279 281 void print_cmd_added_favorite_label(char *cmd, Hstr *hstr) void print_cmd_added_favorite_label(char *cmd, Hstr *hstr)
280 282 { {
283 char screenLine[CMDLINE_LNG];
281 284 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);
282 285 if(hstr->hicolor) { if(hstr->hicolor) {
283 286 color_attr_on(COLOR_PAIR(HH_COLOR_INFO)); color_attr_on(COLOR_PAIR(HH_COLOR_INFO));
 
... ... void print_history_label(Hstr *hstr)
296 299 { {
297 300 int width=getmaxx(stdscr); int width=getmaxx(stdscr);
298 301
302 char screenLine[CMDLINE_LNG];
299 303 snprintf(screenLine, width, "- HISTORY - view:%s (C-/) - match:%s (C-e) - case:%s (C-t) - %d/%d ", snprintf(screenLine, width, "- HISTORY - view:%s (C-/) - match:%s (C-e) - case:%s (C-t) - %d/%d ",
300 304 HH_VIEW_LABELS[hstr->historyView], HH_VIEW_LABELS[hstr->historyView],
301 305 HH_MATCH_LABELS[hstr->historyMatch], HH_MATCH_LABELS[hstr->historyMatch],
 
... ... unsigned hstr_make_selection(char *prefix, HistoryItems *history, int maxSelecti
446 450
447 451 void print_selection_row(char *text, int y, int width, char *pattern) void print_selection_row(char *text, int y, int width, char *pattern)
448 452 { {
453 char screenLine[CMDLINE_LNG];
449 454 snprintf(screenLine, width, " %s", text); snprintf(screenLine, width, " %s", text);
450 455 mvprintw(y, 0, "%s", screenLine); clrtoeol(); mvprintw(y, 0, "%s", screenLine); clrtoeol();
451 456
 
... ... void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hs
484 489 } else { } else {
485 490 color_attr_on(A_REVERSE); color_attr_on(A_REVERSE);
486 491 } }
492 char screenLine[CMDLINE_LNG];
487 493 snprintf(screenLine, getmaxx(stdscr), snprintf(screenLine, getmaxx(stdscr),
488 494 "%s%s" SPACE_PADDING SPACE_PADDING SPACE_PADDING, "%s%s" SPACE_PADDING SPACE_PADDING SPACE_PADDING,
489 495 (terminal_has_colors()?" ":">"), text); (terminal_has_colors()?" ":">"), text);
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