Skip to content

Commit

Permalink
Merge pull request #36 from su8/main
Browse files Browse the repository at this point in the history
Concatenate the pathc requested constellation instead using multiple …
  • Loading branch information
Haruno19 authored Dec 20, 2022
2 parents aa3c043 + 03da736 commit 02528fd
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/starfetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
using namespace std;
using json = nlohmann::json;

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

Expand All @@ -44,20 +44,18 @@ int main(int argc, char *argv[])
case 'n':
{
if(argc < 3) Error(" ", 0); //if the user requested a '-n' argument but didn't provide a name, an error occours
pathc += "constellations" + SEP; //updating the path to the constellations folder
pathc += argv[2]; //adding the name of the requested constellation to the path
pathc += ".json";
pathc += "constellations" + SEP + argv[2] + ".json"; //updating the path to the constellations folder and adding the name of the requested constallation to the pathc
}
break;
case 'h':
Help();
break;
return EXIT_SUCCESS;
case 'r':
pathc += RandomConst(); //with the '-r' option, it selects a random constellation
break;
case 'l':
PrintList();
break;
return EXIT_SUCCESS;
case 'c':
{
if (argc == 2)
Expand All @@ -79,9 +77,7 @@ int main(int argc, char *argv[])
}
else
{
pathc += "constellations" + SEP; //updating the path to the constellations folder
pathc += argv[4]; //adding the name of the requested constellation to the path
pathc += ".json";
pathc += "constellations" + SEP + argv[4] + ".json"; //updating the path to the constellations folder and adding the name of the requested constellation to the pathc
setColor(argv[2]);
}
}
Expand Down Expand Up @@ -198,19 +194,18 @@ static string RandomConst()
return s;
}

static inline void PrintList()
static void PrintList()
{
string s;

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

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

0 comments on commit 02528fd

Please sign in to comment.