boxes.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "boxes.h"
  2. Boxes::Boxes(int width, int style, bool newline) {
  3. width_ = width;
  4. style_ = style;
  5. newline_ = newline;
  6. }
  7. std::string Boxes::top(void) {
  8. std::string line;
  9. box_style &bs = boxes[style_];
  10. line.append(boxcolor);
  11. line.append(1, bs.top_left);
  12. // for (int x = 0; x < width_; ++x)
  13. line.append(width_, bs.top);
  14. line.append(1, bs.top_right);
  15. line.append(reset);
  16. if (newline_)
  17. line.append(nl);
  18. return line;
  19. }
  20. std::string Boxes::middle(void) {
  21. std::string line;
  22. box_style &bs = boxes[style_];
  23. line.append(boxcolor);
  24. line.append(1, bs.middle_left);
  25. // for (int x = 0; x < width_; ++x)
  26. line.append(width_, bs.top);
  27. line.append(1, bs.middle_right);
  28. line.append(reset);
  29. if (newline_)
  30. line.append(nl);
  31. return line;
  32. }
  33. std::string Boxes::row(std::string &text) {
  34. std::string line;
  35. box_style &bs = boxes[style_];
  36. line.append(boxcolor);
  37. line.append(1, bs.side);
  38. if (boxcolor != textcolor) {
  39. line.append(reset);
  40. line.append(textcolor);
  41. }
  42. line.append(text);
  43. if (textcolor != boxcolor) {
  44. line.append(reset);
  45. line.append(boxcolor);
  46. }
  47. line.append(1, bs.side);
  48. line.append(reset);
  49. if (newline_)
  50. line.append(nl);
  51. return line;
  52. }
  53. std::string Boxes::bottom(void) {
  54. std::string line;
  55. box_style &bs = boxes[style_];
  56. line.append(boxcolor);
  57. line.append(1, bs.bottom_left);
  58. // for (int x = 0; x < width_; ++x)
  59. line.append(width_, bs.top);
  60. line.append(1, bs.bottom_right);
  61. line.append(reset);
  62. if (newline_)
  63. line.append(nl);
  64. return line;
  65. }
  66. std::array<std::string, 3> Boxes::alert(std::string message, std::string bcolor,
  67. std::string tcolor, int width,
  68. int style, bool newline) {
  69. std::array<std::string, 3> results;
  70. Boxes abox(width, style, newline);
  71. abox.boxcolor = bcolor;
  72. abox.textcolor = tcolor;
  73. results[0] = abox.top();
  74. results[1] = abox.row(message);
  75. results[2] = abox.bottom();
  76. return results;
  77. }