aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/patched/replxx/src/terminal.hxx
blob: 90c3640b5215ce19dd7e205743750989929606ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef REPLXX_IO_HXX_INCLUDED
#define REPLXX_IO_HXX_INCLUDED 1

#include <deque>

#ifdef _WIN32
#include <vector>
#include <windows.h>
#else
#include <termios.h>
#endif

#include "utf8string.hxx"

namespace replxx {

class Terminal {
public:
	enum class EVENT_TYPE {
		KEY_PRESS,
		MESSAGE,
		TIMEOUT,
		RESIZE
	};
private:
#ifdef _WIN32
	HANDLE _consoleOut;
	HANDLE _consoleIn;
	DWORD _origOutMode;
	DWORD _origInMode;
	bool _autoEscape;
	WORD _oldDisplayAttribute;
	UINT const _inputCodePage;
	UINT const _outputCodePage;
	HANDLE _interrupt;
	typedef std::deque<EVENT_TYPE> events_t;
	events_t _events;
	std::vector<char> _empty;
#else
	struct termios _origTermios; /* in order to restore at exit */
	struct termios _rawModeTermios; /* in order to reset raw mode after callbacks */
	int _interrupt[2];
#endif
	bool _rawMode; /* for destructor to check if restore is needed */
	Utf8String _utf8;
public:
	enum class CLEAR_SCREEN {
		WHOLE,
		TO_END
	};
public:
	Terminal( void );
	~Terminal( void );
	void write32( char32_t const*, int );
	void write8( char const*, int );
	int get_screen_columns(void);
	int get_screen_rows(void);
	void enable_bracketed_paste( void );
	void disable_bracketed_paste( void );
	int enable_raw_mode(void);
	int reset_raw_mode(void);
	void disable_raw_mode(void);
	char32_t read_char(void);
	void clear_screen( CLEAR_SCREEN );
	EVENT_TYPE wait_for_input( int long = 0 );
	void notify_event( EVENT_TYPE );
	void jump_cursor( int, int );
	void set_cursor_visible( bool );
#ifndef _WIN32
	int read_verbatim( char32_t*, int );
	int install_window_change_handler( void );
#endif
private:
	void enable_out( void );
	void disable_out( void );
private:
	Terminal( Terminal const& ) = delete;
	Terminal& operator = ( Terminal const& ) = delete;
	Terminal( Terminal&& ) = delete;
	Terminal& operator = ( Terminal&& ) = delete;
};

void beep();
char32_t read_unicode_character(void);

namespace tty {

extern bool in;
extern bool out;

}

}

#endif