1*c2c66affSColin Finck #pragma once
2*c2c66affSColin Finck 
3*c2c66affSColin Finck //#include "tnconfig.h"
4*c2c66affSColin Finck 
5*c2c66affSColin Finck /* A diagram of the following values:
6*c2c66affSColin Finck  *
7*c2c66affSColin Finck  *           (0,0)
8*c2c66affSColin Finck  *              +----------------------------------------+
9*c2c66affSColin Finck  *              |                                        |
10*c2c66affSColin Finck  *              |                                        |
11*c2c66affSColin Finck  *              |                                        |
12*c2c66affSColin Finck  *              |                                        |
13*c2c66affSColin Finck  *              |                                        |
14*c2c66affSColin Finck  *              |                                        |
15*c2c66affSColin Finck  *              |                                        |
16*c2c66affSColin Finck  *              |                                        |
17*c2c66affSColin Finck  *              |                                        |
18*c2c66affSColin Finck  *              |                                        |
19*c2c66affSColin Finck  *              |                                        |
20*c2c66affSColin Finck  *              |                                        |
21*c2c66affSColin Finck  *              |                                        |
22*c2c66affSColin Finck  *              |          CON_TOP                       |
23*c2c66affSColin Finck  *              +---------------------------+.....?......|     ---
24*c2c66affSColin Finck  *              |              .            |            |      |
25*c2c66affSColin Finck  *              |              .            | <-- OR --> |      |
26*c2c66affSColin Finck  *              |              .            |            |      |
27*c2c66affSColin Finck  *  CON_LEFT    |              .            | CON_RIGHT  |
28*c2c66affSColin Finck  *    (=0)      |              .            | (=CON_     |  CON_LINES
29*c2c66affSColin Finck  *              |..............*            |   WIDTH)   |
30*c2c66affSColin Finck  *              |            (CON_CUR_X,    |            |      |
31*c2c66affSColin Finck  *              |             CON_CUR_Y)    |            |      |
32*c2c66affSColin Finck  *              |                           |            |      |
33*c2c66affSColin Finck  *              |                           |            |      |
34*c2c66affSColin Finck  *              |                           |            |      |
35*c2c66affSColin Finck  *              +---------------------------+------------+     ---
36*c2c66affSColin Finck  *                   CON_BOTTOM (=CON_TOP + CON_HEIGHT)
37*c2c66affSColin Finck  *
38*c2c66affSColin Finck  *              |--------- CON_COLS --------|
39*c2c66affSColin Finck  *
40*c2c66affSColin Finck  * Keep in mind that CON_TOP, CON_BOTTOM, CON_LEFT, and CON_RIGHT are relative
41*c2c66affSColin Finck  * to zero, but CON_CUR_X, CON_CUR_Y, CON_WIDTH, and CON_HEIGHT are relative to
42*c2c66affSColin Finck  * CON_TOP and CON_LEFT
43*c2c66affSColin Finck  */
44*c2c66affSColin Finck 
45*c2c66affSColin Finck #define CON_TOP		ConsoleInfo.srWindow.Top
46*c2c66affSColin Finck #define CON_BOTTOM	ConsoleInfo.srWindow.Bottom
47*c2c66affSColin Finck 
48*c2c66affSColin Finck #define CON_LEFT	0
49*c2c66affSColin Finck #define CON_RIGHT	(ConsoleInfo.dwSize.X - 1)
50*c2c66affSColin Finck 
51*c2c66affSColin Finck #define CON_HEIGHT	(CON_BOTTOM - CON_TOP)
52*c2c66affSColin Finck #define CON_WIDTH	(CON_RIGHT - CON_LEFT)
53*c2c66affSColin Finck #define CON_LINES	(CON_HEIGHT + 1)
54*c2c66affSColin Finck #define CON_COLS	(CON_WIDTH + 1)
55*c2c66affSColin Finck 
56*c2c66affSColin Finck #define CON_CUR_X	(ConsoleInfo.dwCursorPosition.X - CON_LEFT)
57*c2c66affSColin Finck #define CON_CUR_Y	(ConsoleInfo.dwCursorPosition.Y - CON_TOP)
58*c2c66affSColin Finck 
59*c2c66affSColin Finck 
60*c2c66affSColin Finck class TConsole {
61*c2c66affSColin Finck public:
62*c2c66affSColin Finck 	TConsole(HANDLE hConsole);
63*c2c66affSColin Finck 	~TConsole();
64*c2c66affSColin Finck 	void sync();
65*c2c66affSColin Finck 
66*c2c66affSColin Finck 	// Cursor movement routines
GetRawCursorX()67*c2c66affSColin Finck     int GetRawCursorX() {return CON_CUR_X;}
GetRawCursorY()68*c2c66affSColin Finck     int GetRawCursorY() {return CON_CUR_Y;}
GetCursorX()69*c2c66affSColin Finck     int GetCursorX() {return CON_CUR_X;}
GetCursorY()70*c2c66affSColin Finck     int GetCursorY() {
71*c2c66affSColin Finck 		if(iScrollStart != -1)
72*c2c66affSColin Finck 			return CON_CUR_Y - iScrollStart;
73*c2c66affSColin Finck 		return GetRawCursorY();
74*c2c66affSColin Finck 	}
75*c2c66affSColin Finck 	void SetRawCursorPosition(int x, int y);
76*c2c66affSColin Finck 	void SetCursorPosition(int x, int y);
77*c2c66affSColin Finck 	void SetCursorSize(int pct);
78*c2c66affSColin Finck 	void MoveCursorPosition(int x, int y);
79*c2c66affSColin Finck 
80*c2c66affSColin Finck 	// Screen mode/size routines
GetWidth()81*c2c66affSColin Finck     int GetWidth() {return CON_COLS;}
GetHeight()82*c2c66affSColin Finck     int GetHeight() {return CON_LINES;}
83*c2c66affSColin Finck 	void SetExtendedMode(int iFunction, BOOL bEnable);
84*c2c66affSColin Finck 	void SetWindowSize(int width, int height);	// Set the size of the window,
85*c2c66affSColin Finck 												// but not the buffer
86*c2c66affSColin Finck 
87*c2c66affSColin Finck 	// Color/attribute routines
SetAttrib(unsigned char wAttr)88*c2c66affSColin Finck 	void SetAttrib(unsigned char wAttr) {wAttributes = wAttr;}
GetAttrib()89*c2c66affSColin Finck     unsigned char GetAttrib() {return wAttributes;}
90*c2c66affSColin Finck     void Normal();								// Reset all attributes
91*c2c66affSColin Finck     void HighVideo();							// Aka "bold"
92*c2c66affSColin Finck     void LowVideo();
93*c2c66affSColin Finck     void SetForeground(unsigned char wAttrib);	// Set the foreground directly
94*c2c66affSColin Finck     void SetBackground(unsigned char wAttrib);
95*c2c66affSColin Finck     void BlinkOn();								// Blink on/off
96*c2c66affSColin Finck     void BlinkOff();
97*c2c66affSColin Finck 	void UnderlineOn();							// Underline on/off
98*c2c66affSColin Finck 	void UnderlineOff();
99*c2c66affSColin Finck 	void UlBlinkOn();							// Blink+Underline on/off
100*c2c66affSColin Finck 	void UlBlinkOff();
101*c2c66affSColin Finck     void ReverseOn();							// Reverse on/off
102*c2c66affSColin Finck     void ReverseOff();
103*c2c66affSColin Finck 	void Lightbg();								// High-intensity background
104*c2c66affSColin Finck 	void Darkbg();								// Low-intensity background
setDefaultFg(unsigned char u)105*c2c66affSColin Finck 	void setDefaultFg(unsigned char u) {defaultfg = u;}
setDefaultBg(unsigned char u)106*c2c66affSColin Finck 	void setDefaultBg(unsigned char u) {defaultbg = u;}
107*c2c66affSColin Finck 
108*c2c66affSColin Finck 	// Text output routines
109*c2c66affSColin Finck 	unsigned long WriteText(const char *pszString, unsigned long cbString);
110*c2c66affSColin Finck 	unsigned long WriteString(const char* pszString, unsigned long cbString);
111*c2c66affSColin Finck 	unsigned long WriteStringFast(const char *pszString, unsigned long cbString);
112*c2c66affSColin Finck 	unsigned long WriteCtrlString(const char* pszString, unsigned long cbString);
113*c2c66affSColin Finck 	unsigned long WriteCtrlChar(char c);
114*c2c66affSColin Finck 	unsigned long NetWriteString(const char* pszString, unsigned long cbString);
115*c2c66affSColin Finck 
116*c2c66affSColin Finck 	// Clear screen/screen area functions
117*c2c66affSColin Finck 	void ClearScreen(char c = ' ');
118*c2c66affSColin Finck 	void ClearWindow(int start, int end, char c = ' ');
119*c2c66affSColin Finck 	void ClearEOScreen(char c = ' ');
120*c2c66affSColin Finck 	void ClearBOScreen(char c = ' ');
121*c2c66affSColin Finck 	void ClearLine(char c = ' ');
122*c2c66affSColin Finck 	void ClearEOLine(char c = ' ');
123*c2c66affSColin Finck 	void ClearBOLine(char c = ' ');
124*c2c66affSColin Finck 
125*c2c66affSColin Finck 	// Scrolling and text output control functions
126*c2c66affSColin Finck 	void SetScroll(int start, int end);
127*c2c66affSColin Finck     void ScrollDown(int iStartRow , int iEndRow, int bUp);
ScrollAll(int bUp)128*c2c66affSColin Finck 	void ScrollAll(int bUp) {ScrollDown(iScrollStart, iScrollEnd, bUp);}
129*c2c66affSColin Finck 	void index();
130*c2c66affSColin Finck 	void reverse_index();
setLineWrap(bool bEnabled)131*c2c66affSColin Finck 	void setLineWrap(bool bEnabled){
132*c2c66affSColin Finck 		if(!ini.get_lock_linewrap())
133*c2c66affSColin Finck 			ini.set_value("Wrap_Line", bEnabled ? "true" : "false");
134*c2c66affSColin Finck 	}
getLineWrap()135*c2c66affSColin Finck 	bool getLineWrap() {return ini.get_wrapline();}
136*c2c66affSColin Finck 
137*c2c66affSColin Finck     // Insert/delete characters/lines
138*c2c66affSColin Finck 	void InsertLine(int numlines);			// Added by Titus von Boxberg 30/3/97
139*c2c66affSColin Finck     void InsertCharacter(int numchar);		// "
140*c2c66affSColin Finck     void DeleteCharacter(int numchar);		// "
InsertMode(int i)141*c2c66affSColin Finck 	void InsertMode(int i) {insert_mode = i;}
142*c2c66affSColin Finck 
143*c2c66affSColin Finck 	// Miscellaneous functions
144*c2c66affSColin Finck 	void Beep();
145*c2c66affSColin Finck 
146*c2c66affSColin Finck protected:
147*c2c66affSColin Finck 	HANDLE hConsole;
148*c2c66affSColin Finck 
149*c2c66affSColin Finck 	CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
150*c2c66affSColin Finck 
151*c2c66affSColin Finck 	unsigned char wAttributes;
152*c2c66affSColin Finck 	unsigned char fg, bg;
153*c2c66affSColin Finck 	unsigned char defaultfg, defaultbg;
154*c2c66affSColin Finck 	unsigned char origfg, origbg;
155*c2c66affSColin Finck 
156*c2c66affSColin Finck 	bool blink;
157*c2c66affSColin Finck 	bool underline;
158*c2c66affSColin Finck 	bool reverse;
159*c2c66affSColin Finck 
160*c2c66affSColin Finck 	int iScrollStart;
161*c2c66affSColin Finck 	int iScrollEnd;
162*c2c66affSColin Finck 	int insert_mode;
163*c2c66affSColin Finck };
164*c2c66affSColin Finck 
165*c2c66affSColin Finck // Non-member functions for saving state -- used by the scrollback buffer viewer
166*c2c66affSColin Finck void saveScreen(CHAR_INFO* chiBuffer);
167*c2c66affSColin Finck void restoreScreen(CHAR_INFO* chiBuffer);
168*c2c66affSColin Finck CHAR_INFO* newBuffer();
169*c2c66affSColin Finck void deleteBuffer(CHAR_INFO* chiBuffer);
170