Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search #57

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# For next release
# Minor Release v0.5.0 (2023-07-16)
* **Raphael Pour**
* logging: document feature
* **bugfix** terminal: Ignore unsupported special keys
* session/terminal: add HOME+END key-binding
* screen: add line numbers
* add highlighting

*Not released yet*
*Released by Raphael Pour <[email protected]>*

# Patch Release v0.4.2 (2021-01-28)
* **Raphael Pour**
Expand Down
3 changes: 3 additions & 0 deletions include/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ typedef struct {

/* Dirty flag */
bool dirty;

/* Search needle, NULL if no search is going on */
char* needle;
} Session;

Session* fe_init_session( char* filename );
Expand Down
2 changes: 2 additions & 0 deletions include/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ int fe_get_user_input();

enum KEYS {
UNKNOWN = -1,
CTRL_F = 6,
TAB = 9,
ENTER_MAC = 10,
ENTER = 13,
CTRL_R = 18,
CTRL_S = 19,
ESCAPE = 27,
BACKSPACE = 127,
Expand Down
1 change: 1 addition & 0 deletions include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include <session.h>

bool fe_safe_file_dialog( Session *s );
bool fe_search_fwd_dialog( Session *s );
bool fe_quit_dialog( Session *s );
#endif
1 change: 1 addition & 0 deletions source/femto.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ int main(int argc, char *argv[])
case PAGE_UP: fe_move_page_up( session ); break;
case PAGE_DOWN: fe_move_page_down( session ); break;
case CTRL_S: fe_safe_file_dialog( session ); break;
case CTRL_F: fe_search_fwd_dialog( session ); break;
case UNKNOWN:
/*
* Do nothing if there wasn't anything useful to read like
Expand Down
1 change: 1 addition & 0 deletions source/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Session* fe_init_session( char* filename )
s->content_length = 0;
s->line_count = 0;
s->dirty = false;
s->needle = NULL;


/* Determine terminal properties */
Expand Down
14 changes: 13 additions & 1 deletion source/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ bool fe_safe_file_dialog( Session *s )
return true;
}

bool fe_search_fwd_dialog( Session *s )
{
/* Check if a previous search is going on/ needle is already set */
char * needle = fe_user_prompt( s, "Needle:" );


}

bool fe_quit_dialog( Session *s )
{
if( ! s->dirty ) return true;
Expand All @@ -49,8 +57,12 @@ bool fe_quit_dialog( Session *s )
}
}

static char* fe_user_prompt( Session *s, char* prompt )
static char* fe_user_prompt( Session *s, char* prompt)
{
/*
* Add pre-answer to the parameter list in order to have search dialogs
* with predefined needles.
*/
char c = 0;
char *answer = (char*) malloc(1);
answer[0] = '\0';
Expand Down