terminal.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef TERMINAL_H
  2. #define TERMINAL_H
  3. #include <string>
  4. #include <vector>
  5. class Terminal {
  6. private:
  7. int posx, posy;
  8. std::vector<std::pair<int, int>> saved_cursor_position;
  9. std::string ansi;
  10. int in_ansi;
  11. int fgcolor, bgcolor, status;
  12. int dcs_map; // Designate Charater Set
  13. public:
  14. enum ANSI_TYPE { START, CURSOR, COLOR, CLEAR, DCS, OTHER };
  15. struct termchar {
  16. int in_ansi;
  17. Terminal::ANSI_TYPE ansi;
  18. };
  19. public:
  20. Terminal(void);
  21. Terminal(const Terminal &old);
  22. Terminal &operator=(Terminal &rhs);
  23. void init(void);
  24. std::string color_restore(void);
  25. termchar putchar(char ch);
  26. void putstring(std::string text);
  27. int getx(void);
  28. int gety(void);
  29. int getstatus(void);
  30. int inANSI(void);
  31. int fg(void);
  32. int bg(void);
  33. bool ansiempty(void);
  34. int dcs(void);
  35. private:
  36. void ansi_color(int color);
  37. ANSI_TYPE ansi_code(std::string ansi);
  38. };
  39. // notice the curstor position history vector is missing from the struct below?
  40. // Yes, it is a global. Completely WRONG. Broken! Bad!
  41. struct console_details {
  42. int posx, posy;
  43. int savedx, savedy;
  44. char ansi[20]; // current ANSI command being processed.
  45. int in_ansi;
  46. int fgcolor; // 0-7 // not 0-15
  47. int bgcolor; // 0-7
  48. int status; // 0, 1 or 5 (Blink)
  49. };
  50. enum ANSI_TYPE { START, CURSOR, COLOR, CLEAR, OTHER };
  51. struct termchar {
  52. int in_ansi;
  53. ANSI_TYPE ansi; // undefined if in_ansi is false
  54. };
  55. void console_init(struct console_details *cdp);
  56. void ansi_color(struct console_details *cdp, int color);
  57. const char *color_restore(struct console_details *cdp);
  58. ANSI_TYPE console_ansi(struct console_details *cdp, const char *ansi);
  59. termchar console_char(struct console_details *cdp, char ch);
  60. void console_receive(struct console_details *cdp, std::string chars);
  61. #endif