termbase.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. /*
  3. * Functions to handle the terminal and its properties
  4. */
  5. #include "bzbterm/termcolor.h"
  6. #include "bzbstring/stringutils.h"
  7. namespace bzbterm {
  8. /*
  9. * Prints the specified escape sequence
  10. */
  11. inline void set_esc_seq(EscSeq e) {
  12. std::cout << e;
  13. }
  14. /*
  15. * Changes the shell's font color
  16. */
  17. inline void set_fg_color(unsigned int r, unsigned int g, unsigned int b) {
  18. std::cout << bzbstring::concat("\033[38;2;", r, ";", g, ";", b, "m");
  19. }
  20. /*
  21. * Changes the shell's font color
  22. */
  23. inline void set_bg_color(unsigned int r, unsigned int g, unsigned int b) {
  24. std::cout << bzbstring::concat("\033[48;2;", r, ";", g, ";", b, "m");
  25. }
  26. /*
  27. * Clears the screen and resets the cursor to the top left corner
  28. */
  29. inline void clear_screen() {
  30. std::cout << "\033[1;1H" << "\033[2J";
  31. }
  32. /*
  33. * Saves the screen's content for later restoring it
  34. */
  35. inline void save_screen() {
  36. std::cout << "\033[?47h";
  37. }
  38. /*
  39. * Restore the screen's content as saved before
  40. */
  41. inline void restore_screen() {
  42. std::cout << "\033[?47l";
  43. }
  44. /*
  45. * Clears the current line
  46. */
  47. inline void clear_line() noexcept {
  48. std::cout << "\033[2K";
  49. }
  50. /*
  51. * Hide the cursor
  52. */
  53. inline void show_cursor() noexcept {
  54. std::cout << "\033[?25h";
  55. }
  56. /*
  57. * Hide the cursor
  58. */
  59. inline void hide_cursor() noexcept {
  60. std::cout << "\033[?25l";
  61. }
  62. }