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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#ifndef NEWSBEUTER_KEYMAP__H
#define NEWSBEUTER_KEYMAP__H
#include <string>
#include <map>
#include <utility>
#include <vector>
#include <configparser.h>
// in configuration: bind-key <key> <operation>
enum {
KM_FEEDLIST = 1<<0,
KM_FILEBROWSER = 1<<1,
KM_HELP = 1<<2,
KM_ARTICLELIST = 1<<3,
KM_ARTICLE = 1<<4,
KM_TAGSELECT = 1<<5,
KM_FILTERSELECT = 1<<6,
KM_URLVIEW = 1<<7,
KM_PODBEUTER = 1<<8,
KM_SYSKEYS = 1<<9,
KM_INTERNAL = 1<<10,
KM_DIALOGS = 1<<11,
KM_NEWSBEUTER = KM_FEEDLIST | KM_FILEBROWSER | KM_HELP | KM_ARTICLELIST | KM_ARTICLE | KM_TAGSELECT | KM_FILTERSELECT | KM_URLVIEW | KM_DIALOGS,
KM_BOTH = KM_NEWSBEUTER | KM_PODBEUTER
};
namespace newsbeuter {
enum operation { OP_NIL = 0,
// general and newsbeuter-specific operations:
OP_NB_MIN,
OP_QUIT,
OP_HARDQUIT,
OP_RELOAD,
OP_RELOADALL,
OP_MARKFEEDREAD,
OP_MARKALLFEEDSREAD,
OP_OPEN,
OP_SAVE,
OP_NEXTUNREAD,
OP_PREVUNREAD,
OP_NEXT,
OP_PREV,
OP_OPENINBROWSER,
OP_OPENBROWSER_AND_MARK,
OP_HELP,
OP_TOGGLESOURCEVIEW,
OP_TOGGLEITEMREAD,
OP_TOGGLESHOWREAD,
OP_SHOWURLS,
OP_CLEARTAG,
OP_SETTAG,
OP_SEARCH,
OP_GOTO_URL,
OP_ENQUEUE,
OP_REDRAW,
OP_CMDLINE,
OP_SETFILTER,
OP_CLEARFILTER,
OP_SELECTFILTER,
OP_RELOADURLS,
OP_BOOKMARK,
OP_EDITFLAGS,
OP_NEXTUNREADFEED,
OP_PREVUNREADFEED,
OP_NEXTFEED,
OP_PREVFEED,
OP_MACROPREFIX,
OP_DELETE,
OP_PURGE_DELETED,
OP_EDIT_URLS,
OP_CLOSEDIALOG,
OP_VIEWDIALOGS,
OP_NEXTDIALOG,
OP_PREVDIALOG,
OP_PIPE_TO,
OP_RANDOMUNREAD,
OP_SORT,
OP_REVSORT,
OP_NB_MAX,
// podbeuter-specific operations:
OP_PB_MIN = 1000,
OP_PB_DOWNLOAD,
OP_PB_CANCEL,
OP_PB_DELETE,
OP_PB_PURGE,
OP_PB_TOGGLE_DLALL,
OP_PB_MOREDL,
OP_PB_LESSDL,
OP_PB_PLAY,
OP_PB_MARK_FINISHED,
OP_PB_MAX,
OP_SK_MIN = 1500,
OP_SK_UP,
OP_SK_DOWN,
OP_SK_PGUP,
OP_SK_PGDOWN,
/* TODO: add more user-defined keys here */
OP_SK_HOME,
OP_SK_END,
OP_SK_MAX,
OP_INT_MIN = 2000,
OP_INT_END_CMDLINE,
OP_INT_END_SETFILTER,
OP_INT_BM_END,
OP_INT_EDITFLAGS_END,
OP_INT_START_SEARCH,
OP_INT_GOTO_URL,
OP_INT_END_QUESTION,
OP_INT_CANCEL_QNA,
OP_INT_QNA_NEXTHIST,
OP_INT_QNA_PREVHIST,
OP_INT_RESIZE,
OP_INT_SET,
OP_INT_MAX,
OP_1 = 3001,
OP_2,
OP_3,
OP_4,
OP_5,
OP_6,
OP_7,
OP_8,
OP_9,
OP_0
};
struct keymap_desc {
std::string key;
std::string cmd;
std::string desc;
std::string ctx;
unsigned short flags;
};
struct macrocmd {
operation op;
std::vector<std::string> args;
};
class keymap : public config_action_handler {
public:
keymap(unsigned int flags);
~keymap();
void set_key(operation op, const std::string& key, const std::string& context);
void unset_key(const std::string& key, const std::string& context);
operation get_opcode(const std::string& opstr);
operation get_operation(const std::string& keycode, const std::string& context);
std::vector<macrocmd> get_macro(const std::string& key);
char get_key(const std::string& keycode);
std::string getkey(operation op, const std::string& context);
virtual void handle_action(const std::string& action, const std::vector<std::string>& params);
virtual void dump_config(std::vector<std::string>& config_output);
void get_keymap_descriptions(std::vector<keymap_desc>& descs, unsigned short flags);
unsigned short get_flag_from_context(const std::string& context);
private:
bool is_valid_context(const std::string& context);
std::string getopname(operation op);
std::map<std::string, std::map<std::string, operation> > keymap_;
std::map<std::string,std::vector<macrocmd> > macros_;
};
}
#endif
|