更新了数据的存储方式,改为存储指针。

This commit is contained in:
unlockable
2023-06-19 00:50:47 +08:00
parent ae0a2175fd
commit 7ca9f62d4c
13 changed files with 460 additions and 164 deletions

View File

@@ -1,4 +1,5 @@
#include "Tools.hpp"
using namespace ConsoleColorTool;
setoutputcolor::setoutputcolor(ConsoleColors _color)
: color(_color), bold(false){};
@@ -30,6 +31,9 @@ std::ostream &operator<<(std::ostream &out, setoutputcolor setOutput) {
case green:
out << ";32m";
break;
case brown:
out << ";33m";
break;
case blue:
out << ";34m";
break;
@@ -59,6 +63,9 @@ std::ostream &operator<<(std::ostream &out, setbgcolor setbg) {
case green:
out << "\033[7;32m";
break;
case brown:
out << "\033[7;33m";
break;
case blue:
out << "\033[7;34m";
break;
@@ -84,4 +91,31 @@ setbgcolor::setbgcolor(ConsoleColors _color) : color(_color){};
std::ostream &resetOutputColor(std::ostream &out) {
out << setoutputcolor(clear);
return out;
}
const std::string cutToLength(const std::string str, const int length) {
if (str.length() <= length) {
return str;
}
else {
return str.substr(0, length - 3) + "...";
}
}
const std::string setMiddle(const std::string str, const int targetLength, char fillChar) {
if (str.length() >= targetLength) {
return cutToLength(str, targetLength);
}
int left, right;
right = (targetLength - str.length()) / 2;
left = targetLength - str.length() - right;
std::string result;
for (int i = 0; i < left; i++) {
result += fillChar;
}
result += str;
for (int i = 0; i < right; i++) {
result += fillChar;
}
return result;
}