diff --git a/noshx.cpp b/noshx.cpp index 08729dc402172df090663a47cb875bdda1005dd8..ac87a5ce52ac89dec59ac2cbd417fa4e9feb3964 100644 --- a/noshx.cpp +++ b/noshx.cpp @@ -30,15 +30,14 @@ * * CHANGELOG * - * Noémi Shell X ver. 0.2 + * Noémi Shell X ver. 0.2.1 * - * This version introduses the cd command. In additon, this version is changing - * the prompt, to be more 'UNIX' like. - * The prompt will now always show the current working directory, without requiring - * the 'pwd' command. The 'pwd' command is NOT removed. - * This version also introduces colors to the terminal, as highlighting. This is NOT syntax highligthing - * that may come in a future update. - * + * This version is using a much cleaner way to draw the heart shape at the Noemi function, + * by using for loops instad of manual measurments. This version also made the prompt even + * more unix like, by displaying '~' when at home instead of 'home' as well as using the + * '$' instad of the '>' character. I also added a sweet function. If you use the 'now' + * command on may 21st (Noémi's birthday), a yellow, bold, highlighted + * text will say: 'Happy birthday, Noemi!' */ @@ -52,9 +51,10 @@ #include <regex> // For grasp filtering #include <cstdlib> #include <limits.h> +#include <cmath> -const char VERSION[] = "0.2"; ///< Change version number here for the entire code +const char VERSION[] = "0.2.1"; ///< Change version number here for the entire code #define STRLEN 100 ///< Max string length #define WIDTH 10 ///< Width between columns @@ -101,12 +101,19 @@ int main() { while (true) { char buffer[PATH_MAX]; - string cwd = getcwd(buffer, sizeof(buffer)); + + const char* home = getenv("HOME"); + if (home != nullptr) { + string home_str = home; + if (cwd.find(home_str) == 0) { // cwd starts with home + cwd.replace(0, home_str.length(), "~"); + } +} cout << "\033[1;33mnoshx: \033[0m" // Yellow "noshx:" - << "\033[1;96m" << cwd << "\033[0m" // Bold magenta cwd - << ">\033[0m "; // Normal > + << "\033[1;34m" << cwd << "\033[0m" // Bold magenta cwd + << "$\033[0m "; // Normal > getline(cin, command); @@ -221,6 +228,10 @@ void handle_now(const vector<string>& args){ // Print out date and time cout << "\n" << ctime(×tamp) << "\n"; + + if (localtime(×tamp)->tm_mon == 4 && localtime(×tamp)->tm_mday == 21) { + cout << "\033[1;33mHappy birthday, Noemi! \033[0m"; + } } @@ -395,50 +406,30 @@ void handle_noemi(const vector<string>& args){ return; // Exit early } - float time = 0.9; // Default time 60; + float time = 0.1; // Default: 0.5 seconds (short) - // In case an argument follows the command - if (args.size() == 2){ - const string option = args[1]; // Set the option variable to the first argument - - if (option == "-l"){ - time = 1; // 500 milliseconds between each line - } - else{ - cout << "noemi: unrecognized argument " << args[1] << "\n"; - return; // Exit early; + if (args.size() == 2) { + const string option = args[1]; + + if (option == "-l") { + time = 1.0; // Long delay + } else { + cout << "noemi: unrecognized argument '" << args[1] << "'\n"; + return; + } + } + + for (float y = 1.3; y >= -1.1; y -= 0.06) { + for (float x = -1.2; x <= 1.2; x += 0.025) { + if (pow((x * x + y * y - 1.0), 3) - x * x * y * y * y <= 0.0) + cout << '#'; + else + cout << ' '; } + cout << endl; + usleep(static_cast<useconds_t>(time * 1'000'000)); // sleep after each line } - cout << " \n\t ######### ########\n"; - sleep(time); - cout << " ############ ###########\n"; - sleep(time); - cout << " ############### ###############\n"; - sleep(time); - cout << " #################################\n"; - sleep(time); - cout << " ###################################\n"; - sleep(time); - cout << " ###################################\n"; - sleep(time); - cout << " #################################\n"; - sleep(time); - cout << " ###############################\n"; - sleep(time); - cout << " ###########################\n"; - sleep(time); - cout << " #######################\n"; - sleep(time); - cout << " ###################\n"; - sleep(time); - cout << " ###############\n"; - sleep(time); - cout << " #######\n"; - sleep(time); - cout << " ###\n"; - sleep(time); - cout << " #\n\n"; } /**