-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.cpp
49 lines (44 loc) · 1.22 KB
/
command.cpp
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
#include "Main.hpp"
std::string Command::runCommand(void) {
std::string line = "";
if (inputCommand == "q") {
system("clear");
printf("\e[?25h");
std::exit(0);
}
if (inputCommand == "w") {
std::ofstream output_file(openFileName, std::ios::out);
for (auto data : fileData) {
output_file << data << std::endl;
}
output_file.close();
}
if (inputCommand[0] == 'o') {
lineNum = 0;
fileData = {};
inputCommand.erase(0, 2);
openFileName = inputCommand;
std::ifstream input_file(openFileName, std::ios::in);
inputCommand = "";
if (!input_file) {
return "Could not open the file -> '" +openFileName + "'";
}
else {
while (getline(input_file, line)) {
fileData.push_back(line);
lineNum++;
bestLine++;
}
if (lineNum == 0) {
lineNum++;
fileData.push_back("\n");
}
lineNum--;
cY = 0;
cX = fileData[cY].length();
input_file.close();
fileDataC = 0;
}
}
return inputCommand;
}