Commit d06c5590 authored by Zhiping Jiang (蒋志平)'s avatar Zhiping Jiang (蒋志平) 💬

add simple print function

parent 47a8b61f
......@@ -9,6 +9,118 @@
namespace EnhancedConsoleText::CodingStyle {
inline void normalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::NoColor);
}
inline void blueNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Blue);
}
inline void greenNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Green);
}
inline void yellowNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Yellow);
}
inline void redNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Red);
}
inline void cyanNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Cyan);
}
inline void magentaNormalTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Left, FrontColor::Magenta);
}
inline void normalBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::NoColor);
}
inline void blueBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Blue);
}
inline void greenBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Green);
}
inline void yellowBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Yellow);
}
inline void redBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Red);
}
inline void cyanBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Cyan);
}
inline void magentaBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Left, FrontColor::Magenta);
}
inline void normalCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::NoColor);
}
inline void blueCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Blue);
}
inline void greenCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Green);
}
inline void yellowCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Yellow);
}
inline void redCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Red);
}
inline void cyanCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Cyan);
}
inline void magentaCenteredTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Reset, LineAlignment::Center, FrontColor::Magenta);
}
inline void normalCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::NoColor);
}
inline void blueCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Blue);
}
inline void greenCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Green);
}
inline void yellowCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Yellow);
}
inline void redCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Red);
}
inline void cyanCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Cyan);
}
inline void magentaCenteredBoldTextPrint(const std::string &content) {
EnhancedConsoleText::print(content, FontEffect::Bold, LineAlignment::Center, FrontColor::Magenta);
}
inline void normalTextPrintln(const std::string &content) {
EnhancedConsoleText::println(content, FontEffect::Reset, LineAlignment::Left, FrontColor::NoColor);
}
......
......@@ -18,6 +18,21 @@ namespace EnhancedConsoleText {
return converter.to_bytes(content);
}
void print(const std::string &content, FontEffect fontEffect, LineAlignment lineAlignment, FrontColor frontColor,
BackgroundColor bgColor) {
std::regex newlineRegex("\n");
std::smatch match;
std::vector<std::string> lineSplits {
std::sregex_token_iterator(content.begin(), content.end(), newlineRegex, -1), {}
};
for(auto i = 0; i < lineSplits.size(); i++) {
std::cout << decorateString(lineSplits[i], fontEffect, lineAlignment, frontColor, bgColor)<<std::endl;
}
}
void println(const std::string &content, FontEffect fontEffect, LineAlignment lineAlignment, FrontColor frontColor,
BackgroundColor bgColor) {
std::regex newlineRegex("\n");
......
......@@ -64,6 +64,11 @@ namespace EnhancedConsoleText {
std::string wstring2String(std::wstring content);
std::string decorateString(const std::string &content, FontEffect fontEffect, LineAlignment lineAlignment, FrontColor frontColor,
BackgroundColor bgColor);
void print(const std::string &content, FontEffect frontEffect = FontEffect::Reset,
LineAlignment lineAlignment = LineAlignment::Left,
FrontColor frontColor = FrontColor::NoColor,
BackgroundColor bgColor = BackgroundColor::NoColor);
void println(const std::string &content, FontEffect frontEffect = FontEffect::Reset,
LineAlignment lineAlignment = LineAlignment::Left,
FrontColor frontColor = FrontColor::NoColor,
......
......@@ -9,7 +9,41 @@ int main() {
EnhancedConsoleText::lineWidth = 120;
EnhancedConsoleText::println("Bold Green Centered Title with Red background", FontEffect::Bold, LineAlignment::Center, FrontColor::Green, BackgroundColor::Red);
EnhancedConsoleText::CodingStyle::normalTextPrintln("EnhancedConsoleText::CodingStyle::normalTextPrintln");
EnhancedConsoleText::CodingStyle::normalTextPrint("EnhancedConsoleText::\nCodingStyle::\nnormalTextPrint\n");
EnhancedConsoleText::CodingStyle::cyanNormalTextPrint("EnhancedConsoleText::CodingStyle::cyanNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::greenNormalTextPrint("EnhancedConsoleText::CodingStyle::greenNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::redNormalTextPrint("EnhancedConsoleText::CodingStyle::redNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::yellowNormalTextPrint("EnhancedConsoleText::CodingStyle::yellowNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::magentaNormalTextPrint("EnhancedConsoleText::CodingStyle::magentaNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::blueNormalTextPrint("EnhancedConsoleText::CodingStyle::blueNormalTextPrint\n");
EnhancedConsoleText::CodingStyle::normalBoldTextPrint("EnhancedConsoleText::CodingStyle::normalBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::cyanBoldTextPrint("EnhancedConsoleText::CodingStyle::cyanBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::greenBoldTextPrint("EnhancedConsoleText::\nCodingStyle::\nnormalTextPrint\n");
EnhancedConsoleText::CodingStyle::redBoldTextPrint("EnhancedConsoleText::CodingStyle::redBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::yellowBoldTextPrint("EnhancedConsoleText::CodingStyle::yellowBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::magentaBoldTextPrint("EnhancedConsoleText::CodingStyle::magentaBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::blueBoldTextPrint("EnhancedConsoleText::CodingStyle::blueBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::normalCenteredTextPrint("EnhancedConsoleText::CodingStyle::normalCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::cyanCenteredTextPrint("EnhancedConsoleText::CodingStyle::cyanCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::greenCenteredTextPrint("EnhancedConsoleText::CodingStyle::greenCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::redCenteredTextPrint("EnhancedConsoleText::CodingStyle::redCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::yellowCenteredTextPrint("EnhancedConsoleText::CodingStyle::yellowCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::magentaCenteredTextPrint("EnhancedConsoleText::CodingStyle::magentaCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::blueCenteredTextPrint("EnhancedConsoleText::CodingStyle::blueCenteredTextPrint\n");
EnhancedConsoleText::CodingStyle::normalCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::normalCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::cyanCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::cyanCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::greenCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::greenCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::redCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::redCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::yellowCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::yellowCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::magentaCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::magentaCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::blueCenteredBoldTextPrint("EnhancedConsoleText::CodingStyle::blueCenteredBoldTextPrint\n");
EnhancedConsoleText::CodingStyle::normalTextPrintln("EnhancedConsoleText::\nCodingStyle::\nnormalTextPrintln");
EnhancedConsoleText::CodingStyle::cyanNormalTextPrintln("EnhancedConsoleText::CodingStyle::cyanNormalTextPrintln");
EnhancedConsoleText::CodingStyle::greenNormalTextPrintln("EnhancedConsoleText::CodingStyle::greenNormalTextPrintln");
EnhancedConsoleText::CodingStyle::redNormalTextPrintln("EnhancedConsoleText::CodingStyle::redNormalTextPrintln");
......@@ -19,7 +53,7 @@ int main() {
EnhancedConsoleText::CodingStyle::normalBoldTextPrintln("EnhancedConsoleText::CodingStyle::normalBoldTextPrintln");
EnhancedConsoleText::CodingStyle::cyanBoldTextPrintln("EnhancedConsoleText::CodingStyle::cyanBoldTextPrintln");
EnhancedConsoleText::CodingStyle::greenBoldTextPrintln("EnhancedConsoleText::CodingStyle::greenBoldTextPrintln");
EnhancedConsoleText::CodingStyle::greenBoldTextPrintln("EnhancedConsoleText::\nCodingStyle::\nnormalTextPrintln");
EnhancedConsoleText::CodingStyle::redBoldTextPrintln("EnhancedConsoleText::CodingStyle::redBoldTextPrintln");
EnhancedConsoleText::CodingStyle::yellowBoldTextPrintln("EnhancedConsoleText::CodingStyle::yellowBoldTextPrintln");
EnhancedConsoleText::CodingStyle::magentaBoldTextPrintln("EnhancedConsoleText::CodingStyle::magentaBoldTextPrintln");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment