From: abellenir Date: Sat, 26 Jul 2014 07:28:41 +0000 (+0000) Subject: cursorjumping & beginnings of seeking X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d51e8631830448fc436b38c42aa644ccd5b60c87;p=archive%2Fafm.git cursorjumping & beginnings of seeking --- diff --git a/source/input.c b/source/input.c index f64621c..00c712a 100644 --- a/source/input.c +++ b/source/input.c @@ -33,6 +33,22 @@ static void handle_cd(void) { workdir_cd(state_get_focused_frame()->workdir); } +static void handle_scroll_to_top(void) { + workdir_scroll_to_top(state_get_focused_frame()->workdir); +} +static void handle_scroll_to_bottom(void) { + workdir_scroll_to_bot(state_get_focused_frame()->workdir); +} +static void handle_page_up(void){ + workdir_jump_up(state_get_focused_frame()->workdir); +} +static void handle_page_down(void){ + workdir_jump_down(state_get_focused_frame()->workdir); +} + +static void search_mode(void){ +} + static binding_t Default_Bindings[] = { { "a", &handle_aardvark }, { "q", &handle_quit }, @@ -41,6 +57,11 @@ static binding_t Default_Bindings[] = { { "\n", &handle_cd }, { "wn", &screen_open }, { "wc", &screen_close }, + { "/", &search_mode }, + { "gg", &handle_scroll_to_top }, + { "G", &handle_scroll_to_bottom }, + { "U", &handle_page_up }, + { "D", &handle_page_down }, //{ "wj", NULL }, //{ "wk", NULL }, }; diff --git a/source/state.h b/source/state.h index 92d89d6..1da0923 100644 --- a/source/state.h +++ b/source/state.h @@ -10,6 +10,8 @@ #include #include "screen.h" +typedef enum{ MODE_NORMAL, MODE_SEARCH } MODE; + bool state_get_running(void); void state_set_running(bool val); bool state_get_screen_dirty(void); diff --git a/source/workdir.c b/source/workdir.c index 4f6b9dc..ab40d4f 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -149,3 +149,32 @@ void workdir_ls(WorkDir_T* wd){ mem_release(cmd); } +void workdir_seek(WorkDir_T* wd, char* search){ + int i = 0; + if(strcmp(((File_T*)vec_at(wd->vfiles, 0))->name, "..") == 0) i++; + while(i < vec_size(wd->vfiles) && strcmp(search, ((File_T*)vec_at(wd->vfiles, i))->name) < 0) i++; + wd->idx = i; +} + +void workdir_scroll_to_top(WorkDir_T* wd){ + wd->idx = 0; + state_set_screen_dirty(true); +} + +void workdir_scroll_to_bot(WorkDir_T* wd){ + wd->idx = vec_size(wd->vfiles) - 1; + state_set_screen_dirty(true); +} + +void workdir_jump_up(WorkDir_T* wd){ + wd->idx -= 20; + if(wd->idx < 0) wd->idx = 0; + state_set_screen_dirty(true); +} + +void workdir_jump_down(WorkDir_T* wd){ + wd->idx += 20; + if(wd->idx >= vec_size(wd->vfiles)) wd->idx = vec_size(wd->vfiles)-1; + state_set_screen_dirty(true); +} + diff --git a/source/workdir.h b/source/workdir.h index caf0bf3..531fa73 100644 --- a/source/workdir.h +++ b/source/workdir.h @@ -36,4 +36,11 @@ void workdir_ls(WorkDir_T*); bool is_dir(char* path); +void workdir_seek(WorkDir_T* wd, char* search); + +void workdir_scroll_to_top(WorkDir_T* wd); +void workdir_scroll_to_bot(WorkDir_T* wd); +void workdir_jump_down(WorkDir_T* wd); +void workdir_jump_up(WorkDir_T* wd); + #endif /* WORKDIR_H */