-
Notifications
You must be signed in to change notification settings - Fork 1
/
keys.c
63 lines (52 loc) · 1.34 KB
/
keys.c
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
#include "keys.h"
#include "listview.h"
#include "detailview.h"
#include "listview-keys.h"
#include "detailview-keys.h"
keypress_result conch_keypress_dispatch(const int key, view_type current_view,
void *view_state) {
switch (key) {
case 'q':
return CONCH_EXIT;
case '@':
// Toggle "conch view"
if (current_view == VIEW_CONCH) {
return CONCH_LIST;
} else {
return CONCH_CONCH;
}
case -1:
break;
default:
switch (current_view) {
case VIEW_LIST:
return conch_listview_keypress_dispatch(key, (listview *)view_state);
case VIEW_DETAIL:
return conch_detailview_keypress_dispatch(key, (detailview *)view_state);
case VIEW_CONCH:
break;
}
}
return CONCH_NOP;
}
void conch_default_input_config() {
// Disable line buffering
cbreak();
// Turn terminal local keypress echo off
noecho();
// Turn on "half delay" mode, in which getch functions will block for up to n
// tenths of a second before returning ERR.
halfdelay(KEY_DELAY);
// Hide the cursor
const int cursor_invisible = 0;
curs_set(cursor_invisible);
}
void conch_getstr_input_config() {
// Turn local echo back on
echo();
// Make the input cursor visible
curs_set(1);
// Show the cursor again
const int cursor_visible = 1;
curs_set(cursor_visible);
}