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