Skip to content

Commit 4978f19

Browse files
committed
writeInLog
1 parent bf85b6f commit 4978f19

File tree

5 files changed

+132
-58
lines changed

5 files changed

+132
-58
lines changed

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PulsarVenv.exe

-4 KB
Binary file not shown.
Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,91 @@
1-
#include "linuxPulsar.h"
1+
// Библиотеки/модули необходимое для работы
2+
#include "linuxPulsar.h"
23
#include <iostream>
34
#include <cstdlib>
45
#include <string>
6+
#include <chrono>
7+
#include <thread>
58

9+
// Макросы цветов
10+
#define CLEAR "\x1b[0m"
11+
#define RED "\x1b[31m"
12+
#define GREEN "\x1b[32m"
13+
#define BOLD "\x1b[1m"
14+
15+
// Пространство имен
616
using namespace std;
717

18+
// Главный класс информации о пульсаре
19+
class CurrentPulsarInfo {
20+
public:
21+
static string title;
22+
static string platform_version;
23+
static string account;
24+
static string password;
25+
static int start_time;
26+
static string bildingid;
827

9-
int commandAnalyze(string line){
10-
if (line.empty()) {
11-
return 0;
12-
}
13-
else if (line.starts_with("//")) {
14-
return 0;
15-
}
16-
else if (line == "exit") {
17-
return 0101;
28+
static string getCurrentDateTime() {
29+
auto now = chrono::system_clock::now();
30+
time_t now_time = chrono::system_clock::to_time_t(now);
31+
tm local_time;
32+
localtime_s(&local_time, &now_time);
33+
34+
stringstream datetime_stream;
35+
datetime_stream << put_time(&local_time, "%Y-%m-%d %H:%M:%S");
36+
return datetime_stream.str();
1837
}
19-
else {
20-
cout << "Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
38+
39+
static void ShowInfo() {
40+
unsigned int point_time = clock();
41+
cout << "----------------------------------------------" << endl;
42+
cout << "Версия: " << title << endl;
43+
cout << "Платформа: " << platform_version << endl;
44+
cout << "Время работы: " << (point_time - start_time) / 1000 << " сек" << endl;
45+
cout << "Текущее время: " << getCurrentDateTime() << endl;
46+
cout << "Аккаунт: " << account << endl;
47+
cout << "Пароль: " << password << endl;
48+
cout << "ID сборки: " << bildingid << endl;
49+
cout << "----------------------------------------------" << endl;
2150
}
22-
}
51+
};
52+
// Реализация статический переменных class CurrentPulsarInfo
53+
string CurrentPulsarInfo::title = "PulsarVenv 0.3.0";
54+
string CurrentPulsarInfo::platform_version = "Windows";
55+
string CurrentPulsarInfo::account = "";
56+
int CurrentPulsarInfo::start_time = 0;
57+
string CurrentPulsarInfo::bildingid = "";
58+
string CurrentPulsarInfo::password = "";
59+
2360

61+
// Cкелеты/прототипы функций
62+
int commandAnalyze(string line);
63+
64+
// Основная функция
2465
int pulsarStart(){
2566
string com;
2667
while (true) {
2768
getline(cin, com);
2869
com.erase(0, com.find_first_not_of(' '));
2970
com.erase(com.find_last_not_of(' ') + 1);
3071
int code = commandAnalyze(com);
31-
if(code==0101){}
72+
if (code == 0101) { return 0101; }
3273
}
3374
return 0;
3475
}
76+
77+
//Реализация функций
78+
int commandAnalyze(string line) {
79+
if (line.empty()) {
80+
return 0;
81+
}
82+
else if (line.starts_with("//")) {
83+
return 0;
84+
}
85+
else if (line == "exit") {
86+
return 0101;
87+
}
88+
else {
89+
cout << RED <<"Ошибка: Команда не распознана. Введите 'help' для справки." << CLEAR<<endl;
90+
}
91+
}

public/source/WindowsPulsar/winPulsar.cpp

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Неообходимые библиотеки/модули
2-
#include "winPulsar.h"
2+
#include "C:\Users\user\Desktop\PulsarVenv Main\public\source\WindowsPulsar\winPulsar.h"
33
#include <atomic>
44
#include <chrono>
55
#include <cstdlib>
@@ -15,6 +15,12 @@
1515
#include <cctype>
1616
#include "C:\Users\user\source\repos\PulsarVenv\PulsarVenv\pulsFileSystem.h"
1717

18+
// Макросы цветов
19+
#define CLEAR "\x1b[0m"
20+
#define RED "\x1b[31m"
21+
#define GREEN "\x1b[32m"
22+
#define BOLD "\x1b[1m"
23+
1824
//Пространство имен std
1925
using namespace std;
2026

@@ -24,7 +30,6 @@ string current_path;
2430
string build_ID;
2531
string style = "";
2632
bool isLog = true;
27-
bool isError = true;
2833
atomic<bool> timeThreadRunning(true);
2934
mutex consoleMutex;
3035

@@ -82,7 +87,7 @@ class CurrentPulsarInfo {
8287
};
8388

8489
// Реализация статический переменных class CurrentPulsarInfo
85-
string CurrentPulsarInfo::title = "PulsarVenv 0.2.5";
90+
string CurrentPulsarInfo::title = "PulsarVenv 0.3.0";
8691
string CurrentPulsarInfo::platform_version = "Windows";
8792
string CurrentPulsarInfo::account = "";
8893
int CurrentPulsarInfo::start_time = 0;
@@ -212,35 +217,7 @@ void puls_sysconfig(string line) {
212217
}
213218

214219
void show_help() {
215-
cout << "PulsarVenv 0.0.1-alpha - Справочник по командам" << endl << endl;
216-
217-
cout << "Основные команды:" << endl;
218-
cout << "=================" << endl;
219-
cout << "help - Показать эту справку" << endl;
220-
cout << "exit - Выйти из системы" << endl;
221-
cout << "clear - Очистить экран консоли" << endl;
222-
cout << "pinfo - Показать информацию о Pulsar (версия, время работы и т.д.)" << endl << endl;
223-
cout << "chemdb - Химическая база данных" << endl << endl;
224-
225-
cout << "Команды работы с системой:" << endl;
226-
cout << "=========================" << endl;
227-
cout << "sysconfig - Показать конфигурацию системы" << endl;
228-
cout << "sumulator_pulsar - Запустить эмуляцию пульсара (требует подтверждения)" << endl << endl;
229-
230-
cout << "Команды для вычислений:" << endl;
231-
cout << "=======================" << endl;
232-
cout << "calc <выражение> - Выполнить математическое вычисление (например: calc 2+2*3)" << endl << endl;
233-
234-
cout << "Управление аккаунтами:" << endl;
235-
cout << "=====================" << endl;
236-
cout << "account add - Создать новый аккаунт" << endl;
237-
cout << "account remove - Удалить существующий аккаунт" << endl;
238-
cout << "account swap - Сменить текущий аккаунт" << endl << endl;
239-
240-
cout << "Запуск программ:" << endl;
241-
cout << "===============" << endl;
242-
cout << "<имя_программы> - Запустить программу из папки modules" << endl;
243-
cout << " (можно указывать с расширением .exe или без)" << endl;
220+
cout << "Справочник по командам - https://github.com/PulsarPrograms/PulsarVenv/wiki" << endl << endl;
244221
}
245222

246223
int PulsarConsoleClear() {
@@ -538,14 +515,6 @@ int comAnalyze(string line) {
538515
else if (line.substr(0, 12) == "change style") {
539516
changeStyle();
540517
}
541-
else if (line.starts_with("-error")) {
542-
cout << "Сообщения об ошибках выключены" << endl;
543-
isError = false;
544-
}
545-
else if (line.starts_with("+error")) {
546-
cout << "Сообщения об ошибках включены" << endl;
547-
isError = true;
548-
}
549518
else if (line == "chemdb") {
550519
string pathToChemBd = "cd " + current_path + "\\SystemPuls\\systemmodules && chembd.exe";
551520
system(pathToChemBd.c_str());
@@ -591,6 +560,51 @@ int comAnalyze(string line) {
591560
}
592561
}
593562
}
563+
else if (line.starts_with("write")) {
564+
line.erase(0, 5);
565+
line.erase(0, line.find_first_not_of(' '));
566+
567+
if (line.empty() || line[0] != '"') {
568+
cout << RED << BOLD << "Ошибка: ожидается '\"' в начале строки" << CLEAR << endl;
569+
return 1;
570+
}
571+
572+
string log_message;
573+
bool quote_closed = false;
574+
int i = 1;
575+
576+
for (; i < line.length(); i++) {
577+
if (line[i] == '"') {
578+
quote_closed = true;
579+
i++;
580+
break;
581+
}
582+
log_message += line[i];
583+
}
584+
585+
if (!quote_closed) {
586+
cout << RED << BOLD << "Ошибка: незакрытый строковый литерал" << CLEAR << endl;
587+
return 1;
588+
}
589+
590+
line.erase(0, i);
591+
line.erase(0, line.find_first_not_of(' '));
592+
593+
bool add_time = false;
594+
if (line.starts_with("+time")) {
595+
add_time = true;
596+
line.erase(0, 5);
597+
line.erase(0, line.find_first_not_of(' '));
598+
}
599+
600+
for (char c : line) {
601+
if (!isspace(c)) {
602+
cout << RED << BOLD << "Ошибка: неожиданные символы после команды: '" << c << "'" << CLEAR << endl;
603+
return 1;
604+
}
605+
}
606+
writeInLog(log_message, add_time, false);
607+
}
594608

595609
else {
596610
cout << "Неопознанная log-команда" << endl;
@@ -615,7 +629,7 @@ int comAnalyze(string line) {
615629
system(cdmodule.c_str());
616630
}
617631
else {
618-
if (isError) cout << "Ошибка: Команда не распознана. Введите 'help' для справки." << endl;
632+
cout << RED << "Ошибка: Команда не распознана. Введите 'help' для справки." << CLEAR << endl;
619633
}
620634
}
621635
}
@@ -651,7 +665,7 @@ int pulsStarterScript() {
651665
fstream scrsFile;
652666
scrsFile.open(current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.txt", fstream::in | fstream::out | ios::app);
653667
if (!scrsFile.is_open()) {
654-
cout << "Ошибка работы с файлом - " << current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.txt" << endl;
668+
cout << RED <<"Ошибка работы с файлом - " << current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.txt" << CLEAR << endl;
655669
return 1;
656670
}
657671
while (getline(scrsFile, comInFile)) {
@@ -669,7 +683,7 @@ int pulsStarterScript() {
669683
fstream scrsFile;
670684
scrsFile.open(current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.puls", fstream::in | fstream::out | ios::app);
671685
if (!scrsFile.is_open()) {
672-
cout << "Ошибка работы с файлом - " << current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.puls" << endl;
686+
cout << RED <<"Ошибка работы с файлом - " << current_path + "\\accounts\\" + CurrentPulsarInfo::account + "\\startscript.puls" << CLEAR << endl;
673687
return 1;
674688
}
675689
while (getline(scrsFile, comInFile)) {

public/source/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include <string>
33
#include <dos.h>
4-
#include "winPulsar.h"
4+
#include "C:\Users\user\Desktop\PulsarVenv Main\public\source\WindowsPulsar\winPulsar.h"
55
#include <chrono>
66
#include <thread>
77
#include <fstream>

0 commit comments

Comments
 (0)