Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 53dfbf49f9afa5b47fe61d4ba5f4ff7834944f3d Author: Raniconduh <clagv.randomgames@gmail.com> Date: Tue Oct 12 12:14:52 2021 +0000 added proper control key parsing diff --git a/include/io.h b/include/io.h index d7b8529..6bdbb8c 100644 --- a/include/io.h +++ b/include/io.h @@ -217 +2111 @@ enum keys {   ARROW_UP,   ARROW_DOWN,   ARROW_LEFT, - ARROW_RIGHT + ARROW_RIGHT, + CTRL_P, + CTRL_B, + CTRL_N, + CTRL_F  };    void curses_init(void); diff --git a/include/main.h b/include/main.h index 8f2d87c..e29ea09 100644 --- a/include/main.h +++ b/include/main.h @@ -34 +34 @@  #endif    #define LAST_F (n_dir_entries > ((unsigned)LINES - 6) ? LINES - 6 : n_dir_entries) -#define CTRL_KCOMB(key) (key&0x1f) + diff --git a/src/io.c b/src/io.c index c1dc861..128d3b4 100644 --- a/src/io.c +++ b/src/io.c @@ -206 +207 @@ void curses_init(void) {   initscr();   curs_set(0);   noecho(); + raw();   start_color();     init_pair(BLUE, COLOR_BLUE, COLOR_BLACK); @@ -356 +367 @@ void curses_init(void) {  void terminate_curses(void) {   curs_set(1);   echo(); + noraw();   endwin();     if (print_path) { @@ -1166 +11814 @@ char curses_getch(void) {   }   *ptr++ = getch();   *ptr++ = '\0'; + } else { + switch (c) { + case 2: return CTRL_B; break; + case 6: return CTRL_F; break; + case 14: return CTRL_N; break; + case 16: return CTRL_P; break; + default: break; + }   }     if (seq[0] == '[') diff --git a/src/main.c b/src/main.c index eddc7c5..08a4b79 100644 --- a/src/main.c +++ b/src/main.c @@ -7716 +7717 @@ int main(int argc, char ** argv) {   char c = curses_getch();   switch (c) {   case ARROW_UP: - case CTRL_KCOMB('p'): - case 'k': + case CTRL_P: + case 'k':   if (cursor > 1) cursor--;   break;   case ARROW_DOWN: - case CTRL_KCOMB('n'): + case CTRL_N:   case 'j':   if (cursor < n_dir_entries) cursor++;   break;   case ARROW_LEFT: + case CTRL_B:   case 'h':   cd_back();   free_dir_entries(); @@ -967 +977 @@ int main(int argc, char ** argv) {   last_f = LAST_F;   break;   case ARROW_RIGHT: - case CTRL_KCOMB('f'): + case CTRL_F:   case 'l':   case '\n':   if (!n_dir_entries) break;