terminal.h 1.7 KB

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