-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu.c
121 lines (105 loc) · 3.66 KB
/
menu.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
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
/* menu.c
*
* Omnitty SSH Multiplexer
* Copyright (c) 2004 Bruno Takahashi C. de Oliveira
* All rights reserved.
*
* LICENSE INFORMATION:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Copyright (c) 2002 Bruno T. C. de Oliveira
*/
#include "menu.h"
#include "curutil.h"
#include "machmgr.h"
#include <ncurses.h>
#include <stdlib.h>
#include "help.h"
#define MENU_LINES 12
#define MENU_COLS 38
#define MENU_CONTENTS \
"{[h]} online help\n" \
"{[r]} rename machine\n" \
"{[t]} tag all machines (live only)\n" \
"{[T]} tag all machines (live & dead)\n" \
"{[u]} untag all machines\n" \
"{[z]} delete dead machines\n" \
"{[d]} delete all TAGGED machines\n" \
"{[X]} delete all machines\n" \
"{[q]} quit application\n"
#include "minibuf.h"
static WINDOW *minibuf = NULL;
void menu_init(WINDOW *minibuf_win) {
minibuf = minibuf_win;
}
void menu_show() {
int termwidth, termheight;
char buf[16];
const char *p; int i; int ch;
WINDOW *w;
getmaxyx(stdscr, termheight, termwidth);
w = newwin(MENU_LINES, MENU_COLS, (termheight - MENU_LINES)/2,
(termwidth - MENU_COLS )/2);
werase(w);
curutil_attrset(w, 0xF4);
curutil_window_fill(w, ' ');
wborder(w, 0, 0, 0, 0, 0, 0, 0, 0);
wmove(w, 0, 3); waddstr(w, "[ Menu ]");
wmove(w, i = 1, 1);
p = MENU_CONTENTS;
while (*p) {
if (*p == '{') curutil_attrset(w, 0xE4);
else if (*p == '}') curutil_attrset(w, 0xF4);
else if (*p == '\n') wmove(w, ++i, 1);
else waddch(w, *p);
p++;
}
wmove(w, ++i, 1);
curutil_attrset(w, 0xE4);
waddstr(w, "Select an option: ");
wrefresh(w);
while (0 > (ch = getch())) ;
switch (ch) {
case 'h': help_show(); break;
case 'r':
*buf = 0;
minibuf_prompt(minibuf,
"Enter new machine name: ", 0x90, buf, 15);
machmgr_rename(buf);
break;
case 'q': *buf = 0;
if (minibuf_prompt(minibuf,
"Really quit application [y/n]?", 0x90, buf, 2)
&& (*buf == 'y' || *buf == 'Y')) {
endwin();
exit(0);
}
break;
case 't': machmgr_tag_all(true); break;
case 'T': machmgr_tag_all(false); break;
case 'u': machmgr_untag_all(); break;
case 'z': machmgr_delete_dead(); break;
case 'd': *buf = 0;
if (minibuf_prompt(minibuf,
"Really delete all TAGGED machines [y/n]?", 0x90, buf, 2)
&& (*buf == 'y' || *buf == 'Y')) machmgr_delete_tagged();
break;
case 'X': *buf = 0;
if (minibuf_prompt(minibuf,
"Really delete ALL machines [y/n]?", 0x90, buf, 2)
&& (*buf == 'y' || *buf == 'Y')) machmgr_delete_all();
break;
}
delwin(w);
}