commit bb97301776105b762e047396d048a2dcb6e66d99
Author: Raniconduh <clagv.randomgames@gmail.com>
Date: Mon Jan 24 16:46:45 2022 +0000
diff --git a/include/io.h b/include/io.h
index b9608e9..58ab5a5 100644
--- a/include/io.h
+++ b/include/io.h
@@ -2010 +206 @@ enum colors {
};
enum keys {
- ARROW_UP,
- ARROW_DOWN,
- ARROW_LEFT,
- ARROW_RIGHT,
CTRL_P,
CTRL_B,
CTRL_N,
@@ -347 +306 @@ enum keys {
void curses_init(void);
void terminate_curses(void);
void curses_write_file(struct dir_entry_t *, bool);
-char curses_getch(void);
char * prompt(char *, char **);
char * curses_getline(char *);
void unmark_all(void);
diff --git a/src/io.c b/src/io.c
index 5febc73..e0e5bfc 100644
--- a/src/io.c
+++ b/src/io.c
@@ -296 +297 @@ void curses_init(void) {
}
initscr();
+ keypad(stdscr, true);
curs_set(0);
noecho();
raw();
@@ -396 +407 @@ void curses_init(void) {
void terminate_curses(void) {
+ keypad(stdscr, false);
curs_set(1);
echo();
noraw();
@@ -18250 +1846 @@ void curses_write_file(struct dir_entry_t * dir_entry, bool highlight) {
}
-char curses_getch(void) {
- char c = getch();
-
- char seq[5] = {0};
- char * ptr = seq;
-
- if (c == 27) {
- char c = getch();
- if (c == '[') {
- *ptr++ = c;
- } else {
- ungetch(c);
- return seq[0];
- }
- *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] == '[')
- switch (seq[1]) {
- case 'A':
- return ARROW_UP;
- case 'B':
- return ARROW_DOWN;
- case 'D':
- return ARROW_LEFT;
- case 'C':
- return ARROW_RIGHT;
- default:
- break;
- }
-
- return c;
-}
-
-
char * prompt(char * t, char ** args) {
int sub_cols = 30;
int sub_rows = sub_cols / 2;
@@ -28218 +24018 @@ char * prompt(char * t, char ** args) {
wrefresh(w);
- char c = curses_getch();
+ int c = getch();
switch (c) {
- case ARROW_UP:
- case ARROW_LEFT:
+ case KEY_UP:
+ case KEY_LEFT:
case CTRL_P:
case CTRL_B:
case 'h':
case 'k':
if (cursor > 1) cursor--;
break;
- case ARROW_DOWN:
- case ARROW_RIGHT:
+ case KEY_DOWN:
+ case KEY_RIGHT:
case CTRL_N:
case CTRL_F:
case 'l':
diff --git a/src/main.c b/src/main.c
index 1b37104..27af63a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -137 +136 @@
#include "dir.h"
#include "io.h"
-
static size_t first_f, last_f, cursor;
int main(int argc, char ** argv) {
@@ -4810 +4710 @@ int main(int argc, char ** argv) {
strcpy(cwd, p);
}
- signal(SIGWINCH, handle_winch);
-
curses_init();
+ signal(SIGWINCH, handle_winch);
+
list_dir(cwd);
cursor = 1;
@@ -9719 +9619 @@ int main(int argc, char ** argv) {
refresh();
- char c = curses_getch();
+ int c = getch();
switch (c) {
- case ARROW_UP:
+ case KEY_UP:
case CTRL_P:
case 'k':
if (cursor > 1) cursor--;
break;
- case ARROW_DOWN:
+ case KEY_DOWN:
case CTRL_N:
case 'j':
if (cursor < n_dir_entries) cursor++;
break;
- case ARROW_LEFT:
+ case KEY_LEFT:
case CTRL_B:
case 'h':
cd_back();
@@ -1197 +1187 @@ int main(int argc, char ** argv) {
first_f = 0;
last_f = LAST_F;
break;
- case ARROW_RIGHT:
+ case KEY_RIGHT:
case CTRL_F:
case 'l':
case '\n':