-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
129 lines (117 loc) · 4.38 KB
/
Copy pathmain.cpp
File metadata and controls
129 lines (117 loc) · 4.38 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
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
#include <ctime>
#include <sstream>
#include <iomanip>
#include "Console.h"
using namespace std;
map<string, Console> sessions;
bool in_session = false;
int total_line = 0;
void printHeader() {
cout << " ,-----. ,---. ,-----. ,------. ,------. ,---.,--. ,--. " << endl;
cout << "' .--./' .-' ' .-. '| .--. '| .---'' .-'\\ `.' / " << endl;
cout << "| | `. `-. | | | || '--' || `--, `. `-. '. / " << endl;
cout << "' '--'\\.-' |' '-' '| | --' | `---..-' | | | " << endl;
cout << " `-----'`-----' `-----' `--' `------'`-----' `--' " << endl;
cout << "\nCommand Line Interface" << endl;
cout << "Type 'help' to see available commands" << endl;
}
void clearScreen() {
#ifdef _WIN32
system("cls");
#endif
printHeader();
}
void processCommand(const string& command) {
if (command == "initialize") {
cout << "Initialize command recognized. Doing something." << endl;
}
else if (command.find("screen") == 0) {
size_t s_pos = command.find("-s ");
size_t r_pos = command.find("-r ");
if (s_pos != std::string::npos) {
std::string name = command.substr(s_pos + 3);
if (name.empty()) {
std::cout << "Please provide a session name after '-s'." << std::endl;
} else {
if (sessions.find(name) != sessions.end()) {
std::cout << "Session '" << name << "' already exists." << std::endl;
} else {
Console console(name, total_line, total_line);
sessions[name] = console;
std::cout << "Session '" << name << "' created." << std::endl;
in_session = true;
console.display(total_line);
}
}
}
else if (r_pos != std::string::npos) {
std::string name = command.substr(r_pos + 3);
if (name.empty()) {
std::cout << "Please provide a session name after '-r'." << std::endl;
} else {
if (sessions.find(name) != sessions.end()) {
std::cout << "Session '" << name << "' resumed." << std::endl;
in_session = true;
sessions[name].display(total_line);
} else {
std::cout << "Session '" << name << "' does not exist." << std::endl;
}
}
}
else {
std::cout << "Please provide a proper 'screen' command with '-s <name>' to create or '-r <name>' to resume a session." << std::endl;
}
}
else if (command == "scheduler-test") {
cout << "Scheduler-test command recognized. Doing something." << endl;
}
else if (command == "scheduler-stop") {
cout << "Scheduler-stop command recognized. Doing something." << endl;
}
else if (command == "report-util") {
cout << "Report-util command recognized. Doing something." << endl;
}
else if (command == "clear") {
clearScreen();
}
else if (command == "help") {
cout << "\nAvailable commands:" << endl;
cout << "- initialize: Initialize the system" << endl;
cout << "- screen: Display screen information" << endl;
cout << "- scheduler-test: Test the scheduler" << endl;
cout << "- scheduler-stop: Stop the scheduler" << endl;
cout << "- report-util: Generate utility report" << endl;
cout << "- clear: Clear the screen" << endl;
cout << "- exit: Exit the program" << endl;
cout << "- help: Display this help message" << endl;
}
else if (command == "exit" && in_session == true){
system("cls");
printHeader();
in_session = false;
}
else if (command != "exit") {
cout << "Unknown command. Type 'help' for available commands." << endl;
}
}
int main() {
string command;
// Print initial header
clearScreen();
// Main command loop
while (true) {
cout << "\n> ";
getline(cin, command);
if (command == "exit" && in_session == false) {
cout << "Exit command recognized. Closing the application..." << endl;
break;
}
processCommand(command);
total_line++;
}
return 0;
}