-
Notifications
You must be signed in to change notification settings - Fork 0
/
conio2.h
359 lines (319 loc) · 9.77 KB
/
conio2.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/** @file conio2.h
* A conio implementation for Mingw/Dev-C++.
*
* Written by:
* Hongli Lai <hongli@telekabel.nl>
* tkorrovi <tkorrovi@altavista.net> on 2002/02/26.
* Andrew Westcott <ajwestco@users.sourceforge.net>
* Michal Molhanec <michal@molhanec.net>
*
* Offered for use in the public domain without any warranty.
*/
#ifndef _CONIO2_H_
#define _CONIO2_H_
#include <conio.h>
#ifdef UNICODE
#include <windows.h> // we need wchar_t
#endif
#ifdef __cplusplus
extern "C"
{
#endif
/**
* Colors which you can use in your application.
*/
typedef enum
{
BLACK, /**< black color */
BLUE, /**< blue color */
GREEN, /**< green color */
CYAN, /**< cyan color */
RED, /**< red color */
MAGENTA, /**< magenta color */
BROWN, /**< brown color */
LIGHTGRAY, /**< light gray color */
DARKGRAY, /**< dark gray color */
LIGHTBLUE, /**< light blue color */
LIGHTGREEN, /**< light green color */
LIGHTCYAN, /**< light cyan color */
LIGHTRED, /**< light red color */
LIGHTMAGENTA, /**< light magenta color */
YELLOW, /**< yellow color */
WHITE /**< white color */
} COLORS;
/*@{*/
/**
* This defines enables you to use all MinGW conio.h functions without
* underscore.
*/
#define cgets _cgets
#define cprintf _cprintf
#define cputs _cputs
#define cscanf _cscanf
#ifdef UNICODE
#define cgetws _cgetws
#define getwch _getwch
#define getwche _getwche
#define putwch _putwch
#define ungetwch _ungetwch
#define cputws _cputws
#define cwprintf _cwprintf
#define cwscanf _cwscanf
#endif
/*@}*/
/**
* Define alias for _conio_gettext.
* If you want to use gettext function from some other library
* (e.g. GNU gettext) you have to define _CONIO_NO_GETTEXT_ so you won't get
* name conflict.
*/
#ifndef _CONIO_NO_GETTEXT_
#define gettext _conio_gettext
#endif
#define ScreenClear clrscr
/**
* @anchor cursortypes
* @name Cursor types
* Predefined cursor types. */
/*@{*/
#define _NOCURSOR 0 /**< no cursor */
#define _SOLIDCURSOR 100 /**< cursor filling whole cell */
#define _NORMALCURSOR 20 /**< cursor filling 20 percent of cell height */
/*@}*/
/**
* Structure holding information about screen.
* @see gettextinfo
* @see inittextinfo
*/
struct text_info
{
unsigned char curx; /**< cursor coordinate x */
unsigned char cury; /**< cursor coordinate y */
unsigned short attribute; /**< current text attribute */
unsigned short normattr; /**< original value of text attribute after
start of the application. If you don't
called the <TT>inittextinfo</TT> on the
beginning of the application, this always
will be black background and light gray
foreground */
unsigned char screenwidth; /**< screen width */
unsigned char screenheight; /**< screen height */
};
/**
* Structure used by gettext/puttext.
* @see _conio_gettext
* @see puttext
*/
struct char_info
{
#ifdef UNICODE
wchar_t letter; /**< character value */
#else
char letter; /**< character value */
#endif
unsigned short attr; /**< attribute value */
};
/**
* Returns information of the screen.
* @see text_info
*/
void gettextinfo(struct text_info *info);
/**
* Call this if you need real value of normattr attribute in the text_info
* structure.
* @see text_info
*/
void inittextinfo(void);
/**
* Clears rest of the line from cursor position to the end of line without
* moving the cursor.
*/
void clreol(void);
/**
* Clears whole screen.
*/
void clrscr(void);
/**
* Delete the current line (line on which is cursor) and then moves all lines
* below one line up. Lines below the line are moved one line up.
*/
void delline(void);
/**
* Insert blank line at the cursor position.
* Original content of the line and content of lines below moves one line down.
* The last line is deleted.
*/
void insline(void);
/**
* Gets text from the screen. If you haven't defined <TT>_CONIO_NO_GETTEXT_</TT>
* prior to including <TT>conio2.h</TT> you can use this function also under
* the <TT>gettext</TT> name.
* @see char_info
* @see puttext
* @param left Left coordinate of the rectangle, inclusive, starting from 1.
* @param top Top coordinate of the rectangle, inclusive, starting from 1.
* @param right Right coordinate of the rectangle, inclusive, starting from 1.
* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.
* @param buf You have to pass buffer of size
* <TT>(right - left + 1) * (bottom - top + 1) * sizeof(char_info)</TT>.
*/
void _conio_gettext(int left, int top, int right, int bottom,
struct char_info *buf);
/**
* Puts text back to the screen.
* @see char_info
* @see _conio_gettext
* @param left Left coordinate of the rectangle, inclusive, starting from 1.
* @param top Top coordinate of the rectangle, inclusive, starting from 1.
* @param right Right coordinate of the rectangle, inclusive, starting from 1.
* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.
* @param buf You have to pass buffer of size
* <TT>(right - left + 1) * (bottom - top + 1) * sizeof(char_info)</TT>.
*/
void puttext(int left, int top, int right, int bottom, struct char_info *buf);
/**
* Copies text.
* @param left Left coordinate of the rectangle, inclusive, starting from 1.
* @param top Top coordinate of the rectangle, inclusive, starting from 1.
* @param right Right coordinate of the rectangle, inclusive, starting from 1.
* @param bottom Bottom coordinate of the rectangle, inclusive, starting from 1.
* @param destleft Left coordinate of the destination rectangle.
* @param desttop Top coordinate of the destination rectangle.
*/
void movetext(int left, int top, int right, int bottom, int destleft,
int desttop);
/**
* Moves cursor to the specified position.
* @param x horizontal position
* @param y vertical position
*/
void gotoxy(int x, int y);
/**
* Puts string at the specified position.
* @param x horizontal position
* @param y vertical position
* @param str string
*/
void cputsxy(int x, int y, char *str);
/**
* Puts char at the specified position.
* @param x horizontal position
* @param y vertical position
* @param ch char
*/
void putchxy(int x, int y, char ch);
/**
* Sets the cursor type.
* @see @ref cursortypes
* @param type cursor type, under Win32 it is height of the cursor in percents
*/
void _setcursortype(int type);
/**
* Sets attribute of text.
* @param _attr new text attribute
*/
void textattr(int _attr);
/**
* Sets text attribute back to value it had after program start.
* It uses text_info's normattr value.
* @see text_info
*/
void normvideo(void);
/**
* Sets text background color.
* @see COLORS
* @param color new background color
*/
void textbackground(int color);
/**
* Sets text foreground color.
* @see COLORS
* @param color new foreground color
*/
void textcolor(int color);
/**
* Reads the cursor X position.
* @returns cursor X position
*/
int wherex(void);
/**
* Reads the cursor Y position.
* @returns cursor Y position
*/
int wherey(void);
/**
* Reads password. This function behaves like cgets.
*
* @see cgets
* @param prompt prompt which will be displayed to user
* @param str string for the password. <TT>str[0]</TT> have to contain
* length of the <TT>str</TT> - 3
* @returns <TT>&str[2]</TT>, the password will be stored in <TT>str</TT>
* beginning at <TT>str[2]</TT>, in <TT>str[1]</TT> will be length of the
* string without <TT>\\0</TT>, at <TT>str[2 + str[1]]</TT> will be \\0.
*/
char *getpass(const char *prompt, char *str);
/**
* Makes foreground colors light.
* If the current foreground color is less than <TT>DARKGRAY</TT> adds
* 8 to the its value making dark colors light.
* @see COLORS
* @see lowvideo
*/
void highvideo(void);
/**
* Makes foreground colors dark.
* If the current foreground color is higher than <TT>LIGHTGRAY</TT> substracts
* 8 from its value making light colors dark.
* @see COLORS
* @see highvideo
*/
void lowvideo(void);
/*@{*/
/*
* You may need to link with libmsvcr70.a or libmsvcr70d.a or libmsvcr71.a
* or libmsvcr71d.a if you want any of these functions.
*/
#ifdef UNICODE
_CRTIMP wchar_t *__cdecl _cgetws(wchar_t *);
_CRTIMP unsigned short __cdecl _getwch(void);
_CRTIMP unsigned short __cdecl _getwche(void);
_CRTIMP unsigned short __cdecl _putwch(wchar_t);
_CRTIMP unsigned short __cdecl _ungetwch(unsigned short);
_CRTIMP int __cdecl _cputws(const wchar_t *);
_CRTIMP int __cdecl _cwprintf(const wchar_t *, ...);
_CRTIMP int __cdecl _cwscanf(const wchar_t *, ...);
#endif
/*@}*/
/**
* Pauses program execution for a given time.
* @see switchbackground
* @param ms miliseconds
*/
void delay(int ms);
/**
* Replaces background color in the whole window. The text however
* is left intact. Does not modify textbackground().
* @see flashbackground
* @param color background color
*/
void switchbackground(int color);
/**
* Changes background color for a given time and then it restores it back.
* You can use it for visual bell. Does not modify textbackground().
* @see switchbackground
* @see delay
* @param color background color
* @param ms miliseconds
*/
void flashbackground(int color, int ms);
/**
* Clears the keyboard buffer.
* To see it in effect run <TT>conio_test</TT> and try to press a key during
* the 'Flashing...' phase.
*/
void clearkeybuf(void);
#ifdef __cplusplus
}
#endif
#endif /* _CONIO2_H_ */