-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
95 lines (85 loc) · 2.31 KB
/
main.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
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
#include <iostream>
#include <fstream>
#include <string>
void setColor(int textColor)
{
std::cout << "\033[" << textColor << "m";
}
void resetColor()
{
std::cout << "\033[0m";
}
void readFile(const std::string &filePath)
{
std::ifstream file(filePath);
if (file)
{
std::string line;
std::cout << "File content:\n";
while (std::getline(file, line))
{
std::cout << line << std::endl;
}
file.close();
}
else
{
std::cout << "File '" << filePath << "' does not exist." << std::endl;
}
}
void writeFile(const std::string &filePath)
{
std::ofstream file(filePath, std::ios::app);
if (file)
{
std::string input;
std::cout << "Enter text to write to the file (type 'exit' to stop):\n";
while (true)
{
std::getline(std::cin, input);
if (input == "exit")
{
std::cout << "\n\nGoodbye :D!";
break;
}
file << input << std::endl;
}
file.close();
}
else
{
std::cout << "Unable to open file '" << filePath << "' for writing." << std::endl;
}
}
int main()
{
std::string res;
do
{
setColor(31);
std::cout << "===================================================================\n";
resetColor();
std::cout << " Rain Editor \n";
std::cout << "\n\n";
std::cout << " !code - You could write code. \n";
std::cout << " :github - You can see our GitHub repository \n";
std::cout << " rainn:@v - Show the Rain CLI version (Coming soon) \n";
setColor(31);
std::cout << "===================================================================\n";
resetColor();
std::cin >> res;
if (res == ":github")
{
std::cout << "https://github.com/NopAngel/rain - Follow me and give it a Star :D!\n\n";
}
} while (res != "!code");
if (res == "!code")
{
std::string filePath;
std::cout << "Enter the file path: ";
std::cin >> filePath;
readFile(filePath);
writeFile(filePath);
}
return 0;
}