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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef REPLXX_IO_HXX_INCLUDED
  2. #define REPLXX_IO_HXX_INCLUDED 1
  3. #include <deque>
  4. #ifdef _WIN32
  5. #include <vector>
  6. #include <windows.h>
  7. #else
  8. #include <termios.h>
  9. #endif
  10. #include "utf8string.hxx"
  11. namespace replxx {
  12. class Terminal {
  13. public:
  14. enum class EVENT_TYPE {
  15. KEY_PRESS,
  16. MESSAGE,
  17. TIMEOUT,
  18. RESIZE
  19. };
  20. private:
  21. #ifdef _WIN32
  22. HANDLE _consoleOut;
  23. HANDLE _consoleIn;
  24. DWORD _origOutMode;
  25. DWORD _origInMode;
  26. bool _autoEscape;
  27. WORD _oldDisplayAttribute;
  28. UINT const _inputCodePage;
  29. UINT const _outputCodePage;
  30. HANDLE _interrupt;
  31. typedef std::deque<EVENT_TYPE> events_t;
  32. events_t _events;
  33. std::vector<char> _empty;
  34. #else
  35. struct termios _origTermios; /* in order to restore at exit */
  36. int _interrupt[2];
  37. #endif
  38. bool _rawMode; /* for destructor to check if restore is needed */
  39. Utf8String _utf8;
  40. public:
  41. enum class CLEAR_SCREEN {
  42. WHOLE,
  43. TO_END
  44. };
  45. public:
  46. Terminal( void );
  47. ~Terminal( void );
  48. void write32( char32_t const*, int );
  49. void write8( char const*, int );
  50. int get_screen_columns(void);
  51. int get_screen_rows(void);
  52. void enable_bracketed_paste( void );
  53. void disable_bracketed_paste( void );
  54. int enable_raw_mode(void);
  55. void disable_raw_mode(void);
  56. char32_t read_char(void);
  57. void clear_screen( CLEAR_SCREEN );
  58. EVENT_TYPE wait_for_input( int long = 0 );
  59. void notify_event( EVENT_TYPE );
  60. void jump_cursor( int, int );
  61. void set_cursor_visible( bool );
  62. #ifndef _WIN32
  63. int read_verbatim( char32_t*, int );
  64. int install_window_change_handler( void );
  65. #endif
  66. private:
  67. void enable_out( void );
  68. void disable_out( void );
  69. private:
  70. Terminal( Terminal const& ) = delete;
  71. Terminal& operator = ( Terminal const& ) = delete;
  72. Terminal( Terminal&& ) = delete;
  73. Terminal& operator = ( Terminal&& ) = delete;
  74. };
  75. void beep();
  76. char32_t read_unicode_character(void);
  77. namespace tty {
  78. extern bool in;
  79. extern bool out;
  80. }
  81. }
  82. #endif