mirror of
https://github.com/dvorka/hstr.git
synced 2025-09-07 04:54:15 +08:00
Ensuring that functions declarations indicate that they have no parameters which resolves #252
This commit is contained in:
parent
b51d5f2e25
commit
d201ef1f84
6 changed files with 45 additions and 37 deletions
68
src/hstr.c
68
src/hstr.c
|
@ -158,24 +158,24 @@
|
||||||
#define LOGSELECTION(Y,SCREEN,MODEL)
|
#define LOGSELECTION(Y,SCREEN,MODEL)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *HH_VIEW_LABELS[]={
|
static const char* HH_VIEW_LABELS[]={
|
||||||
"ranking",
|
"ranking",
|
||||||
"history",
|
"history",
|
||||||
"favorites"
|
"favorites"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *HH_MATCH_LABELS[]={
|
static const char* HH_MATCH_LABELS[]={
|
||||||
"exact",
|
"exact",
|
||||||
"regexp",
|
"regexp",
|
||||||
"keywords"
|
"keywords"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *HH_CASE_LABELS[]={
|
static const char* HH_CASE_LABELS[]={
|
||||||
"insensitive",
|
"insensitive",
|
||||||
"sensitive"
|
"sensitive"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *INSTALL_BASH_STRING=
|
static const char* INSTALL_BASH_STRING=
|
||||||
"\n# add this configuration to ~/.bashrc"
|
"\n# add this configuration to ~/.bashrc"
|
||||||
"\nexport HH_CONFIG=hicolor # get more colors"
|
"\nexport HH_CONFIG=hicolor # get more colors"
|
||||||
"\nshopt -s histappend # append new history items to .bash_history"
|
"\nshopt -s histappend # append new history items to .bash_history"
|
||||||
|
@ -219,11 +219,19 @@ static const char *INSTALL_BASH_STRING=
|
||||||
#endif
|
#endif
|
||||||
"\n\n";
|
"\n\n";
|
||||||
|
|
||||||
static const char *INSTALL_ZSH_STRING=
|
static const char* INSTALL_ZSH_STRING=
|
||||||
"\n# add this configuration to ~/.zshrc"
|
"\n# add this configuration to ~/.zshrc"
|
||||||
"\nexport HISTFILE=~/.zsh_history # ensure history file visibility"
|
"\nexport HISTFILE=~/.zsh_history # ensure history file visibility"
|
||||||
"\nexport HH_CONFIG=hicolor # get more colors"
|
"\nexport HH_CONFIG=hicolor # get more colors"
|
||||||
|
#if defined(__MS_WSL__)
|
||||||
|
// TODO binding to be rewritten for zsh@WSL as it's done for Bash - hstr_winwsl() like function to be implemented to make it work on WSL
|
||||||
"\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
"\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
||||||
|
#elif defined(__CYGWIN__)
|
||||||
|
// TODO binding to be rewritten for zsh@Cygwin as it's done for Bash - hstr_winwsl() like function to be implemented to make it work on WSL
|
||||||
|
"\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
||||||
|
#else
|
||||||
|
"\nbindkey -s \"\\C-r\" \"\\eqhh\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
||||||
|
#endif
|
||||||
// TODO try variant with args/pars separation
|
// TODO try variant with args/pars separation
|
||||||
//"\nbindkey -s \"\\C-r\" \"\\eqhh --\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
//"\nbindkey -s \"\\C-r\" \"\\eqhh --\\n\" # bind hh to Ctrl-r (for Vi mode check doc)"
|
||||||
// alternate binding options in zsh:
|
// alternate binding options in zsh:
|
||||||
|
@ -231,7 +239,7 @@ static const char *INSTALL_ZSH_STRING=
|
||||||
// bindkey -s "\C-r" "\C-ahh \C-j"
|
// bindkey -s "\C-r" "\C-ahh \C-j"
|
||||||
"\n\n";
|
"\n\n";
|
||||||
|
|
||||||
static const char *HELP_STRING=
|
static const char* HELP_STRING=
|
||||||
"Usage: hh [option] [arg1] [arg2]..."
|
"Usage: hh [option] [arg1] [arg2]..."
|
||||||
"\nShell history suggest box:"
|
"\nShell history suggest box:"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -249,12 +257,12 @@ static const char *HELP_STRING=
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
// major.minor.revision
|
// major.minor.revision
|
||||||
static const char *VERSION_STRING=
|
static const char* VERSION_STRING=
|
||||||
"hh version \"1.27.0\" (2018-08-1T13:00:00)"
|
"hh version \"1.27.0\" (2018-08-1T13:00:00)"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
// TODO help screen - curses window (tig)
|
// TODO help screen - curses window (tig)
|
||||||
static const char *LABEL_HELP=
|
static const char* LABEL_HELP=
|
||||||
"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";
|
||||||
|
|
||||||
#define GETOPT_NO_ARGUMENT 0
|
#define GETOPT_NO_ARGUMENT 0
|
||||||
|
@ -310,9 +318,9 @@ typedef struct {
|
||||||
int promptItems;
|
int promptItems;
|
||||||
} Hstr;
|
} Hstr;
|
||||||
|
|
||||||
static Hstr *hstr;
|
static Hstr* hstr;
|
||||||
|
|
||||||
void hstr_init()
|
void hstr_init(void)
|
||||||
{
|
{
|
||||||
hstr->selection=NULL;
|
hstr->selection=NULL;
|
||||||
hstr->selectionRegexpMatch=NULL;
|
hstr->selectionRegexpMatch=NULL;
|
||||||
|
@ -335,7 +343,7 @@ void hstr_init()
|
||||||
hstr_regexp_init(&hstr->regexp);
|
hstr_regexp_init(&hstr->regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned recalculate_max_history_items()
|
unsigned recalculate_max_history_items(void)
|
||||||
{
|
{
|
||||||
hstr->promptItems = getmaxy(stdscr) - 3;
|
hstr->promptItems = getmaxy(stdscr) - 3;
|
||||||
if(hstr->promptBottom) {
|
if(hstr->promptBottom) {
|
||||||
|
@ -354,7 +362,7 @@ unsigned recalculate_max_history_items()
|
||||||
return hstr->promptItems;
|
return hstr->promptItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hstr_get_env_configuration(Hstr *hstr)
|
void hstr_get_env_configuration(Hstr* hstr)
|
||||||
{
|
{
|
||||||
char *hstr_config=getenv(HH_ENV_VAR_CONFIG);
|
char *hstr_config=getenv(HH_ENV_VAR_CONFIG);
|
||||||
if(hstr_config && strlen(hstr_config)>0) {
|
if(hstr_config && strlen(hstr_config)>0) {
|
||||||
|
@ -429,7 +437,7 @@ void hstr_get_env_configuration(Hstr *hstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned print_prompt()
|
unsigned print_prompt(void)
|
||||||
{
|
{
|
||||||
unsigned xoffset = 0, promptLength;
|
unsigned xoffset = 0, promptLength;
|
||||||
|
|
||||||
|
@ -461,7 +469,7 @@ unsigned print_prompt()
|
||||||
return promptLength;
|
return promptLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_to_selection(Hstr *hstr, char *line, unsigned int *index)
|
void add_to_selection(Hstr* hstr, char* line, unsigned int* index)
|
||||||
{
|
{
|
||||||
if (hstr->unique) {
|
if (hstr->unique) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -475,7 +483,7 @@ void add_to_selection(Hstr *hstr, char *line, unsigned int *index)
|
||||||
*index = *index + 1;
|
*index = *index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_help_label()
|
void print_help_label(void)
|
||||||
{
|
{
|
||||||
int cursorX=getcurx(stdscr);
|
int cursorX=getcurx(stdscr);
|
||||||
int cursorY=getcury(stdscr);
|
int cursorY=getcury(stdscr);
|
||||||
|
@ -488,7 +496,7 @@ void print_help_label()
|
||||||
move(cursorY, cursorX);
|
move(cursorY, cursorX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_confirm_delete(const char *cmd, Hstr *hstr)
|
void print_confirm_delete(const char* cmd, Hstr* hstr)
|
||||||
{
|
{
|
||||||
char screenLine[CMDLINE_LNG];
|
char screenLine[CMDLINE_LNG];
|
||||||
snprintf(screenLine, getmaxx(stdscr), "Do you want to delete all occurrences of '%s'? y/n", cmd);
|
snprintf(screenLine, getmaxx(stdscr), "Do you want to delete all occurrences of '%s'? y/n", cmd);
|
||||||
|
@ -506,7 +514,7 @@ void print_confirm_delete(const char *cmd, Hstr *hstr)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmd_deleted_label(const char *cmd, int occurences, Hstr *hstr)
|
void print_cmd_deleted_label(const char* cmd, int occurences, Hstr* hstr)
|
||||||
{
|
{
|
||||||
char screenLine[CMDLINE_LNG];
|
char screenLine[CMDLINE_LNG];
|
||||||
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"));
|
||||||
|
@ -541,7 +549,7 @@ void print_regexp_error(const char *errorMessage)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_cmd_added_favorite_label(const char *cmd, Hstr *hstr)
|
void print_cmd_added_favorite_label(const char* cmd, Hstr* hstr)
|
||||||
{
|
{
|
||||||
char screenLine[CMDLINE_LNG];
|
char screenLine[CMDLINE_LNG];
|
||||||
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);
|
||||||
|
@ -558,7 +566,7 @@ void print_cmd_added_favorite_label(const char *cmd, Hstr *hstr)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_history_label()
|
void print_history_label(void)
|
||||||
{
|
{
|
||||||
unsigned width=getmaxx(stdscr);
|
unsigned width=getmaxx(stdscr);
|
||||||
|
|
||||||
|
@ -587,7 +595,7 @@ void print_history_label()
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_pattern(char *pattern, int y, int x)
|
void print_pattern(char* pattern, int y, int x)
|
||||||
{
|
{
|
||||||
if(pattern) {
|
if(pattern) {
|
||||||
color_attr_on(A_BOLD);
|
color_attr_on(A_BOLD);
|
||||||
|
@ -598,7 +606,7 @@ void print_pattern(char *pattern, int y, int x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO don't realloc if size doesn't change
|
// TODO don't realloc if size doesn't change
|
||||||
void hstr_realloc_selection(unsigned size, Hstr *hstr)
|
void hstr_realloc_selection(unsigned size, Hstr* hstr)
|
||||||
{
|
{
|
||||||
if(hstr->selection) {
|
if(hstr->selection) {
|
||||||
if(size) {
|
if(size) {
|
||||||
|
@ -620,7 +628,7 @@ void hstr_realloc_selection(unsigned size, Hstr *hstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned hstr_make_selection(char *prefix, HistoryItems *history, unsigned maxSelectionCount, Hstr *hstr)
|
unsigned hstr_make_selection(char* prefix, HistoryItems* history, unsigned maxSelectionCount, Hstr* hstr)
|
||||||
{
|
{
|
||||||
hstr_realloc_selection(maxSelectionCount, hstr);
|
hstr_realloc_selection(maxSelectionCount, hstr);
|
||||||
|
|
||||||
|
@ -754,7 +762,7 @@ unsigned hstr_make_selection(char *prefix, HistoryItems *history, unsigned maxSe
|
||||||
return selectionCount;
|
return selectionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_selection_row(char *text, int y, int width, char *pattern)
|
void print_selection_row(char* text, int y, int width, char* pattern)
|
||||||
{
|
{
|
||||||
char screenLine[CMDLINE_LNG];
|
char screenLine[CMDLINE_LNG];
|
||||||
snprintf(screenLine, width, " %s", text);
|
snprintf(screenLine, width, " %s", text);
|
||||||
|
@ -847,7 +855,7 @@ void hstr_print_highlighted_selection_row(char *text, int y, int width, Hstr *hs
|
||||||
color_attr_off(A_BOLD);
|
color_attr_off(A_BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
|
char *hstr_print_selection(unsigned maxHistoryItems, char* pattern, Hstr* hstr)
|
||||||
{
|
{
|
||||||
char *result=NULL;
|
char *result=NULL;
|
||||||
unsigned selectionCount=hstr_make_selection(pattern, hstr->history, maxHistoryItems, hstr);
|
unsigned selectionCount=hstr_make_selection(pattern, hstr->history, maxHistoryItems, hstr);
|
||||||
|
@ -909,7 +917,7 @@ char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void highlight_selection(int selectionCursorPosition, int previousSelectionCursorPosition, char *pattern, Hstr *hstr)
|
void highlight_selection(int selectionCursorPosition, int previousSelectionCursorPosition, char* pattern, Hstr* hstr)
|
||||||
{
|
{
|
||||||
if(previousSelectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) {
|
if(previousSelectionCursorPosition!=SELECTION_CURSOR_IN_PROMPT) {
|
||||||
// TODO make this function
|
// TODO make this function
|
||||||
|
@ -989,13 +997,13 @@ int remove_from_history_model(char* delete, Hstr *hstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hstr_next_view(Hstr *hstr)
|
void hstr_next_view(Hstr* hstr)
|
||||||
{
|
{
|
||||||
hstr->historyView++;
|
hstr->historyView++;
|
||||||
hstr->historyView=hstr->historyView%3;
|
hstr->historyView=hstr->historyView%3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stdout_history_and_return(Hstr *hstr) {
|
void stdout_history_and_return(Hstr* hstr) {
|
||||||
unsigned selectionCount=hstr_make_selection(hstr->cmdline, hstr->history, hstr->history->rawCount, hstr);
|
unsigned selectionCount=hstr_make_selection(hstr->cmdline, hstr->history, hstr->history->rawCount, hstr);
|
||||||
if (selectionCount > 0) {
|
if (selectionCount > 0) {
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -1014,7 +1022,7 @@ char* getResultFromSelection(int selectionCursorPosition, Hstr* hstr, char* resu
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop_to_select(Hstr *hstr)
|
void loop_to_select(Hstr* hstr)
|
||||||
{
|
{
|
||||||
signal(SIGINT, signal_callback_handler_ctrl_c);
|
signal(SIGINT, signal_callback_handler_ctrl_c);
|
||||||
|
|
||||||
|
@ -1417,14 +1425,14 @@ void hstr_assemble_cmdline_pattern(int argc, char* argv[], Hstr* hstr, int start
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO make favorites loading lazy (load on the first opening of favorites view)
|
// TODO make favorites loading lazy (load on the first opening of favorites view)
|
||||||
void hstr_init_favorites(Hstr *hstr)
|
void hstr_init_favorites(Hstr* hstr)
|
||||||
{
|
{
|
||||||
hstr->favorites=malloc(sizeof(FavoriteItems));
|
hstr->favorites=malloc(sizeof(FavoriteItems));
|
||||||
favorites_init(hstr->favorites);
|
favorites_init(hstr->favorites);
|
||||||
favorites_get(hstr->favorites);
|
favorites_get(hstr->favorites);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hstr_main(Hstr *hstr)
|
void hstr_main(Hstr* hstr)
|
||||||
{
|
{
|
||||||
hstr->history=get_prioritized_history(hstr->bigKeys, hstr->blacklist.set);
|
hstr->history=get_prioritized_history(hstr->bigKeys, hstr->blacklist.set);
|
||||||
if(hstr->history) {
|
if(hstr->history) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
static bool terminalHasColors=FALSE;
|
static bool terminalHasColors=FALSE;
|
||||||
|
|
||||||
void hstr_curses_start()
|
void hstr_curses_start(void)
|
||||||
{
|
{
|
||||||
initscr();
|
initscr();
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
|
@ -42,7 +42,7 @@ void hstr_curses_start()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool terminal_has_colors() {
|
bool terminal_has_colors(void) {
|
||||||
return terminalHasColors;
|
return terminalHasColors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ unsigned get_item_offset(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_hist_timestamp(const char *line)
|
bool is_hist_timestamp(const char* line)
|
||||||
{
|
{
|
||||||
// HISTTIMEFORMAT defined > ^#1234567890$
|
// HISTTIMEFORMAT defined > ^#1234567890$
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,7 @@ char *get_shell_name_by_ppid(const int pid)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isZshParentShell() {
|
bool isZshParentShell(void) {
|
||||||
pid_t parentPid=getppid();
|
pid_t parentPid=getppid();
|
||||||
char* cmdline=get_shell_name_by_ppid(parentPid);
|
char* cmdline=get_shell_name_by_ppid(parentPid);
|
||||||
bool result=cmdline && strstr(cmdline, "zsh");
|
bool result=cmdline && strstr(cmdline, "zsh");
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
#define color_attr_off(C) if(terminal_has_colors()) { attroff(C); }
|
#define color_attr_off(C) if(terminal_has_colors()) { attroff(C); }
|
||||||
#define color_init_pair(X, Y, Z) if(terminal_has_colors()) { init_pair(X, Y, Z); }
|
#define color_init_pair(X, Y, Z) if(terminal_has_colors()) { init_pair(X, Y, Z); }
|
||||||
|
|
||||||
void hstr_curses_start();
|
void hstr_curses_start(void);
|
||||||
bool terminal_has_colors();
|
bool terminal_has_colors(void);
|
||||||
void hstr_curses_stop(bool keepPage);
|
void hstr_curses_stop(bool keepPage);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,6 +42,6 @@ void fill_terminal_input(char* cmd, bool padding);
|
||||||
void reverse_char_pointer_array(char **array, unsigned length);
|
void reverse_char_pointer_array(char **array, unsigned length);
|
||||||
void get_hostname(int bufferSize, char *buffer);
|
void get_hostname(int bufferSize, char *buffer);
|
||||||
void toggle_case(char *str, bool lowercase);
|
void toggle_case(char *str, bool lowercase);
|
||||||
bool isZshParentShell();
|
bool isZshParentShell(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue