Files
BasicsOfComputerSoftwareEng…/大作业/Tools.hpp

48 lines
1.2 KiB
C++

#pragma once
#include <iostream>
// Reference: https://cplusplus.com/forum/unices/36461/
namespace ConsoleColorTool {
enum ConsoleColors {
black,
red,
green,
brown,
blue,
magenta,
cyan,
lightGray,
clear
};
};
class setoutputcolor {
private:
ConsoleColorTool::ConsoleColors color;
bool bold;
friend std::ostream &operator<<(std::ostream &out,
setoutputcolor setOutput);
public:
setoutputcolor(ConsoleColorTool::ConsoleColors _color);
setoutputcolor(bool bold);
setoutputcolor(ConsoleColorTool::ConsoleColors _color, bool bold);
};
class setbgcolor {
private:
ConsoleColorTool::ConsoleColors color;
friend std::ostream &operator<<(std::ostream &out, setbgcolor setbg);
public:
setbgcolor(ConsoleColorTool::ConsoleColors _color);
};
std::ostream &resetOutputColor(std::ostream &out);
// If the string is shorter than length, returns the string; if the string
// is longer than length, takes the first lenght - 1 letters and add a "+".
const std::string cutToLength(const std::string str, const int length);
const std::string setMiddle(const std::string str, const int targetLength, char fillChar = ' ');