-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntry.cpp
More file actions
336 lines (279 loc) · 9.29 KB
/
Copy pathEntry.cpp
File metadata and controls
336 lines (279 loc) · 9.29 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#define Clear std::cout << "\033[2J\033[;H"
//varibles for color
char normal[] = { 0x1b, '[', '0', ';', '3', '9', 'm', 0 };
char black[] = { 0x1b, '[', '1', ';', '3', '0', 'm', 0 };
char red[] = { 0x1b, '[', '1', ';', '3', '1', 'm', 0 };
char green[] = { 0x1b, '[', '1', ';', '3', '2', 'm', 0 };
char yellow[] = { 0x1b, '[', '1', ';', '3', '3', 'm', 0 };
char blue[] = { 0x1b, '[', '1', ';', '3', '4', 'm', 0 };
char magenta[] = { 0x1b, '[', '1', ';', '3', '5', 'm', 0 };
char cyan[] = { 0x1b, '[', '1', ';', '3', '6', 'm', 0 };
char white[] = { 0x1b, '[', '1', ';', '3', '7', 'm', 0 };
//varibles for Menu Function
int num=0;
int sel=0;
bool ColorOn;
bool WideOn;
bool my_popen (const std::string& cmd,std::vector<std::string>& out );
int Menu(int Selection);
void get_int(int& d, std::string prompt, std::string fail);
void PrintMenu(std::vector<std::string>& FileMenu);
// Print the menu
//void FillMenu(std::vector<std::string>& FileMenu);
int GetOptions();
int GetFiles();
void Pause(int x);
int main () {
//varibles for menu and user input
GetOptions();
GetFiles();
return 0;
}
bool my_popen (const std::string& cmd,std::vector<std::string>& out ) {
//system call with output to vector
bool ret_boolValue = true;
FILE* fp;
const int SIZEBUF = 1234;
char buf [SIZEBUF];
out = std::vector<std::string> ();
if ((fp = popen(cmd.c_str (), "r")) == NULL)
{
return false;
}
std::string cur_string = "";
while (fgets(buf, sizeof (buf), fp))
{
cur_string += buf;
}
out.push_back (cur_string.substr (0, cur_string.size () - 1));
pclose(fp);
return true;
}
int GetOptions()
{
//system("clear");
//std::cout << "\033[2J\033[;H";
Clear;
char ColorSelect;
std::cout << "Do you want color? <Y/N>\n";
std::cin >> ColorSelect;
switch (ColorSelect)
{
case 'Y':
case 'y':
ColorOn = true;
if (ColorOn == true)
{
std::cout << "Color display is ON\n";
}
break;
case 'N':
case 'n':
WideOn = false;
if (ColorOn == false)
{
std::cout << "Color display is OFF\n";
}
break;
default:
std::cout << "Please press <Y/N>\n";
break;
}
char WidthSelect;
std::cout << "Do you want wide display <Y/N>\n";
std::cin >> WidthSelect;
switch (WidthSelect)
{
case 'Y':
case 'y':
WideOn = true;
if (WideOn == true)
{
std::cout << "Wide Display is ON\n";
}
break;
case 'N':
case 'n':
WideOn = false;
if (WideOn == false)
{
std::cout << "Wide Display is OFF\n";
}
break;
default:
std::cout << "Please press <Y/N>\n";
break;
}
}
void PrintMenu(std::vector<std::string>& FileMenu)
{
//cycle through vector and print output
int x=1;
int y=0;
//system("clear");
//std::cout << "\033[2J\033[;H";
Clear;
for (unsigned int i = 0; i < FileMenu.size()-1; i++, x++)
{
// //horizontal display
if (ColorOn == 1 && WideOn == 1)
{
//size_t FileSize = FileMenu.size();
// if ((FileSize % 2) == 0)
// {
// std::cout << "Even";
// }
// else
// {
// std::cout << "Odd";
// }
// if (i+2 < FileSize)
{
std::cout << "\033[" << x << ";" << 0 << "H" << green << " [" << blue << i+1 << green << "] " << " " << cyan << FileMenu[i] << " " <<
"\033[" << x << ";" << 40 << "H" << green << " [" << blue << i+2 << green << "] " << " " << cyan << FileMenu[i+1] << normal << "\n ";
//<< "\033[1;0H"
//
i += 1;
Pause(x);
}
// std::cout << "\033[" << x << ";" << 0 << "H" << green << "[" << blue << i+1 << green << "]"<< " " << cyan << FileMenu[i] <<
// "\033[" << x << ";" << 20 << "H" << green << "[" << blue << i+2 << green << "]"<< " " << cyan << FileMenu[i+1] <<
// "\033[" << x << ";" << 40 << "H" << green << "[" << blue << i+3 << green << "]"<< " " << cyan << FileMenu[i+2] << normal;
}
if (ColorOn == 0 && WideOn == 1 )
{
// std::cout << "\033[" << x << ";" << 0 << "H" << " [" << i+1 << "] " << " " << FileMenu[i] << " "
// << "\033[" << x << ";" << 20 << "H" << " [" << i+2 << "] " << " " << FileMenu[i+1]
// << "\033[" << x << ";" << 40 << "H" << " [" << i+3 << "] " << " " << FileMenu[i+2] << " \n";
std::cout << "\033[" << x << ";" << 0 << "H" << " [" << i+1 << "] " << " " << FileMenu[i] << " "
<< "\033[" << x << ";" << 40 << "H" << " [" << i+2 << "] " << " " << FileMenu[i+1] << "\n ";
i += 1;
Pause(x);
//vertical display
}
else if (ColorOn == 1 && WideOn == 0)
{
std::cout << green << "[" << blue << i+1 << green << "]"<< " " << cyan << FileMenu[i] << " \n" << normal;
Pause(x);
}
else if (ColorOn == 0 && WideOn == 0)
{
std::cout << "[" << i+1 << "]"<< " " << FileMenu[i] << " " << normal <<std::endl;
Pause(x);
}
}
}
void get_int(int& d, std::string prompt, std::string fail)
{
while(1) {
std::cout << magenta << prompt << normal;
std::string str;
std::cin >> str;
std::istringstream ss(str);
int val1;
ss >> val1;
if(!ss.eof()) {
std::cout << red << fail << normal;
continue;
} else {
d = val1;
break;
}
}
}
int Menu(int Selection)
{
//std::cout << "Enter the number of the program you want to run: \n\t(0 or any letter to Exit):=> ";
//std::cin >> sel;
std::cout << blue << "\n_________________________________________________\n" << normal;
get_int(sel, "\n\t Please enter the number of the\n\t program you would like to run:\n\t(Enter 0 to exit):=> ", "Sorry, that's not an integer. \n");
if(sel > num)
{
std::cout << red << "ERROR: Please enter a valid selection\n" << normal;
//main();
Menu(sel);
return Selection;
}
}
int GetFiles()
{
//my_open output vector
std::vector<std::string> output;
//sytem calls for output vector
// my_popen("ls ~/ -Fla | grep \*$ | awk '{print $9}' | cut -d '*' -f1 ", output);
//my_popen(" find ~/ -maxdepth 1 -executable -type f -print0 | xargs -0", output);
my_popen("ls -F | grep '*' | cut -d '*' -f1", output);
//my_popen("ls -F | grep '*' | cut -d '*' -f1", output);
//display output vector
for ( std::vector<std::string>::iterator itr = output.begin(); itr != output.end(); ++itr )
{
for (unsigned int i = 0; i < output.size(); i++ , num++, output.size()-1)
{
//std::cout << "(" << num << ")" << std::endl;
//std::cout << std::endl << "[" << output.size() << "]" << " " << output.at(i);}
//std::cout << *itr;
}
//parse vector into peices seperated by spaces
std::string s(*itr);
std::istringstream iss(s);
std::string sub;
std::vector<std::string> FileMenu;
//display menu
do
{
std::string sub;
iss >> sub;
// std::cout << std::endl << num << " Substring: " << sub << std::endl;
while( num > FileMenu.size())
{
FileMenu.push_back(sub);
//PrintMenu(FileMenu);
}
//PrintMenu(FileMenu);
num++;
}while (iss);
PrintMenu(FileMenu);
//ask for user input to run selected program file
// and error check input
do
{
int Selection;
Menu(Selection);
std::string SysRun;
//add Linux synstax to file selection
//FileMenu.erase(FileMenu.begin() + sel+1);
if (sel > 0)
{
SysRun = "./" + FileMenu[sel-1];
//system call with string to char conversion
system(SysRun.c_str());
system("read -p 'Press Enter' key");
}
else
{
return 0;
}
//delete &FileMenu;
//delete &output;
}while (sel > 1);
}
}
void Pause(int x)
{
if (x == 20 || x == 40 || x == 60|| x == 80 || x == 100 || x == 120 )
{
system("read -p '\nDisplay Output Paused, please hit <Enter> to continue\n' key");
}
// else if ()
}