aboutsummaryrefslogtreecommitdiffstats
path: root/src/keys.c
blob: 4514f9d7dd26e74cf67d060e0016b711ebee5699 (plain) (blame)
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
#include "keys.h"

#include <linux/limits.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>

#include "display.h"
#include "err.h"
#include "fm.h"
#include "log.h"
#include "mem.h"
#include "wm.h"

void
handling_keys(int ch, fm_info *i)
{
	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);
			break;
		} else {
			return;
		}
		break;
	default:
		return;
	}

	need_redraw = true;
}