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.

136 lines
4.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* XTerm display handler routines header.
  2. Copyright by Salvador E. Tropea (SET) (2002-2003)
  3. Covered by the GPL license. */
  4. #if defined(TVOS_UNIX) && !defined(TVOSf_QNXRtP) && !defined(XTERMSCREEN_HEADER_INCLUDED)
  5. #define XTERMSCREEN_HEADER_INCLUDED
  6. // virtual to avoid problems with multiple inheritance
  7. class TDisplayXTerm : virtual public TDisplay
  8. {
  9. protected:
  10. TDisplayXTerm() {};
  11. // We will use casts to base classes, destructors must be pointers
  12. virtual ~TDisplayXTerm();
  13. // This sets the pointers of TDisplay to point to this class
  14. static void Init();
  15. // Behaviors to replace TDisplay
  16. static void SetCursorPos(unsigned x, unsigned y);
  17. static void GetCursorPos(unsigned &x, unsigned &y);
  18. static void SetCursorShape(unsigned start, unsigned end);
  19. static void GetCursorShape(unsigned &start, unsigned &end);
  20. // Not available static void clearScreen(uchar, uchar);
  21. static ushort GetRowsIOCTL();
  22. static ushort GetRowsSeq();
  23. static ushort GetColsIOCTL();
  24. static ushort GetColsSeq();
  25. // Not available static void SetCrtMode(ushort mode);
  26. // Not available static ushort getCrtMode();
  27. // Not available static void SetCrtModeExt(char *mode);
  28. static int SetCrtModeXT(unsigned w, unsigned h, int , int );
  29. static int SetCrtModeEt(unsigned w, unsigned h, int , int );
  30. static int CheckForWindowSize(void);
  31. static const char *GetWindowTitle(void);
  32. static int SetWindowTitle(const char *name);
  33. static int SetDisPaletteColorsXT(int from, int number, TScreenColor *colors);
  34. static int SetDisPaletteColorsEt(int from, int number, TScreenColor *colors);
  35. // Functions and members specific for this driver
  36. // Current cursor position
  37. static int curX, curY;
  38. // Current cursor shape
  39. static int cursorStart,cursorEnd;
  40. // 1 when the size of the window where the program is running changed
  41. static volatile sig_atomic_t windowSizeChanged;
  42. static int hOut; // Handle for the console output
  43. // Font size, this is just a guess
  44. static unsigned fontW,fontH;
  45. // To distiguish between similar terminals
  46. enum { XTerm, Eterm };
  47. static int terminalType;
  48. // How to restore the palette
  49. static void ResetPaletteColorsXT();
  50. static void ResetPaletteColorsEt();
  51. static void (*ResetPaletteColors)();
  52. // Color translation table
  53. static char cMap[16];
  54. // Which charset is currently selected (G0/G1)
  55. static int selCharset;
  56. // Available font sizes
  57. static TScreenResolution XFonts[];
  58. static char fontChanged;
  59. static char *oldFontName;
  60. static char *GetCurrentFontName();
  61. // Window size at start-up
  62. static uchar startScreenWidth,startScreenHeight;
  63. };
  64. // With this order the destructor will be called first for TScreen,
  65. // TScreenXTerm, TScreen, TScreenXTerm::suspend, TDisplayXTerm and
  66. // finally TDisplay (twice).
  67. class TScreenXTerm : public TDisplayXTerm, public TScreen
  68. {
  69. public:
  70. TScreenXTerm();
  71. // We will use casts to base classes, destructors must be pointers
  72. virtual ~TScreenXTerm();
  73. friend class TDisplayXTerm;
  74. protected:
  75. static void Suspend();
  76. static void Resume();
  77. // Default: ushort fixCrtMode( ushort mode )
  78. // Default: void setCrtData();
  79. // Default: void clearScreen()
  80. static void SetVideoMode(ushort mode);
  81. static void SetVideoModeExt(char *mode);
  82. // Default: static void GetCharacters(unsigned offset,ushort *buf,unsigned count);
  83. // Default: static ushort GetCharacter(unsigned dst);
  84. // Default: static void SetCharacter(unsigned offset,ushort value);
  85. static void SetCharacters(unsigned dst,ushort *src,unsigned len);
  86. static int System(const char *command, pid_t *pidChild, int in, int out,
  87. int err);
  88. // Initialization code executed just once
  89. static int InitOnce();
  90. // Initialize member pointers
  91. static void Init();
  92. // Window size change signal handler
  93. static void sigWindowSizeChanged(int sig);
  94. // Helper function to save the current content of the screen
  95. static void SaveScreen();
  96. static void RestoreScreen();
  97. static void SaveScreenReleaseMemory(void);
  98. // Helper used to resize screenBuffer
  99. static void CheckSizeBuffer(int oldWidth, int oldHeight);
  100. // Helper to write the text and escape sequences
  101. static void writeBlock(int dst, int len, ushort *old, ushort *src);
  102. // Helper to set the color escape sequence
  103. static void mapColor(int col);
  104. // Closes and releases all, called from TDisplayXTerm
  105. static void DeallocateResources();
  106. // Terminal state before starting
  107. static struct termios outTermiosOrig;
  108. // Our terminal state
  109. static struct termios outTermiosNew;
  110. // Last error
  111. static const char *error;
  112. // Kind of palette
  113. static int palette;
  114. enum
  115. {
  116. PAL_MONO, PAL_LOW, PAL_HIGH, PAL_LOW2
  117. };
  118. // Current colors, for escape sequences
  119. static int oldCol, oldBack, oldFore;
  120. // Tables to convert to ISO 2022 scheme
  121. static const uchar Code[256];
  122. static const uchar Modifier[256];
  123. // Indicates if we must use the shell screen instead of the secondary buffer
  124. static char useShellScreen;
  125. };
  126. #endif // XTERMSCREEN_HEADER_INCLUDED