12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include "boxes.h"
- Boxes::Boxes(int width, int style, bool newline) {
- width_ = width;
- style_ = style;
- newline_ = newline;
- }
- std::string Boxes::top(void) {
- std::string line;
- box_style &bs = boxes[style_];
- line.append(boxcolor);
- line.append(1, bs.top_left);
- // for (int x = 0; x < width_; ++x)
- line.append(width_, bs.top);
- line.append(1, bs.top_right);
- line.append(reset);
- if (newline_)
- line.append(nl);
- return line;
- }
- std::string Boxes::middle(void) {
- std::string line;
- box_style &bs = boxes[style_];
- line.append(boxcolor);
- line.append(1, bs.middle_left);
- // for (int x = 0; x < width_; ++x)
- line.append(width_, bs.top);
- line.append(1, bs.middle_right);
- line.append(reset);
- if (newline_)
- line.append(nl);
- return line;
- }
- std::string Boxes::row(std::string &text) {
- std::string line;
- box_style &bs = boxes[style_];
- line.append(boxcolor);
- line.append(1, bs.side);
- if (boxcolor != textcolor) {
- line.append(reset);
- line.append(textcolor);
- }
- line.append(text);
- if (textcolor != boxcolor) {
- line.append(reset);
- line.append(boxcolor);
- }
- line.append(1, bs.side);
- line.append(reset);
- if (newline_)
- line.append(nl);
- return line;
- }
- std::string Boxes::bottom(void) {
- std::string line;
- box_style &bs = boxes[style_];
- line.append(boxcolor);
- line.append(1, bs.bottom_left);
- // for (int x = 0; x < width_; ++x)
- line.append(width_, bs.top);
- line.append(1, bs.bottom_right);
- line.append(reset);
- if (newline_)
- line.append(nl);
- return line;
- }
- std::array<std::string, 3> Boxes::alert(std::string message, std::string bcolor,
- std::string tcolor, int width,
- int style, bool newline) {
- std::array<std::string, 3> results;
- Boxes abox(width, style, newline);
- abox.boxcolor = bcolor;
- abox.textcolor = tcolor;
- results[0] = abox.top();
- results[1] = abox.row(message);
- results[2] = abox.bottom();
- return results;
- }
|