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