Skip to content

Commit a6e3576

Browse files
committedMay 15, 2018
update doc
1 parent 4def740 commit a6e3576

File tree

1 file changed

+24
-215
lines changed

1 file changed

+24
-215
lines changed
 

‎README.md

+24-215
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,25 @@ and remove `-DNCURSES_WIDECHAR=1`
5959
#include <locale.h>
6060
#include <ncurses.h>
6161
#include <panel.h>
62-
#include <stdlib.h>
6362
#include <string.h>
6463
#include <unicase.h>
6564

6665
#include "st_menu.h"
6766

6867
/*
6968
* 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.
7569
*/
7670
static inline int
7771
get_event(MEVENT *mevent, bool *alt)
7872
{
7973
bool first_event = true;
8074
int c;
81-
wint_t ch;
82-
int ret;
8375

8476
*alt = false;
8577

8678
repeat:
8779

88-
ret = get_wch(&ch);
89-
(void) ret;
90-
91-
c = ch;
80+
c = getch();
9281

9382
/*
9483
* Read mouse event when it is possible. Do it now, before st_meny_driver call,
@@ -113,6 +102,7 @@ repeat:
113102
}
114103

115104
*alt = !first_event;
105+
116106
return c;
117107
}
118108

@@ -122,120 +112,22 @@ repeat:
122112
int
123113
main()
124114
{
125-
int maxx, maxy;
126115
PANEL *mainpanel;
127116
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;
130119
bool activated;
131120
int c;
132121
MEVENT mevent;
133-
int i;
134122
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-
};
207123

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"},
231126
{NULL, -1, NULL}
232127
};
233128

234-
ST_MENU menubar[] = {
235-
{"~L~eft", 60, NULL, 0, _left},
129+
ST_MENU_ITEM menubar[] = {
236130
{"~F~ile", 61, NULL, 0, _file},
237-
{"~C~ommand", 62, NULL, 0, _command},
238-
{"~O~ptions", 63, NULL, ST_MENU_OPTION_DISABLED, NULL},
239131
{NULL, -1, NULL}
240132
};
241133

@@ -253,153 +145,70 @@ main()
253145
noecho();
254146
keypad(stdscr, TRUE);
255147

148+
#ifdef NCURSES_EXT_FUNCS
149+
150+
set_escdelay(25);
151+
152+
#endif
153+
256154
refresh();
257155

258156
init_pair(1, COLOR_WHITE, COLOR_BLUE);
259157

260158
/* 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);
264160

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);
267162
mouseinterval(0);
268163

269164
/* prepare main window */
270-
getmaxyx(stdscr, maxy, maxx);
271165
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-
280166
wrefresh(stdscr);
281167

282168
/*
283169
* main window should be panelized. Only panels can be
284170
* overlapped without unwanted effects.
285171
*/
286172
mainpanel = new_panel(stdscr);
287-
288-
/* pass desktop panel to lib to show shadows correctly */
289173
st_menu_set_desktop_panel(mainpanel);
290174

291175
/* prepare state variable for menubar */
292-
mstate = st_menu_new_menubar(&config, menubar);
176+
menu = st_menu_new_menubar(&config, menubar);
293177

294178
/* post meubar (display it) */
295-
st_menu_post(mstate);
179+
st_menu_post(menu);
296180

297181
c = get_event(&mevent, &alt);
298182

299183
refresh();
300184

301-
while (!requested_exit)
185+
while (1)
302186
{
303187
bool processed = false;
304188

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);
345190

346191
doupdate();
347192

348193
active_item = st_menu_selected_item(&activated);
349-
if (processed && active_item && activated)
194+
if (processed && activated)
350195
{
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-
}
371196
/* 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)
378198
break;
379199
}
380200

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')
385202
break;
386-
}
387203

388204
/* get new event */
389205
c = get_event(&mevent, &alt);
390206
}
391207

392208
endwin();
393209

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);
403212

404213
return 0;
405214
}

0 commit comments

Comments
 (0)