Skip to content

Commit 02528fd

Browse files
authored
Merge pull request #36 from su8/main
Concatenate the pathc requested constellation instead using multiple …
2 parents aa3c043 + 03da736 commit 02528fd

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/starfetch.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
using namespace std;
1717
using json = nlohmann::json;
1818

19-
static void setColor(const char *str);
19+
static void setColor(const char *str); //sets given color to the REQUESTED_COLOR variable to colorize the output constellation
2020
static inline void PrintConst(string &pathc); //formats the template file with the requested data and prints out the constellation info
2121
static string RandomConst(); //select a random constellation from the available ones
22-
static inline void PrintList(); //prints out the list of the available constellations
22+
static void PrintList(); //prints out the list of the available constellations
2323
static void Error(const char *err, int type); //shows an error message
2424
static void Help(); //prints out the help message
2525

@@ -44,20 +44,18 @@ int main(int argc, char *argv[])
4444
case 'n':
4545
{
4646
if(argc < 3) Error(" ", 0); //if the user requested a '-n' argument but didn't provide a name, an error occours
47-
pathc += "constellations" + SEP; //updating the path to the constellations folder
48-
pathc += argv[2]; //adding the name of the requested constellation to the path
49-
pathc += ".json";
47+
pathc += "constellations" + SEP + argv[2] + ".json"; //updating the path to the constellations folder and adding the name of the requested constallation to the pathc
5048
}
5149
break;
5250
case 'h':
5351
Help();
54-
break;
52+
return EXIT_SUCCESS;
5553
case 'r':
5654
pathc += RandomConst(); //with the '-r' option, it selects a random constellation
5755
break;
5856
case 'l':
5957
PrintList();
60-
break;
58+
return EXIT_SUCCESS;
6159
case 'c':
6260
{
6361
if (argc == 2)
@@ -79,9 +77,7 @@ int main(int argc, char *argv[])
7977
}
8078
else
8179
{
82-
pathc += "constellations" + SEP; //updating the path to the constellations folder
83-
pathc += argv[4]; //adding the name of the requested constellation to the path
84-
pathc += ".json";
80+
pathc += "constellations" + SEP + argv[4] + ".json"; //updating the path to the constellations folder and adding the name of the requested constellation to the pathc
8581
setColor(argv[2]);
8682
}
8783
}
@@ -198,19 +194,18 @@ static string RandomConst()
198194
return s;
199195
}
200196

201-
static inline void PrintList()
197+
static void PrintList()
202198
{
203199
string s;
204200

205-
cout << "\e[1;37mavailable constellations\e[0m: " << endl;
201+
cout << REQUESTED_COLOR + "available constellations\033[0;0m:" << endl;
206202
//prints every constellation name from the files name in the "constellations/" directory
207203
for (const auto & entry : filesystem::directory_iterator(path+"constellations" + SEP))
208204
{
209205
s = entry.path().u8string().substr(entry.path().u8string().find("constellations" + SEP)+15); //from "/usr/local/opt/starfetch/res/constellations/xxxxxx" to "xxxxxx"
210206
s = s.substr(0, s.length()-5);
211207
if(s != ".DS_") cout << REQUESTED_COLOR + s + "\033[0;0m" << endl;
212208
}
213-
exit(EXIT_SUCCESS);
214209
}
215210

216211
static void Error(const char *err, int code)

0 commit comments

Comments
 (0)