Skip to content

Commit

Permalink
The set_color() function has been renamed to set_static_color().
Browse files Browse the repository at this point in the history
Now, when entering a command, not `PLUSTERM/main` is displayed on the left, but just PT.

There is a new function set_color(), it does not work yet (in development).

The new "web" command (opens the site).

The "pt" command has been deleted (temporarily).

The version in the code has been replaced with a new one (0.20.1).
  • Loading branch information
yarb00 committed Jan 25, 2024
1 parent f93df84 commit dd816e1
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 65 deletions.
144 changes: 82 additions & 62 deletions iarb_plusterm/Plusterm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Plusterm::plusterm_main()
setlocale(LC_ALL, "ru-RU");
system("chcp 1251 > nul 2>&1");

set_color("output_default");
this->set_static_color("output_default");

system("title PlusTerm");

Expand All @@ -29,13 +29,13 @@ void Plusterm::plusterm_main()

for (int i{ 0 }; true; i++)
{
std::string user_input{}, user_input_command{}, user_input_text{}, plusterm_workspace{ "main" };
std::string user_input{}, user_input_command{}, user_input_text{};

std::cout << std::endl;

this->set_color("input_default");
this->set_static_color("input_default");

std::cout << "`PLUSTERM/" << plusterm_workspace << "` |>>> ";
std::cout << "PT |>>> ";
std::getline(std::cin, user_input);

//
Expand Down Expand Up @@ -67,118 +67,116 @@ void Plusterm::plusterm_main()
system("exit");
}

void Plusterm::run(std::string _user_input_command, std::string _user_input_text)
void Plusterm::run(std::string _command, std::string _text)
{
const std::string *command_address{ &_user_input_command }, *text_address{ &_user_input_text }, command{ *command_address }, text{ *text_address };
this->set_static_color("output_default");

this->set_color("output_default");

if (command == "" || command == "_plusterm?empty_")
if (_command == "" || _command == "_plusterm?empty_")
{
//nothing
}
else if (command == "_plusterm?undefined_")
else if (_command == "_plusterm?undefined_")
{
this->info("error", command, command);
this->info("error", _command, _command);
}
else if (command == "exit" || command == "quit")
else if (_command == "exit" || _command == "quit")
{
system("cls");
system("exit");
is_exit = true;
}
else if (command == "help" || command == "?")
else if (_command == "help" || _command == "?")
{
if (text != "")
if (_text != "")
{
this->info("warning", "Êîìàíäà help íå ïðèíèìàåò ïàðàìåòðîâ", command);
this->info("warning", "Êîìàíäà help íå ïðèíèìàåò ïàðàìåòðîâ", _command);
}
std::cout << "Ñïèñîê êîìàíä:" << std::endl << std::endl;
std::cout << "êîìàíäà [îïöèè] (ïàðàìåòðû) ||| Îïèñàíèå" << std::endl << "Äîñòóïíûå îïöèè: äîñòóïíàÿ îïöèÿ êîììàíäû ; åù¸ îäíà äîñòóïíàÿ îïöèÿ êîììàíäû" << std::endl << "Ïðèìåð: ïðèìåð êîììàíäû ; äðóãîé ïðèìåð êîììàíäû" << std::endl << std::endl;
this->help();
}
else if (command == "clear" || command == "cls")
else if (_command == "clear" || _command == "cls")
{
system("cls");
this->set_color("output_default");
this->set_static_color("output_default");
this->print_title();
}
else if (command == "print" || command == "say")
else if (_command == "print" || _command == "say")
{
if (text != "")
if (_text != "")
{
std::cout << text << std::endl;
std::cout << _text << std::endl;
}
else
{
this->info("error", "Âû íå ââåëè íå êàêîãî òåêñòà äëÿ âûâîäà", command);
this->info("error", "Âû íå ââåëè íå êàêîãî òåêñòà äëÿ âûâîäà", _command);
}
}
else if (command == "get_date" || command == "date")
else if (_command == "get_date" || _command == "date")
{
if (text != "")
if (_text != "")
{
this->info("warning", "Êîìàíäà get_date íå ïðèíèìàåò ïàðàìåòðîâ", command);
this->info("warning", "Êîìàíäà get_date íå ïðèíèìàåò ïàðàìåòðîâ", _command);
}
system("echo %date%");
}
else if (command == "get_time" || command == "time")
else if (_command == "get_time" || _command == "time")
{
if (text != "")
if (_text != "")
{
this->info("warning", "Êîìàíäà get_time íå ïðèíèìàåò ïàðàìåòðîâ", command);
this->info("warning", "Êîìàíäà get_time íå ïðèíèìàåò ïàðàìåòðîâ", _command);
}
system("echo %time%");
}
else if (command == "square_root" || command == "sqrt")
else if (_command == "square_root" || _command == "sqrt")
{
/*
char pStr[]{ 0 };
for (int i{ 0 }; i < command.length(); i++)
for (int i{ 0 }; i < _command.length(); i++)
{
pStr[i] = command[i];
pStr[i] = _command[i];
}
for (int i = 0; i < strlen(pStr); i++)
{
if (!isdigit(pStr[i]))
{
this->info("error", "Òî, ÷òî âû ââåëè - íå ÷èñëî", command);
this->info("error", "Òî, ÷òî âû ââåëè - íå ÷èñëî", _command);
}
else if (i == command.length() - 1 && isdigit(pStr[i]))
else if (i == _command.length() - 1 && isdigit(pStr[i]))
{
std::cout << "Êâàäðàòíûé êîðåíü èç " << text << ": " << sqrt(std::stoi(text)) << std::endl;
std::cout << "Êâàäðàòíûé êîðåíü èç " << _text << ": " << sqrt(std::stoi(_text)) << std::endl;
}
}
*/

if (text != "")
if (_text != "")
{
std::cout << "Êâàäðàòíûé êîðåíü èç " << text << ": " << sqrt(std::stoi(text)) << std::endl;
std::cout << "Êâàäðàòíûé êîðåíü èç " << _text << ": " << sqrt(std::stoi(_text)) << std::endl;
}
else
{
this->info("error", "Âû íå ââåëè ÷èñëî", command);
this->info("error", "Âû íå ââåëè ÷èñëî", _command);
}
}
else if (command == "version" || command == "ver")
else if (_command == "version" || _command == "ver")
{
if (text != "")
if (_text != "")
{
this->info("warning", "Êîìàíäà plusterm_version íå ïðèíèìàåò ïàðàìåòðîâ", command);
this->info("warning", "Êîìàíäà plusterm_version íå ïðèíèìàåò ïàðàìåòðîâ", _command);
}
print_title("version");
}
else if (command == "cmd")
else if (_command == "cmd")
{
if (text != "")
if (_text != "")
{
this->info("info", "Îòïðàâëÿåì êîììàíäó â CMD...", command);
this->info("info", "Îòïðàâëÿåì êîììàíäó â CMD...", _command);
std::cout << std::endl;

system(text.c_str());
system(_text.c_str());

std::cout << std::endl;
this->info("info", "Êîìàíäà CMD âûïîëíåíà!", command);
this->info("info", "Êîìàíäà CMD âûïîëíåíà!", _command);
}
else
{
Expand All @@ -188,24 +186,36 @@ void Plusterm::run(std::string _user_input_command, std::string _user_input_text
system("cmd");
}
}
else if (command == "plusterm" || command == "pt")
/*else if (_command == "plusterm" || _command == "pt")
{
if (text.find("/*") != std::string::npos)
if (_text.find("/*") != std::string::npos)
{
system("iarb_plusterm.exe");
}
else
{
this->info("warning", "Ïîõîæå, ÷òî ýêçýìïëÿð PlusTerm óæå çàïóùåí. Åñëè âû âñ¸ ðàâíî õîòèòå çàïóñòèòü åù¸ îäèí ýêçýìïëÿð PlusTerm ïîâåðõ ýòîãî, âûïîëíèòå êîììàíäó ñ ïàðàìåòðîì /*", command);
this->info("warning", "Ïîõîæå, ÷òî ýêçýìïëÿð PlusTerm óæå çàïóùåí. Åñëè âû âñ¸ ðàâíî õîòèòå çàïóñòèòü åù¸ îäèí ýêçýìïëÿð PlusTerm ïîâåðõ ýòîãî, âûïîëíèòå êîììàíäó ñ ïàðàìåòðîì /*", _command);
}
}
else if (command == "about")
}*/
else if (_command == "about")
{
set_color("title_name");
this->set_static_color("title_name");
std::cout << "PlusTerm";
set_color("output_default");
this->set_static_color("output_default");
std::cout << std::endl << "Àâòîð PlusTerm`a - yarb00." << std::endl << "Discord: @yarb00" << std::endl << "Telegram: @yarb000" << std::endl;
}
else if (_command == "web")
{
if (_text != "")
{
std::string com_{ "start https://\"" + _text + "\"" };
system(com_.c_str());
}
else
{
system("start https://\"github.com/yarb00\"");
}
}
else
{
this->info("error", "Íåèçâåñòíàÿ êîìàíäà");
Expand All @@ -222,19 +232,20 @@ void Plusterm::help()
std::cout << "date ||| Âûâåñòè òåêóùóþ äàòó íà ýêðàí" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: date" << std::endl << std::endl;
std::cout << "time ||| Âûâåñòè òåêóùåå âðåìÿ íà ýêðàí" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: time" << std::endl << std::endl;
std::cout << "sqrt (÷èñëî) ||| Âûâåñòè êâàäðàòíûé êîðåíü èç ÷èñëà íà ýêðàí" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: sqrt 9" << std::endl << std::endl;
std::cout << "pt_ver ||| Âûâåñòè âåðñèþ PlusTerm íà ýêðàí" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: pt_ver" << std::endl << std::endl;
std::cout << "ver ||| Âûâåñòè âåðñèþ PlusTerm íà ýêðàí" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: pt_ver" << std::endl << std::endl;
std::cout << "cmd (êîìàíäà CMD) ||| Âûïîëíèòü êîìàíäó CMD èç ïàðàìåòðà, èëè, áåç ïàðàìåòðîâ çàïóñòèòü ñåàíñ CMD (êëàññè÷åñêîé êîìàíäíîé ñòðîêè)" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: cmd ; cmd echo Hello, world!" << std::endl << std::endl;
std::cout << "pt [îïöèè] ||| Çàïóñòèòü ýêçýìïëÿð PlusTerm" << std::endl << "Äîñòóïíûå îïöèè: /* - ïîäòâåðäèòü çàïóñê" << std::endl << "Ïðèìåð: pt ; pt /*" << std::endl << std::endl;
//std::cout << "pt [îïöèè] ||| Çàïóñòèòü ýêçýìïëÿð PlusTerm" << std::endl << "Äîñòóïíûå îïöèè: /* - ïîäòâåðäèòü çàïóñê" << std::endl << "Ïðèìåð: pt ; pt /*" << std::endl << std::endl;
std::cout << "about ||| Î Plusterm è åãî àâòîðå" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: about" << std::endl << std::endl;
std::cout << "web (àäðåñ ñàéòà áåç ïðîòîêîëà https) ||| Îòêðûâàåò ñàéò â áðàóçåðå ïî óìîë÷àíèþ" << std::endl << "Äîñòóïíûå îïöèè: íåò" << std::endl << "Ïðèìåð: web google.com" << std::endl << std::endl;
}

void Plusterm::print_title(std::string _mode)
{
if (_mode == "title")
{
set_color("title_name");
set_static_color("title_name");
std::cout << "PlusTerm";
set_color("output_default");
set_static_color("output_default");
std::cout << std::endl << "îò yarb00\t(ïîäðîáíåå: \"about\")" << std::endl << std::endl << "ÂÅÐÑÈß { |" << this->plusterm_version << "| }" << std::endl << std::endl << "-----" << std::endl;
}
else if (_mode == "version")
Expand All @@ -247,24 +258,34 @@ void Plusterm::info(std::string _info_level, std::string _info_text, std::string
{
if (_info_level == "error")
{
this->set_color("output_error");
this->set_static_color("output_error");
std::cout << "ÎØÈÁÊÀ [" << _input_command << " / " << _info_text << "] !" << std::endl;
}
else if (_info_level == "warning")
{
this->set_color("output_warning");
this->set_static_color("output_warning");
std::cout << "ÏÐÅÄÓÏÐÅÆÄÅÍÈÅ [" << _input_command << " / " << _info_text << "] !" << std::endl;
}
else if (_info_level == "info")
{
this->set_color("light_blue");
this->set_static_color("light_blue");
std::cout << "ÑÎÎÁÙÅÍÈÅ [" << _input_command << " / " << _info_text << "] !" << std::endl;
}

set_color();
set_static_color();
}

void Plusterm::set_color(std::string _color_mode)
//in developing, doesn't work now. use set_static_color() instead
template<int txt = 7, int bg = 0>
std::ostream& set_color(std::ostream& _text)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | txt));
return _text;
}
//

void Plusterm::set_static_color(std::string _color_mode)
{
int _text_color{}, _background_color{ 1 };

Expand Down Expand Up @@ -295,7 +316,6 @@ void Plusterm::set_color(std::string _color_mode)
}

//
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD)((_background_color << 4) | _text_color));
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (WORD)((_background_color << 4) | _text_color));
//
}
11 changes: 8 additions & 3 deletions iarb_plusterm/Plusterm.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once
#include <string>
#include <Windows.h>

class Plusterm
{
public:
void start();
private:
const std::string plusterm_version{ "0.16.2" };
const std::string plusterm_version{ "0.20.1" };

#ifdef DEBUG
const std::string plusterm_version_channel{ "DEV_DEBUG" };
const std::string plusterm_version_channel{ "DEBUG" };
#else
const std::string plusterm_version_channel{ "RTL_CANARY" };
#endif
Expand All @@ -26,5 +27,9 @@ class Plusterm

void info(std::string _info_level, std::string _info_text, std::string _input_command = "_plusterm?undefined_");

void set_color(std::string _color_mode = "output_default");
//in developing, doesn't work now. use set_static_color() instead
template<int txt = 7, int bg = 0>
std::ostream& set_color(std::ostream& text);

void set_static_color(std::string _color_mode = "output_default");
};

0 comments on commit dd816e1

Please sign in to comment.