初具人形!
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
#include "Tools.hpp"
|
||||
#include <string>
|
||||
|
||||
#ifdef __API_AVAILABLE_PLATFORM_macosx
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace ConsoleColorTool;
|
||||
|
||||
setoutputcolor::setoutputcolor(ConsoleColors _color)
|
||||
@@ -102,7 +109,8 @@ const std::string cutToLength(const std::string str, const int length) {
|
||||
}
|
||||
}
|
||||
|
||||
const std::string setMiddle(const std::string str, const int targetLength, char fillChar) {
|
||||
const std::string setMiddle(const std::string str, const int targetLength,
|
||||
char fillChar) {
|
||||
if (str.length() >= targetLength) {
|
||||
return cutToLength(str, targetLength);
|
||||
}
|
||||
@@ -118,4 +126,58 @@ const std::string setMiddle(const std::string str, const int targetLength, char
|
||||
result += fillChar;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __API_AVAILABLE_PLATFORM_macosx
|
||||
void clearScreen() {
|
||||
system("clear");
|
||||
}
|
||||
// May be useful on linux. Does not work on mac OS.
|
||||
// void disableEchoBack() {
|
||||
// termios term;
|
||||
// tcgetattr(STDIN_FILENO, &term);
|
||||
// termios newTerm = term;
|
||||
// newTerm.c_lflag &= -ECHO;
|
||||
// tcsetattr(STDIN_FILENO, TCSANOW, &newTerm);
|
||||
// }
|
||||
|
||||
// void enableEchoBack() {
|
||||
// termios term;
|
||||
// tcgetattr(STDIN_FILENO, &term);
|
||||
// term.c_lflag &= ECHO;
|
||||
// tcsetattr(STDIN_FILENO, TCSANOW, &term);
|
||||
// }
|
||||
|
||||
void disableEchoBack() {
|
||||
system("stty -echo");
|
||||
system("stty raw");
|
||||
}
|
||||
|
||||
void enableEchoBack() {
|
||||
system("stty echo");
|
||||
system("stty cooked");
|
||||
}
|
||||
|
||||
const termSize getConsoleSize() {
|
||||
winsize size;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
|
||||
return termSize{.height = size.ws_row, .width = size.ws_col};
|
||||
}
|
||||
#endif
|
||||
|
||||
void backSpace(int num) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
std::cout << "\033[D";
|
||||
}
|
||||
std::cout << std::string(num, ' ');
|
||||
for (int i = 0; i < num; i++) {
|
||||
std::cout << "\033[D";
|
||||
}
|
||||
}
|
||||
|
||||
void waitForAnyInput() {
|
||||
std::cout << "Press any key to continue..." << std::flush;
|
||||
disableEchoBack();
|
||||
std::cin.get();
|
||||
enableEchoBack();
|
||||
}
|
||||
Reference in New Issue
Block a user