termcolor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. /*
  3. * Escape sequences handling and common constants
  4. */
  5. #include <string>
  6. #include <iostream>
  7. namespace bzbterm {
  8. // EscSeq is an helper class to handle escape sequences
  9. struct EscSeq {
  10. std::string str {""};
  11. // Initialize with given escaped string
  12. EscSeq(std::string s) : str(s) {}
  13. friend std::ostream& operator<<(std::ostream& stream, const EscSeq& e) {
  14. stream << e.str;
  15. return stream;
  16. }
  17. };
  18. namespace style {
  19. const EscSeq reset("\033[0m");
  20. const EscSeq bold("\033[1m");
  21. const EscSeq faint("\033[2m");
  22. const EscSeq italic("\033[3m");
  23. const EscSeq underline("\033[4m");
  24. const EscSeq overline("\033[53m");
  25. const EscSeq blink("\033[5m");
  26. const EscSeq blink_rapid("\033[6m");
  27. const EscSeq reverse("\033[7m");
  28. const EscSeq conceal("\033[8m");
  29. const EscSeq crossedout("\033[9m");
  30. const EscSeq defaultfont("\033[10m");
  31. const EscSeq altfont1("\033[11m");
  32. const EscSeq altfont2("\033[12m");
  33. const EscSeq altfont3("\033[13m");
  34. const EscSeq altfont4("\033[14m");
  35. const EscSeq altfont5("\033[15m");
  36. const EscSeq altfont6("\033[16m");
  37. const EscSeq altfont7("\033[17m");
  38. const EscSeq altfont8("\033[18m");
  39. const EscSeq altfont9("\033[19m");
  40. const EscSeq bold_off("\033[21m");
  41. const EscSeq normal("\033[22m");
  42. const EscSeq italic_off("\033[23m");
  43. const EscSeq underline_off("\033[24m");
  44. const EscSeq blink_off("\033[25m");
  45. const EscSeq inverse_off("\033[27m");
  46. const EscSeq conceal_off("\033[28m");
  47. const EscSeq crossedout_off("\033[29m");
  48. const EscSeq framed("\033[51m");
  49. const EscSeq encircled("\033[52m");
  50. const EscSeq overlined("\033[53m");
  51. const EscSeq framed_off("\033[54m");
  52. const EscSeq overlined_off("\033[55m");
  53. }
  54. namespace fg {
  55. const EscSeq bright_black("\033[90m");
  56. const EscSeq bright_red("\033[91m");
  57. const EscSeq bright_green("\033[92m");
  58. const EscSeq bright_yellow("\033[93m");
  59. const EscSeq bright_blue("\033[94m");
  60. const EscSeq bright_magenta("\033[95m");
  61. const EscSeq bright_cyan("\033[96m");
  62. const EscSeq bright_white("\033[97m");
  63. const EscSeq black("\033[30m");
  64. const EscSeq red("\033[31m");
  65. const EscSeq green("\033[32m");
  66. const EscSeq yellow("\033[33m");
  67. const EscSeq blue("\033[34m");
  68. const EscSeq magenta("\033[35m");
  69. const EscSeq cyan("\033[36m");
  70. const EscSeq white("\033[37m");
  71. const EscSeq reset("\033[39m");
  72. }
  73. namespace bg {
  74. const EscSeq bright_black("\033[100m");
  75. const EscSeq bright_red("\033[101m");
  76. const EscSeq bright_green("\033[102m");
  77. const EscSeq bright_yellow("\033[103m");
  78. const EscSeq bright_blue("\033[104m");
  79. const EscSeq bright_magenta("\033[105m");
  80. const EscSeq bright_cyan("\033[106m");
  81. const EscSeq bright_white("\033[107m");
  82. const EscSeq black("\033[40m");
  83. const EscSeq red("\033[41m");
  84. const EscSeq green("\033[42m");
  85. const EscSeq yellow("\033[43m");
  86. const EscSeq blue("\033[44m");
  87. const EscSeq magenta("\033[45m");
  88. const EscSeq cyan("\033[46m");
  89. const EscSeq white("\033[47m");
  90. const EscSeq reset("\033[49m");
  91. }
  92. }