@@ -59,36 +59,25 @@ and remove `-DNCURSES_WIDECHAR=1`
59
59
#include < locale.h>
60
60
#include < ncurses.h>
61
61
#include < panel.h>
62
- #include < stdlib.h>
63
62
#include < string.h>
64
63
#include < unicase.h>
65
64
66
65
#include " st_menu.h"
67
66
68
67
/*
69
68
* Read event. When event is mouse event, read mouse data
70
- *
71
- * Use wide char function when it is available. Then shortcuts
72
- * can be any wide char, else shortcut can be only 8bit char.
73
- * ncurses divides multibyte chars to separate events when a function
74
- * getch is used.
75
69
*/
76
70
static inline int
77
71
get_event (MEVENT * mevent, bool * alt)
78
72
{
79
73
bool first_event = true;
80
74
int c;
81
- wint_t ch;
82
- int ret;
83
75
84
76
*alt = false;
85
77
86
78
repeat:
87
79
88
- ret = get_wch(&ch);
89
- (void) ret;
90
-
91
- c = ch;
80
+ c = getch();
92
81
93
82
/*
94
83
* Read mouse event when it is possible. Do it now, before st_meny_driver call,
@@ -113,6 +102,7 @@ repeat:
113
102
}
114
103
115
104
*alt = !first_event;
105
+
116
106
return c;
117
107
}
118
108
@@ -122,120 +112,22 @@ repeat:
122
112
int
123
113
main()
124
114
{
125
- int maxx, maxy;
126
115
PANEL * mainpanel;
127
116
ST_MENU_CONFIG config;
128
- ST_MENU * active_item;
129
- struct ST_MENU_STATE * mstate ;
117
+ ST_MENU_ITEM * active_item;
118
+ struct ST_MENU * menu ;
130
119
bool activated;
131
120
int c;
132
121
MEVENT mevent;
133
- int i;
134
122
bool alt;
135
- bool requested_exit = false;
136
-
137
- const char *demo =
138
- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore "
139
- "et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
140
- "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum "
141
- "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia"
142
- "deserunt mollit anim id est laborum.";
143
-
144
- ST_MENU _left[] = {
145
- {"~F~ile listing", 1, NULL},
146
- {"~Q~uick view", 2, "C-x q"},
147
- {"~I~nfo", 3, "C-x i"},
148
- {"~T~ree", 4, NULL},
149
- {"--", -1, NULL},
150
- {"~L~isting mode...", 5, NULL},
151
- {"~S~ort order...", 6, NULL},
152
- {"~F~ilter...", 7, NULL},
153
- {"~E~ncoding", 8, "M-e"},
154
- {"--", -1, NULL},
155
- {"FT~P~ link...", 9, NULL},
156
- {"S~h~ell link...", 10, NULL},
157
- {"S~F~TP link...", 11, NULL},
158
- {"SM~B~ link...", 12, NULL},
159
- {"Paneli~z~e", 13, NULL},
160
- {"--", -1, NULL},
161
- {"~R~escan", 14, "C-r"},
162
- {NULL, -1, NULL}
163
- };
164
-
165
- ST_MENU _file[] = {
166
- {"~V~iew", 15, "F3"},
167
- {"Vie~w~ file...",16, NULL},
168
- {"~F~iltered view", 17, "M-!"},
169
- {"~E~dit", 18, "F4"},
170
- {"~C~opy", 19, "F5"},
171
- {"C~h~mod", 20, "C-x c"},
172
- {"~L~ink", 21, "C-x l"},
173
- {"~S~ymlink", 22, "C-x s"},
174
- {"Relative symlin~k~", 23, "C-x v"},
175
- {"Edit s~y~mlink", 24, "C-x C-s"},
176
- {"Ch~o~wn", 25, "C-x o"},
177
- {"~A~dvanced chown", 26, NULL},
178
- {"~R~ename/Move", 27, "F6"},
179
- {"~M~kdir", 28, "F7"},
180
- {"~D~elete", 29, "F8"},
181
- {"~Q~uick cd", 30, "M-c", ST_MENU_OPTION_DISABLED},
182
- {"--", -1, NULL},
183
- {"Select ~g~roup", 31, "+"},
184
- {"U~n~select group", 32, "-"},
185
- {"~I~nvert selection", 33, "*"},
186
- {"--", -1, NULL},
187
- {"E~x~it", 34, "F10"},
188
- {NULL, -1, NULL}
189
- };
190
-
191
- ST_MENU _styles[] = {
192
- {"_1_Midnight black", 70},
193
- {"_2_Midnight", 71},
194
- {"_3_Vision", 72},
195
- {"_4_Dos", 73},
196
- {"_5_FAND 1", 74},
197
- {"_6_FAND 2", 75},
198
- {"_7_Fox", 76},
199
- {"_8_Perfect", 77},
200
- {"_9_No color", 78},
201
- {"_0_One color", 79},
202
- {"_t_Turbo", 80},
203
- {"_p_Pdmenu", 81, NULL, ST_MENU_OPTION_DEFAULT},
204
- {"_o_Old Turbo", 82},
205
- {NULL, -1, NULL}
206
- };
207
123
208
- ST_MENU _command[] = {
209
- {"~U~ser menu", 35, "F2"},
210
- {"~D~irectory tree", 36, NULL},
211
- {"~F~ind file", 37, "M-?"},
212
- {"S~w~ap panels", 38, "C-u"},
213
- {"Switch ~p~anels on/off", 39, "C-o"},
214
- {"~C~ompare directories", 40, "C-x d"},
215
- {"C~o~mpare files", 41, "C-x C-d"},
216
- {"E~x~ternal panelize", 42, "C-x !"},
217
- {"~S~how directory sizes", 43, "C-Space"},
218
- {"--", -1, NULL},
219
- {"Command ~h~istory", 44, "M-h"},
220
- {"Di~r~ectory hotlist", 45, "C-\\"},
221
- {"~A~ctive VFS list", 46, "C-x a"},
222
- {"~B~ackground jobs", 47, "C-x j"},
223
- {"Screen lis~t~", 48, "M-`"},
224
- {"--", -1, NULL},
225
- {"Edit ~e~xtension file", 49, NULL},
226
- {"Edit ~m~enu file", 50, NULL},
227
- {"Edit highli~g~hting group file", 51, NULL},
228
- {"--", -1, NULL},
229
- {"Set st~y~le", 52, NULL, 0, _styles},
230
- {"_@_Do something on current file", 53, NULL},
124
+ ST_MENU_ITEM _file[] = {
125
+ {"E~x~it", 34, "Alt-x"},
231
126
{NULL, -1, NULL}
232
127
};
233
128
234
- ST_MENU menubar[] = {
235
- {"~L~eft", 60, NULL, 0, _left},
129
+ ST_MENU_ITEM menubar[] = {
236
130
{"~F~ile", 61, NULL, 0, _file},
237
- {"~C~ommand", 62, NULL, 0, _command},
238
- {"~O~ptions", 63, NULL, ST_MENU_OPTION_DISABLED, NULL},
239
131
{NULL, -1, NULL}
240
132
};
241
133
@@ -253,153 +145,70 @@ main()
253
145
noecho();
254
146
keypad(stdscr, TRUE);
255
147
148
+ #ifdef NCURSES_EXT_FUNCS
149
+
150
+ set_escdelay(25);
151
+
152
+ #endif
153
+
256
154
refresh();
257
155
258
156
init_pair(1, COLOR_WHITE, COLOR_BLUE);
259
157
260
158
/* load style, possible alternatives: ST_MENU_STYLE_MC, ST_MENU_STYLE_DOS */
261
- st_menu_load_style(&config, 11, 2);
262
-
263
- set_escdelay(25);
159
+ st_menu_load_style(&config, ST_MENU_STYLE_VISION, 2);
264
160
265
- /* BUTTON1_PRESSED | BUTTON1_RELEASED are mandatory enabled */
266
- mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
161
+ mousemask(BUTTON1_PRESSED | BUTTON1_RELEASED, NULL);
267
162
mouseinterval(0);
268
163
269
164
/* prepare main window */
270
- getmaxyx(stdscr, maxy, maxx);
271
165
wbkgd(stdscr, COLOR_PAIR(1));
272
-
273
- for (i = 0; i <= maxy; i++)
274
- {
275
- wmove(stdscr, i, 0);
276
-
277
- waddnstr(stdscr, demo + i , maxx);
278
- }
279
-
280
166
wrefresh(stdscr);
281
167
282
168
/*
283
169
* main window should be panelized. Only panels can be
284
170
* overlapped without unwanted effects.
285
171
*/
286
172
mainpanel = new_panel(stdscr);
287
-
288
- /* pass desktop panel to lib to show shadows correctly */
289
173
st_menu_set_desktop_panel(mainpanel);
290
174
291
175
/* prepare state variable for menubar */
292
- mstate = st_menu_new_menubar(&config, menubar);
176
+ menu = st_menu_new_menubar(&config, menubar);
293
177
294
178
/* post meubar (display it) */
295
- st_menu_post(mstate );
179
+ st_menu_post(menu );
296
180
297
181
c = get_event(&mevent, &alt);
298
182
299
183
refresh();
300
184
301
- while (!requested_exit )
185
+ while (1 )
302
186
{
303
187
bool processed = false;
304
188
305
- /*
306
- * test of possible shortcuts should be done before
307
- * st_menu_driver call. Here is test on F10 displayed on exit
308
- * field.
309
- */
310
- if (c == KEY_F(10))
311
- {
312
- requested_exit = true;
313
- break;
314
- }
315
-
316
- if (c == KEY_RESIZE)
317
- {
318
- int cursor_store[1024];
319
-
320
- getmaxyx(stdscr, maxy, maxx);
321
- wbkgd(stdscr, COLOR_PAIR(1));
322
-
323
- for (i = 0; i <= maxy; i++)
324
- {
325
- wmove(stdscr, i, 0);
326
-
327
- waddnstr(stdscr, demo + i , maxx);
328
- }
329
-
330
- wnoutrefresh(stdscr);
331
-
332
- st_menu_save(mstate, cursor_store, 1023);
333
-
334
- st_menu_delete(mstate);
335
- mstate = st_menu_new_menubar(&config, menubar);
336
-
337
- st_menu_load(mstate, cursor_store);
338
-
339
- st_menu_post(mstate);
340
-
341
- doupdate();
342
- }
343
- else
344
- processed = st_menu_driver(mstate, c, alt, &mevent);
189
+ processed = st_menu_driver(menu, c, alt, &mevent);
345
190
346
191
doupdate();
347
192
348
193
active_item = st_menu_selected_item(&activated);
349
- if (processed && active_item && activated)
194
+ if (processed && activated)
350
195
{
351
- if (active_item->code >= 70 && active_item->code <= 82)
352
- {
353
- int style = active_item->code - 70;
354
- int cursor_store[1024];
355
-
356
- st_menu_save(mstate, cursor_store, 1023);
357
-
358
- st_menu_delete(mstate);
359
-
360
- st_menu_load_style(&config,
361
- style, style == ST_MENU_STYLE_ONECOLOR ? 1 : 2);
362
-
363
- mstate = st_menu_new_menubar(&config, menubar);
364
-
365
- st_menu_load(mstate, cursor_store);
366
-
367
- st_menu_post(mstate);
368
-
369
- refresh();
370
- }
371
196
/* here is processing of menucode related to Exit menu item */
372
- else if (active_item->code == 34)
373
- {
374
- requested_exit = true;
375
- break;
376
- }
377
- else
197
+ if (active_item->code == 34)
378
198
break;
379
199
}
380
200
381
- /* q is common command for exit (when it is not used like accelerator */
382
- if (c == 'q' && !activated)
383
- {
384
- requested_exit = true;
201
+ if (!processed && alt && c == 'x')
385
202
break;
386
- }
387
203
388
204
/* get new event */
389
205
c = get_event(&mevent, &alt);
390
206
}
391
207
392
208
endwin();
393
209
394
- st_menu_unpost(mstate, true);
395
- st_menu_delete(mstate);
396
-
397
- if (requested_exit)
398
- printf("exiting...\n");
399
- else if (active_item)
400
- printf("selected text: %s, code: %d\n", active_item->text, active_item->code);
401
- else
402
- printf("ending without select menu item\n");
210
+ st_menu_unpost(menu, true);
211
+ st_menu_free(menu);
403
212
404
213
return 0;
405
214
}
0 commit comments