1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#include "keys.h"
#include "display.h"
#include "err.h"
#include "fm.h"
#include "log.h"
#include "mem.h"
#include "utils.h"
#include "wm.h"
#include <errno.h>
#include <linux/limits.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool keymap = false;
void
handling_keys(int ch, fm_info *i)
{
log_write(LOG_INFO, "ch = %d", ch);
/* Control(C) or Alt(M) */
if (ch < 32) {
switch (ch) {
case 14: /* C-n, scroll down in Emacs*/
fm_entries_scroll(i, 1);
break;
case 16: /* C-p scroll up in Emacs */
fm_entries_scroll(i, -1);
break;
/* Page down */
case 4: /* C-d, for Vi users' habit */
case 22: /* C-v, for Emacs users' habit*/
fm_entries_scroll(i, i->windows[PANE_LEFT]->height / 2);
break;
/* Page up */
case 21: /* C-u */
case 27: /* M-v */
fm_entries_scroll(i,
-(i->windows[PANE_LEFT]->height / 2));
break;
}
return;
}
switch (ch) {
#ifdef KEY_RESIZE
case KEY_RESIZE:
handle_resize();
/* TODO: redraw ui */
break;
#endif
/* Quit */
case 'q':
endwin();
exit(0);
/* Down */
case 'j':
fm_entries_scroll(i, 1);
break;
case 'k':
fm_entries_scroll(i, -1);
break;
case 'h':
fm_cd_up(i);
break;
case 'l':
fm_cd_down(i);
break;
case 'o':
case '\n':
case '\r':
case KEY_ENTER:
log_write(LOG_INFO, "Open file");
if (!(i->cur->items[i->cursor].is_dir)) {
char filepath[PATH_MAX];
size_t len =
snprintf(filepath, PATH_MAX, "%s/%s", i->cwd,
i->cur->items[i->cursor].name);
if (len >= PATH_MAX) {
die("snprintf failed");
}
char *argv[] = {enveditor, filepath, NULL};
open_with_editor(argv);
} else {
fm_cd_down(i);
}
break;
case '+':
new_dir(i);
break;
case 'R':
case 'r': {
fm_rename(i);
break;
}
case 'd': {
char path[PATH_MAX] = {0};
size_t len = snprintf(path, sizeof(path), "%s/%s", i->cwd,
i->cur->items[i->cursor].name);
if (len >= PATH_MAX) {
die("Itmes length error");
}
if (fm_rm(path) == 0) {
need_redraw = true;
fm_getdir(i->cur, i->cwd);
} else {
log_write(LOG_ERR, "%s", strerror(errno));
}
break;
}
default:
return;
}
need_redraw = true;
}
|