Skip to content

Commit

Permalink
Merge pull request #36 from DashPolo/cross_play
Browse files Browse the repository at this point in the history
cpad: fix clang-format
  • Loading branch information
DashPolo authored Apr 30, 2022
2 parents 15568ef + 67476a6 commit 498707d
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 209 deletions.
6 changes: 3 additions & 3 deletions src/argument-type.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "argument-type.hh"
#include <iostream>

#include <iostream>

ArgumentType::ELEMENT_TYPE ArgumentType::convert_to_element_type(std::string& argument)
ArgumentType::ELEMENT_TYPE
ArgumentType::convert_to_element_type(std::string &argument)
{
if (argument == "-ac")
return ELEMENT_TYPE::CREATE_COMMAND;
Expand Down Expand Up @@ -39,5 +40,4 @@ int ArgumentType::number_arguments_expected(ELEMENT_TYPE element_type)
return -1;
}
return -1;

}
6 changes: 3 additions & 3 deletions src/argument-type.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "singleton.hh"
#include <string>

#include "singleton.hh"

class ArgumentType : public Singleton<ArgumentType>
{
public:
Expand All @@ -18,7 +19,6 @@ public:
CREATE_COMBO
};


ELEMENT_TYPE convert_to_element_type(std::string& argument);
ELEMENT_TYPE convert_to_element_type(std::string &argument);
int number_arguments_expected(ELEMENT_TYPE element_type);
};
8 changes: 4 additions & 4 deletions src/convertor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "element.hh"


void Convertor::add_command(std::map<std::string, Folder> &map,
std::string &key, std::string &command)
{
Expand Down Expand Up @@ -87,7 +86,7 @@ void Convertor::combo(std::map<std::string, Folder> &map, std::string &key,
map[key].get_elements().push_back(combo);
}

std::map<std::string, Folder> Convertor::read(std::string &path, bool& emoji)
std::map<std::string, Folder> Convertor::read(std::string &path, bool &emoji)
{
auto map = std::map<std::string, Folder>();

Expand Down Expand Up @@ -170,10 +169,11 @@ std::map<std::string, Folder> Convertor::read(std::string &path, bool& emoji)
return map;
}

void Convertor::write(std::map<std::string, Folder> &map, std::string &path, bool emoji)
void Convertor::write(std::map<std::string, Folder> &map, std::string &path,
bool emoji)
{
std::ofstream MyFile(path);

MyFile << "EMOJI " << (emoji ? "TRUE" : "FALSE") << "\n";
for (auto &folder : map)
{
Expand Down
5 changes: 3 additions & 2 deletions src/convertor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
class Convertor : public Singleton<Convertor>
{
public:
std::map<std::string, Folder> read(std::string &path, bool& emoji);
void write(std::map<std::string, Folder> &map, std::string &path, bool emoji);
std::map<std::string, Folder> read(std::string &path, bool &emoji);
void write(std::map<std::string, Folder> &map, std::string &path,
bool emoji);

void add_command(std::map<std::string, Folder> &map, std::string &key,
std::string &command);
Expand Down
117 changes: 79 additions & 38 deletions src/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ void Display::execute(std::string &command, bool emoji, bool clear)
std::cout << "---\n\n";
}

void Display::execute_combo(std::string &command, std::string display_line, Element& element_combo, bool emoji)
void Display::execute_combo(std::string &command, std::string display_line,
Element &element_combo, bool emoji)
{
set_display_line(display_line, "COMBO EXECUTION:", "✔️ ", "", BOLDGREEN,
emoji);
std::cout << RESET << display_line << RESET << WHITE << ' '
<< command << RESET << '\n'
std::cout << RESET << display_line << RESET << WHITE << ' ' << command
<< RESET << '\n'
<< std::endl;
for (auto &command : element_combo.get_combo_elements_())
{
Expand All @@ -31,7 +32,8 @@ void Display::execute_combo(std::string &command, std::string display_line, Elem
}

void Display::set_display_line(std::string &display_line, std::string end_str,
std::string emoji_str, std::string replace, std::string color, bool emoji)
std::string emoji_str, std::string replace,
std::string color, bool emoji)
{
if (emoji)
display_line = color + emoji_str + end_str;
Expand Down Expand Up @@ -92,31 +94,49 @@ void Display::display_error(ErrorHandling::Error error, bool emoji)
switch (error)
{
case Error::COMMAND_ERROR_NAME:
set_display_line(display_line, "You can't have the same commands in the same folder twice.", "", "", BOLDRED, emoji);
set_display_line(
display_line,
"You can't have the same commands in the same folder twice.", "",
"", BOLDRED, emoji);
break;
case Error::FOLDER_ERROR_NAME:
set_display_line(display_line, "You can't have two folders with the same name in the whole project.","", "", BOLDRED, emoji);
set_display_line(display_line,
"You can't have two folders with the same name in the "
"whole project.",
"", "", BOLDRED, emoji);
break;
case Error::INVALID_INPUT:
set_display_line(display_line, "Your input is invalid","", "", BOLDRED, emoji);
set_display_line(display_line, "Your input is invalid", "", "",
BOLDRED, emoji);
break;
case Error::OUT_OF_RANGE:
set_display_line(display_line, "Your arguments must be in the interval of your folder.","", "", BOLDRED, emoji);
set_display_line(
display_line,
"Your arguments must be in the interval of your folder.", "", "",
BOLDRED, emoji);
break;
case Error::NEED_MORE_ARGUMENTS:
set_display_line(display_line, "Your function needs more arguments to be executed.","", "", BOLDRED, emoji);
set_display_line(display_line,
"Your function needs more arguments to be executed.",
"", "", BOLDRED, emoji);
break;
case Error::TOO_MUCH_ARGUMENTS:
set_display_line(display_line, "Your function needs less arguments to be executed.","", "", BOLDRED, emoji);
set_display_line(display_line,
"Your function needs less arguments to be executed.",
"", "", BOLDRED, emoji);
break;
case Error::BIG_INDEX:
set_display_line(display_line, "Your index is too big.","", "", BOLDRED, emoji);
set_display_line(display_line, "Your index is too big.", "", "",
BOLDRED, emoji);
break;
case Error::NONE:
break;
}
std::cout << RESET << display_line << RESET << std::endl;
std::cout << RESET << YELLOW << " Press "<< RESET << BOLDGREEN << "h" << RESET << YELLOW<<" to see the documentation." << RESET << '\n' << std::endl;
std::cout << RESET << YELLOW << " Press " << RESET << BOLDGREEN << "h"
<< RESET << YELLOW << " to see the documentation." << RESET
<< '\n'
<< std::endl;
}

void Display::display_executor(Executor::executor_result executor,
Expand All @@ -130,37 +150,48 @@ void Display::display_executor(Executor::executor_result executor,
case Executor::ExecutionType::COMMAND:
return execute(executor.second, emoji, clear);
case Executor::ExecutionType::CREATE_COMMAND:
set_display_line(display_line, "Creation of command:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Creation of command:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::CREATE_COMBO:
set_display_line(display_line, "Creation of combo:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Creation of combo:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::CREATE_FOLDER:
set_display_line(display_line, "Creation of the folder:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Creation of the folder:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::DELETE_COMMAND:
set_display_line(display_line, "Deletion of command:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Deletion of command:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::DELETE_FOLDER:
set_display_line(display_line, "Deletion of folder:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Deletion of folder:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::DELETE_COMBO:
set_display_line(display_line, "Deletion of combo:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "Deletion of combo:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::BACK_FOLDER:
set_display_line(display_line, "You have returned to your old file", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "You have returned to your old file",
"✔️ ", "", BOLDGREEN, emoji);
break;
case Executor::ExecutionType::MOVE_FOLDER:
set_display_line(display_line, "You move into the folder:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "You move into the folder:", "✔️ ",
"", BOLDGREEN, emoji);
break;
case Executor::ExecutionType::RESET_FOLDER:
set_display_line(display_line, "You reset the folder:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "You reset the folder:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::MOVE:
set_display_line(display_line, "You move elements:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "You move elements:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::RESET_ALL:
set_display_line(display_line, "You reset all folders:", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "You reset all folders:", "✔️ ", "",
BOLDGREEN, emoji);
break;
case Executor::ExecutionType::DISPLAY_HELP:
display_helper();
Expand All @@ -169,39 +200,47 @@ void Display::display_executor(Executor::executor_result executor,
system("clear");
return;
case Executor::ExecutionType::QUIT:
set_display_line(display_line, "See you soon !", "👋 ", "", BOLDGREEN, emoji);
set_display_line(display_line, "See you soon !", "👋 ", "", BOLDGREEN,
emoji);
break;
case Executor::ExecutionType::COMBO_EXECUTION:
return execute_combo(executor.second, display_line, element_combo, emoji);
return execute_combo(executor.second, display_line, element_combo,
emoji);
case Executor::ExecutionType::CLEAR:
set_display_line(display_line, "CLEAR !", "✔️ ", "", BOLDGREEN, emoji);
set_display_line(display_line, "CLEAR !", "✔️ ", "", BOLDGREEN,
emoji);
break;
}
std::cout << RESET << display_line << RESET << WHITE << ' ' << executor.second
<< RESET << '\n'
std::cout << RESET << display_line << RESET << WHITE << ' '
<< executor.second << RESET << '\n'
<< std::endl;
}

void Display::display(std::map<std::string, Folder> &map, std::string& current_folder, bool emoji)
void Display::display(std::map<std::string, Folder> &map,
std::string &current_folder, bool emoji)
{
std::cout << (emoji ? "📁 : " : "Current folder: ") << BOLDGREEN << current_folder << std::endl << std::endl;
std::cout << (emoji ? "📁 : " : "Current folder: ") << BOLDGREEN
<< current_folder << std::endl
<< std::endl;
std::cout << RESET;
int i = 1;
auto elms = map[current_folder].get_elements();
for (auto elm : elms)
{
if (elm.get_is_folder())
std::cout << BOLD << std::to_string(i) << RESET << (emoji ? "" : " - ") << BOLDBLUE
<< elm.get_name() << (emoji ? " 📁 " : "") << std::endl;
std::cout << BOLD << std::to_string(i) << RESET
<< (emoji ? "" : " - ") << BOLDBLUE << elm.get_name()
<< (emoji ? " 📁 " : "") << std::endl;
else if (!elm.get_is_combo())
std::cout << BOLD << std::to_string(i) << RESET << (emoji ? "" : " - ")
<< elm.get_name() << std::endl;
std::cout << BOLD << std::to_string(i) << RESET
<< (emoji ? "" : " - ") << elm.get_name() << std::endl;
else
{
if (elm.get_name().empty())
{
if (elm.get_combo_elements_().size() > 0)
std::cout << BOLD << std::to_string(i) << RESET << (emoji ? "" : " - ")
std::cout << BOLD << std::to_string(i) << RESET
<< (emoji ? "" : " - ")
<< elm.get_combo_elements_()[0].get_name()
<< std::endl;

Expand All @@ -215,8 +254,9 @@ void Display::display(std::map<std::string, Folder> &map, std::string& current_f
}
else
{
std::cout << BOLD << std::to_string(i) << RESET << (emoji ? "" : " - ")
<< BOLDRED << elm.get_name() << RESET << (emoji ? " 🔸 " : "")
std::cout << BOLD << std::to_string(i) << RESET
<< (emoji ? "" : " - ") << BOLDRED
<< elm.get_name() << RESET << (emoji ? " 🔸 " : "")
<< std::endl;
}
}
Expand Down Expand Up @@ -294,7 +334,8 @@ void Display::display_helper()
std::cout << YELLOW << "\t exemple: -cb ls [?] [cb] cd [?] \n" << RESET;

std::cout << BOLDWHITE << "\n---" << std::endl;
std::cout << BOLDGREEN << "Press " << RESET << BOLDRED << "Enter" << RESET << BOLDGREEN << " to back to Cpad" << std::endl;
std::cout << BOLDGREEN << "Press " << RESET << BOLDRED << "Enter" << RESET
<< BOLDGREEN << " to back to Cpad" << std::endl;
std::cout << RESET;
std::cout << std::endl;
}
23 changes: 15 additions & 8 deletions src/display.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// #include <windows.hh>

#include "element.hh"
#include "folder.hh"
#include "singleton.hh"
#include "error-handling.hh"
#include "executor.hh"
#include "folder.hh"
#include "singleton.hh"

#define RESET "\033[0m"
#define BOLD "\033[1m"
Expand All @@ -27,22 +27,29 @@
class Display : public Singleton<Display>
{
public:
using error_map = std::map<ErrorHandling::Error, std::pair<std::string, std::string>>;
using executor_map = std::map<Executor::ExecutionType, std::pair<std::string, std::string>>;
using error_map =
std::map<ErrorHandling::Error, std::pair<std::string, std::string>>;
using executor_map =
std::map<Executor::ExecutionType, std::pair<std::string, std::string>>;
using Error = ErrorHandling::Error;
using Exec = Executor::ExecutionType;

void display_error(ErrorHandling::Error error, bool emoji);
void display_executor(Executor::executor_result executor,
Element &element_combo, bool emoji, bool clear = true);
void display(std::map<std::string, Folder> &map, std::string& current_folder, bool emoji);
Element &element_combo, bool emoji,
bool clear = true);
void display(std::map<std::string, Folder> &map,
std::string &current_folder, bool emoji);
void display_helper();
void set_display_line(std::string& display_line, std::string end_str, std::string emoji_str, std::string replace, std::string color,bool emoji);
void set_display_line(std::string &display_line, std::string end_str,
std::string emoji_str, std::string replace,
std::string color, bool emoji);

private:
bool is_template(std::string command);
void remplace_templates(std::string &command, bool clear);
bool cd_exec(std::string command);
void execute(std::string& command, bool emoji, bool clear);
void execute(std::string &command, bool emoji, bool clear);
void execute_combo(std::string &command, std::string display_line,
Element &combo_elem, bool emoji);
};
Loading

0 comments on commit 498707d

Please sign in to comment.