添加windows 支持,不完整。
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,3 +6,5 @@
|
|||||||
**/.vscode/
|
**/.vscode/
|
||||||
*.o
|
*.o
|
||||||
*.dat
|
*.dat
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
11
大作业/Date.cpp
11
大作业/Date.cpp
@@ -39,7 +39,16 @@ std::string Date::toString() const {
|
|||||||
return "[Any]";
|
return "[Any]";
|
||||||
}
|
}
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
strftime(buffer, 20, "%F", localtime(&this->time));
|
tm curTime;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
curDate = *(localtime(&this->time));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
localtime_s(&curTime, &this->time);
|
||||||
|
#endif
|
||||||
|
strftime(buffer, 20, "%F", &curTime);
|
||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,11 +260,20 @@ void ListDisplay::promptForRecordID() {
|
|||||||
|
|
||||||
void ListDisplay::promptForFromDate() {
|
void ListDisplay::promptForFromDate() {
|
||||||
time_t originTime = this->fromDate.getTime();
|
time_t originTime = this->fromDate.getTime();
|
||||||
tm *curDate = localtime(&originTime);
|
tm curDate;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
curDate = *(localtime(&originTime));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
localtime_s(&curDate, &originTime);
|
||||||
|
#endif
|
||||||
|
|
||||||
int tempInput;
|
int tempInput;
|
||||||
if (!this->fromDate.isAny()) {
|
if (!this->fromDate.isAny()) {
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
strftime(buffer, 20, "%F", curDate);
|
strftime(buffer, 20, "%F", &curDate);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::green)
|
std::cout << setoutputcolor(ConsoleColorTool::green)
|
||||||
<< "Current date: " << buffer
|
<< "Current date: " << buffer
|
||||||
<< ". Enter 0 to retain original value." << resetOutputColor
|
<< ". Enter 0 to retain original value." << resetOutputColor
|
||||||
@@ -275,22 +284,22 @@ void ListDisplay::promptForFromDate() {
|
|||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_year =
|
curDate.tm_year =
|
||||||
(tempInput == 0 ? curDate->tm_year : tempInput - 1900);
|
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Month: " << resetOutputColor << std::flush;
|
<< "Month: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mon = (tempInput == 0 ? curDate->tm_mon : tempInput - 1);
|
curDate.tm_mon = (tempInput == 0 ? curDate.tm_mon : tempInput - 1);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Day: " << resetOutputColor << std::flush;
|
<< "Day: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mday = (tempInput == 0 ? curDate->tm_mday : tempInput);
|
curDate.tm_mday = (tempInput == 0 ? curDate.tm_mday : tempInput);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
@@ -299,33 +308,43 @@ void ListDisplay::promptForFromDate() {
|
|||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_year = tempInput - 1900;
|
curDate.tm_year = tempInput - 1900;
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Month: " << resetOutputColor << std::flush;
|
<< "Month: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mon = tempInput - 1;
|
curDate.tm_mon = tempInput - 1;
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Day: " << resetOutputColor << std::flush;
|
<< "Day: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mday = tempInput;
|
curDate.tm_mday = tempInput;
|
||||||
}
|
}
|
||||||
this->fromDate = mktime(curDate);
|
this->fromDate = mktime(&curDate);
|
||||||
this->reapplyFilter();
|
this->reapplyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListDisplay::promptForToDate() {
|
void ListDisplay::promptForToDate() {
|
||||||
time_t originTime = this->fromDate.getTime();
|
time_t originTime = this->fromDate.getTime();
|
||||||
tm *curDate = localtime(&originTime);
|
|
||||||
|
tm curDate;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
curDate = *(localtime(&originTime));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
localtime_s(&curDate, &originTime);
|
||||||
|
#endif
|
||||||
|
|
||||||
int tempInput;
|
int tempInput;
|
||||||
if (!this->toDate.isAny()) {
|
if (!this->toDate.isAny()) {
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
strftime(buffer, 20, "%F", curDate);
|
strftime(buffer, 20, "%F", &curDate);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::green)
|
std::cout << setoutputcolor(ConsoleColorTool::green)
|
||||||
<< "Current date: " << buffer
|
<< "Current date: " << buffer
|
||||||
<< ". Enter 0 to retain original value." << resetOutputColor
|
<< ". Enter 0 to retain original value." << resetOutputColor
|
||||||
@@ -336,22 +355,22 @@ void ListDisplay::promptForToDate() {
|
|||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_year =
|
curDate.tm_year =
|
||||||
(tempInput == 0 ? curDate->tm_year : tempInput - 1900);
|
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Month: " << resetOutputColor << std::flush;
|
<< "Month: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mon = (tempInput == 0 ? curDate->tm_mon : tempInput - 1);
|
curDate.tm_mon = (tempInput == 0 ? curDate.tm_mon : tempInput - 1);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Day: " << resetOutputColor << std::flush;
|
<< "Day: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mday = (tempInput == 0 ? curDate->tm_mday : tempInput);
|
curDate.tm_mday = (tempInput == 0 ? curDate.tm_mday : tempInput);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
@@ -360,27 +379,27 @@ void ListDisplay::promptForToDate() {
|
|||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_year = tempInput - 1900;
|
curDate.tm_year = tempInput - 1900;
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Month: " << resetOutputColor << std::flush;
|
<< "Month: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mon = tempInput - 1;
|
curDate.tm_mon = tempInput - 1;
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Day: " << resetOutputColor << std::flush;
|
<< "Day: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
curDate->tm_mday = tempInput;
|
curDate.tm_mday = tempInput;
|
||||||
}
|
}
|
||||||
curDate->tm_hour = 0;
|
curDate.tm_hour = 0;
|
||||||
curDate->tm_min = 0;
|
curDate.tm_min = 0;
|
||||||
curDate->tm_sec = 0;
|
curDate.tm_sec = 0;
|
||||||
curDate->tm_isdst = 0;
|
curDate.tm_isdst = 0;
|
||||||
this->toDate = mktime(curDate);
|
this->toDate = mktime(&curDate);
|
||||||
this->reapplyFilter();
|
this->reapplyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Exceptions.hpp"
|
#include "Exceptions.hpp"
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
template <class E> class List {
|
template <class E> class List {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
generalArguments = -std=c++17 -g
|
generalArguments = -std=c++20 -g
|
||||||
|
|
||||||
main.out: main.o Tools.o Exceptions.o Record.o Date.o Student.o StudentInfoManager.o ListDisplay.o
|
main.out: main.o Tools.o Exceptions.o Record.o Date.o Student.o StudentInfoManager.o ListDisplay.o
|
||||||
clang++ $(generalArguments) $^ -o main.out
|
clang++ $(generalArguments) $^ -o main.out
|
||||||
|
|
||||||
|
main.exe: main.o Tools.o Exceptions.o Record.o Date.o Student.o StudentInfoManager.o ListDisplay.o
|
||||||
|
clang++ $(generalArguments) $^ -o main.exe
|
||||||
|
|
||||||
main.o: main.cpp ListE.hpp Node.hpp
|
main.o: main.cpp ListE.hpp Node.hpp
|
||||||
clang++ $(generalArguments) -c main.cpp -o main.o
|
clang++ $(generalArguments) -c main.cpp -o main.o
|
||||||
|
|
||||||
|
|||||||
@@ -45,12 +45,23 @@ const Student &BaseRecord::getStudent() const {
|
|||||||
|
|
||||||
void BaseRecord::promptForNewDate(bool showOriginal) {
|
void BaseRecord::promptForNewDate(bool showOriginal) {
|
||||||
time_t originTime = this->date.getTime();
|
time_t originTime = this->date.getTime();
|
||||||
tm *curDate = localtime(&originTime);
|
// tm *curDate = localtime(&originTime);
|
||||||
|
|
||||||
|
tm curDate;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
curDate = *(localtime(&originTime));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
localtime_s(&curDate, &originTime);
|
||||||
|
#endif
|
||||||
|
|
||||||
tm newDate;
|
tm newDate;
|
||||||
int tempInput;
|
int tempInput;
|
||||||
if (showOriginal) {
|
if (showOriginal) {
|
||||||
char buffer[20];
|
char buffer[20];
|
||||||
strftime(buffer, 20, "%F", curDate);
|
strftime(buffer, 20, "%F", &curDate);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::green)
|
std::cout << setoutputcolor(ConsoleColorTool::green)
|
||||||
<< "Current date: " << buffer
|
<< "Current date: " << buffer
|
||||||
<< ". Enter 0 to retain original value." << resetOutputColor
|
<< ". Enter 0 to retain original value." << resetOutputColor
|
||||||
@@ -62,21 +73,21 @@ void BaseRecord::promptForNewDate(bool showOriginal) {
|
|||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
newDate.tm_year =
|
newDate.tm_year =
|
||||||
(tempInput == 0 ? curDate->tm_year : tempInput - 1900);
|
(tempInput == 0 ? curDate.tm_year : tempInput - 1900);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Month: " << resetOutputColor << std::flush;
|
<< "Month: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
newDate.tm_mon = (tempInput == 0 ? curDate->tm_mon : tempInput - 1);
|
newDate.tm_mon = (tempInput == 0 ? curDate.tm_mon : tempInput - 1);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Day: " << resetOutputColor << std::flush;
|
<< "Day: " << resetOutputColor << std::flush;
|
||||||
// std::cin >> tempInput;
|
// std::cin >> tempInput;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
tempInput = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
newDate.tm_mday = (tempInput == 0 ? curDate->tm_mday : tempInput);
|
newDate.tm_mday = (tempInput == 0 ? curDate.tm_mday : tempInput);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
@@ -147,7 +158,7 @@ void BaseRecord::promptForNewStudentInfo(bool showOriginal) {
|
|||||||
// std::cin >> tempStuID;
|
// std::cin >> tempStuID;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempStuID = safeInputNum<int>("Please input a positive integer.\n",
|
tempStuID = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
this->student.setNumber(tempStuID == 0 ? this->student.getNumber()
|
this->student.setNumber(tempStuID == 0 ? this->student.getNumber()
|
||||||
: tempStuID);
|
: tempStuID);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
@@ -162,7 +173,7 @@ void BaseRecord::promptForNewStudentInfo(bool showOriginal) {
|
|||||||
// std::cin >> tempStuID;
|
// std::cin >> tempStuID;
|
||||||
// std::cin.ignore();
|
// std::cin.ignore();
|
||||||
tempStuID = safeInputNum<int>("Please input a positive integer.\n",
|
tempStuID = safeInputNum<int>("Please input a positive integer.\n",
|
||||||
[](const int &num) { return num > 0; });
|
[](const int &num) { return num > 0; });
|
||||||
this->student.setNumber(tempStuID);
|
this->student.setNumber(tempStuID);
|
||||||
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
||||||
<< "Student Name: " << resetOutputColor << std::flush;
|
<< "Student Name: " << resetOutputColor << std::flush;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const struct {
|
|||||||
int studentName = 15;
|
int studentName = 15;
|
||||||
int type = 10;
|
int type = 10;
|
||||||
} recordDisplayRowSize;
|
} recordDisplayRowSize;
|
||||||
|
|
||||||
namespace StuRecord {
|
namespace StuRecord {
|
||||||
enum RecordType { Late, Absent, PersonalLeave, Any };
|
enum RecordType { Late, Absent, PersonalLeave, Any };
|
||||||
};
|
};
|
||||||
@@ -30,9 +31,9 @@ enum RecordType { Late, Absent, PersonalLeave, Any };
|
|||||||
struct SaveRecord {
|
struct SaveRecord {
|
||||||
int recordID;
|
int recordID;
|
||||||
time_t date;
|
time_t date;
|
||||||
unsigned long courseNameLength;
|
unsigned long long courseNameLength;
|
||||||
int studentNumber;
|
int studentNumber;
|
||||||
unsigned long studentNameLength;
|
unsigned long long studentNameLength;
|
||||||
StuRecord::RecordType recordType;
|
StuRecord::RecordType recordType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ bool StudentInfoManager::promptForFileName() {
|
|||||||
clearScreen();
|
clearScreen();
|
||||||
std::cout << "\n\n"
|
std::cout << "\n\n"
|
||||||
<< setMiddle("Student Info Management",
|
<< setMiddle("Student Info Management",
|
||||||
std::min(getConsoleSize().width, 80))
|
std::min(getConsoleSize().width, 120))
|
||||||
<< "\n\n\n"
|
<< "\n\n\n"
|
||||||
<< setMiddle("(O)pen file (N)ew file",
|
<< setMiddle("(O)pen file (N)ew file",
|
||||||
std::min(getConsoleSize().width, 80))
|
std::min(getConsoleSize().width, 120))
|
||||||
<< "\n\n\n"
|
<< "\n\n\n"
|
||||||
<< std::flush;
|
<< std::flush;
|
||||||
|
|
||||||
@@ -350,11 +350,21 @@ bool StudentInfoManager::cmdNew() {
|
|||||||
if (useTodayDate) {
|
if (useTodayDate) {
|
||||||
time_t curTime;
|
time_t curTime;
|
||||||
time(&curTime);
|
time(&curTime);
|
||||||
tm *curDate = localtime(&curTime);
|
|
||||||
|
tm curDate;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
curDate = *(localtime(&curTime));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
localtime_s(&curDate, &curTime);
|
||||||
|
#endif
|
||||||
|
|
||||||
tm newDate;
|
tm newDate;
|
||||||
newDate.tm_year = curDate->tm_year;
|
newDate.tm_year = curDate.tm_year;
|
||||||
newDate.tm_mon = curDate->tm_mon;
|
newDate.tm_mon = curDate.tm_mon;
|
||||||
newDate.tm_mday = curDate->tm_mday;
|
newDate.tm_mday = curDate.tm_mday;
|
||||||
newDate.tm_hour = 0;
|
newDate.tm_hour = 0;
|
||||||
newDate.tm_min = 0;
|
newDate.tm_min = 0;
|
||||||
newDate.tm_sec = 0;
|
newDate.tm_sec = 0;
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
#include "Tools.hpp"
|
#include "Tools.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef __API_AVAILABLE_PLATFORM_macosx
|
#ifdef __APPLE__
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <conio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace ConsoleColorTool;
|
using namespace ConsoleColorTool;
|
||||||
|
|
||||||
setoutputcolor::setoutputcolor(ConsoleColors _color)
|
setoutputcolor::setoutputcolor(ConsoleColors _color)
|
||||||
@@ -128,7 +133,7 @@ const std::string setMiddle(const std::string str, const int targetLength,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __API_AVAILABLE_PLATFORM_macosx
|
#ifdef __APPLE__
|
||||||
void clearScreen() {
|
void clearScreen() {
|
||||||
system("clear");
|
system("clear");
|
||||||
}
|
}
|
||||||
@@ -165,6 +170,34 @@ const termSize getConsoleSize() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
void clearScreen() {
|
||||||
|
std::cout << "\x1B[2J\x1B[H" << std::flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disableEchoBack() {
|
||||||
|
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
DWORD mode = 0;
|
||||||
|
GetConsoleMode(hStdin, &mode);
|
||||||
|
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT) & (~ENABLE_LINE_INPUT) & (~ENABLE_PROCESSED_INPUT));
|
||||||
|
}
|
||||||
|
|
||||||
|
void enableEchoBack() {
|
||||||
|
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
DWORD mode = 0;
|
||||||
|
GetConsoleMode(hStdin, &mode);
|
||||||
|
SetConsoleMode(hStdin, mode | (ENABLE_ECHO_INPUT) | (ENABLE_LINE_INPUT) | (ENABLE_PROCESSED_INPUT));
|
||||||
|
}
|
||||||
|
|
||||||
|
const termSize getConsoleSize() {
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO scrInfo;
|
||||||
|
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
GetConsoleScreenBufferInfo(hStdout, &scrInfo);
|
||||||
|
return termSize{ .width=scrInfo.dwSize.X, .height=scrInfo.dwSize.Y };
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void backSpace(int num) {
|
void backSpace(int num) {
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
std::cout << "\033[D";
|
std::cout << "\033[D";
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
// Reference: https://cplusplus.com/forum/unices/36461/
|
// Reference: https://cplusplus.com/forum/unices/36461/
|
||||||
// Reference: https://isocpp.org/wiki/faq/input-output#turn-off-tty-echo
|
// Reference: https://isocpp.org/wiki/faq/input-output#turn-off-tty-echo
|
||||||
// Reference:
|
// Reference:
|
||||||
// https://forums.codeguru.com/showthread.php?466009-Reading-from-stdin-(without-echo)
|
// https://forums.codeguru.com/showthread.php?466009-Reading-from-stdin-(without-echo)
|
||||||
|
// Reference: https://dev.to/tenry/predefined-c-c-macros-43id
|
||||||
|
|
||||||
namespace ConsoleColorTool {
|
namespace ConsoleColorTool {
|
||||||
enum ConsoleColors {
|
enum ConsoleColors {
|
||||||
@@ -21,6 +23,11 @@ enum ConsoleColors {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct termSize {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
class setoutputcolor {
|
class setoutputcolor {
|
||||||
private:
|
private:
|
||||||
ConsoleColorTool::ConsoleColors color;
|
ConsoleColorTool::ConsoleColors color;
|
||||||
@@ -67,11 +74,6 @@ void enableEchoBack();
|
|||||||
// (maybe?)
|
// (maybe?)
|
||||||
void backSpace(int num);
|
void backSpace(int num);
|
||||||
|
|
||||||
struct termSize {
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return the size of the command line terminal
|
// Return the size of the command line terminal
|
||||||
const termSize getConsoleSize();
|
const termSize getConsoleSize();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#include "Tools.hpp"
|
#include "Tools.hpp"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
#if defined _WIN64 || defined _WIN32
|
||||||
|
system("chcp 65001");
|
||||||
|
#endif
|
||||||
enableEchoBack(); // Just in case
|
enableEchoBack(); // Just in case
|
||||||
StudentInfoManager *studManager;
|
StudentInfoManager *studManager;
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user