You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* UNIX screen handler routines header.
  2. Copyright by Salvador E. Tropea (SET) (2001-2003)
  3. Covered by the GPL license. */
  4. #if defined(HAVE_NCURSES) && defined(TVOS_UNIX) && !defined(TVOSf_QNXRtP) && \
  5. !defined(UNIXSCREEN_HEADER_INCLUDED)
  6. #define UNIXSCREEN_HEADER_INCLUDED
  7. // virtual to avoid problems with multiple inheritance
  8. class TDisplayUNIX : virtual public TDisplay
  9. {
  10. protected:
  11. TDisplayUNIX() {};
  12. // We will use casts to base classes, destructors must be pointers
  13. virtual ~TDisplayUNIX();
  14. // This sets the pointers of TDisplay to point to this class
  15. static void Init();
  16. // Behaviors to replace TDisplay
  17. static void SetCursorPos(unsigned x, unsigned y);
  18. static void GetCursorPos(unsigned &x, unsigned &y);
  19. static void GetCursorShape(unsigned &start, unsigned &end);
  20. static void SetCursorShape(unsigned start, unsigned end);
  21. // Not available static void clearScreen(uchar, uchar);
  22. static ushort GetRows();
  23. static ushort GetCols();
  24. // Not available static void setCrtMode(ushort mode);
  25. // Not available static ushort getCrtMode();
  26. static void SetCrtModeExt(char *mode);
  27. static int CheckForWindowSize(void);
  28. // Not available static const char *getWindowTitle(void);
  29. // Not available static int setWindowTitle(const char *name);
  30. // Functions and members specific for this driver
  31. inline static void safeput(char *&p, char *cap);
  32. inline static int canWriteVCS();
  33. inline static int canReadVCS();
  34. inline static int canOnlyWriteVCS();
  35. static int vcsWfd; // virtual console system descriptor
  36. static int vcsRfd; // SET: Same for reading
  37. static int tty_fd; // tty descriptor
  38. // Current cursor position
  39. static int cur_x, cur_y;
  40. // SET: Current cursor shape
  41. static int cursorStart,cursorEnd;
  42. // SET: 1 when the size of the window where the program is running changed
  43. static volatile sig_atomic_t windowSizeChanged;
  44. };
  45. inline
  46. void TDisplayUNIX::safeput(char *&p, char *cap)
  47. {
  48. if (cap)
  49. while (*cap) *p++=*cap++;
  50. }
  51. // With this order the destructor will be called first for TScreenUnix,
  52. // TScreen, TDisplayUNIX and finally TDisplay.
  53. class TScreenUNIX : public TDisplayUNIX, public TScreen
  54. {
  55. public:
  56. TScreenUNIX();
  57. // We will use casts to base classes, destructors must be pointers
  58. virtual ~TScreenUNIX();
  59. friend class THWMouseXTerm;
  60. // Fix me: should be protected but right now is used by the editor for the
  61. // pal. that should be moved here.
  62. static void SendToTerminal(const char *value);
  63. protected:
  64. static void InitPCCharsMapping();
  65. static void sigWindowSizeChanged(int sig);
  66. static void SpecialKeysDisable(int file);
  67. static void SpecialKeysRestore(int file);
  68. static void startcurses();
  69. static void mapColor(char *&p, int col);
  70. static void writeBlock(int dst, int len, ushort *old, ushort *src);
  71. static void RestoreScreen();
  72. static void Resume();
  73. static void Suspend();
  74. // Default: ushort fixCrtMode( ushort mode )
  75. static void setCrtData();
  76. // Default: void clearScreen()
  77. static void setVideoMode(ushort mode);
  78. static void setVideoModeExt(char *mode);
  79. static void getCharacters(unsigned offset,ushort *buf,unsigned count);
  80. static ushort getCharacter(unsigned dst);
  81. static void setCharacter(unsigned offset,uint32 value);
  82. static void setCharacters(unsigned dst,ushort *src,unsigned len);
  83. static int System(const char *command, pid_t *pidChild, int in, int out,
  84. int err);
  85. enum terminalType
  86. {
  87. LINUX_TERMINAL=0,
  88. GENER_TERMINAL=1,
  89. VCSA_TERMINAL=2,
  90. XTERM_TERMINAL=3
  91. };
  92. enum
  93. {
  94. PAL_MONO, PAL_LOW, PAL_HIGH, PAL_LOW2
  95. };
  96. static int use_pc_chars;
  97. static int TerminalType;
  98. static FILE *tty_file;
  99. static int palette;
  100. static int force_redraw;
  101. // SET: data to restore the XON/XOFF control keys and others like ^C, ^\ and ^Z
  102. // Used by SpecialKeys*
  103. static cc_t oldKeys[5];
  104. // Used by mapColor:
  105. static int old_col,old_fore,old_back;
  106. // Save/Restore screen
  107. static ushort *user_buffer;
  108. static int user_buffer_size;
  109. static unsigned user_cursor_x,user_cursor_y;
  110. static char *terminal;
  111. static char cursesInitialized;
  112. static char termAttrsSaved;
  113. // SET: That's the job of curses endwin(), additionally it does a much more
  114. // complete work so I don't see the point of duplicating work, in my system
  115. // I didn't see any change after removing it, but I left the code just in
  116. // case
  117. #ifdef SAVE_TERMIOS
  118. static struct termios old_term,new_term;
  119. #endif
  120. };
  121. #endif