ReactOS 0.4.15-dev-7934-g1dc8d80
consup.c
Go to the documentation of this file.
1/*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: base/setup/usetup/consup.c
23 * PURPOSE: Console support functions
24 * PROGRAMMER:
25 */
26
27/* INCLUDES ******************************************************************/
28
29#include <usetup.h>
30
31#define NDEBUG
32#include <debug.h>
33
34/* GLOBALS ******************************************************************/
35
38
41
42/* FUNCTIONS *****************************************************************/
43
46{
48
49 /* Allocate a new console */
50 if (!AllocConsole())
51 return FALSE;
52
53 /* Get the standard handles */
56
57 /* Retrieve the size of the console */
59 {
61 return FALSE;
62 }
63 xScreen = csbi.dwSize.X;
64 yScreen = csbi.dwSize.Y;
65
66 return TRUE;
67}
68
69VOID
72{
73 DWORD Read;
74
75 while (TRUE)
76 {
77 /* Wait for a key press */
79
80 if ((Buffer->EventType == KEY_EVENT) &&
81 (Buffer->Event.KeyEvent.bKeyDown != FALSE))
82 {
83 break;
84 }
85 }
86}
87
91{
92 DWORD Read = 0;
93
94 while (TRUE)
95 {
96 /* Try to get a key press without blocking */
98 return FALSE;
99 if (Read == 0)
100 return FALSE;
101
102 /* Consume it */
104
105 if ((Buffer->EventType == KEY_EVENT) &&
106 (Buffer->Event.KeyEvent.bKeyDown != FALSE))
107 {
108 return TRUE;
109 }
110 }
111}
112
113VOID
115 IN CHAR c)
116{
117 DWORD Written;
118
120 &c,
121 1,
122 &Written,
123 NULL);
124}
125
126VOID
128 IN LPCSTR szText)
129{
130 DWORD Written;
131
133 szText,
134 (ULONG)strlen(szText),
135 &Written,
136 NULL);
138 "\n",
139 1,
140 &Written,
141 NULL);
142}
143
144VOID
146 IN LPCSTR szFormat,
148{
149 CHAR szOut[256];
150 DWORD dwWritten;
151
152 vsprintf(szOut, szFormat, args);
153
155 szOut,
156 (ULONG)strlen(szOut),
157 &dwWritten,
158 NULL);
159}
160
161VOID
164 IN LPCSTR szFormat,
165 ...)
166{
167 va_list arg_ptr;
168
169 va_start(arg_ptr, szFormat);
170 CONSOLE_ConOutPrintfV(szFormat, arg_ptr);
171 va_end(arg_ptr);
172}
173
174BOOL
176{
178}
179
180VOID
182 OUT PSHORT x,
183 OUT PSHORT y)
184{
186
188
189 *x = csbi.dwCursorPosition.X;
190 *y = csbi.dwCursorPosition.Y;
191}
192
193SHORT
195{
197
199
200 return csbi.dwCursorPosition.X;
201}
202
203SHORT
205{
207
209
210 return csbi.dwCursorPosition.Y;
211}
212
213VOID
216 IN BOOL bVisible)
217{
219
220 cci.dwSize = bInsert ? 10 : 99;
221 cci.bVisible = bVisible;
222
224}
225
226VOID
228 IN SHORT x,
229 IN SHORT y)
230{
231 COORD coPos;
232
233 coPos.X = x;
234 coPos.Y = y;
236}
237
238VOID
240{
241 COORD coPos;
242 DWORD Written;
243
244 coPos.X = 0;
245 coPos.Y = 0;
246
247 /*
248 * Hide everything under the same foreground & background colors, so that
249 * the actual color and text blanking reset does not create a visual "blinking".
250 * We do this because we cannot do the screen scrolling trick that would
251 * allow to change both the text and the colors at the same time (the
252 * function is currently not available in our console "emulation" layer).
253 */
257 coPos,
258 &Written);
259
260 /* Blank the text */
262 ' ',
264 coPos,
265 &Written);
266
267 /* Reset the actual foreground & background colors */
271 coPos,
272 &Written);
273}
274
275VOID
277 IN SHORT x,
278 IN SHORT y,
279 IN SHORT col,
280 IN SHORT row)
281{
282 COORD coPos;
283 DWORD Written;
284
285 for (coPos.Y = y; coPos.Y < y + row; coPos.Y++)
286 {
287 coPos.X = x;
288
291 col,
292 coPos,
293 &Written);
294 }
295}
296
297VOID
299 IN SHORT x,
300 IN SHORT y,
301 IN SHORT col,
302 IN SHORT row)
303{
304 COORD coPos;
305 DWORD Written;
306
307 for (coPos.Y = y; coPos.Y < y + row; coPos.Y++)
308 {
309 coPos.X = x;
310
313 col,
314 coPos,
315 &Written);
316 }
317}
318
319VOID
321 IN SHORT x,
322 IN SHORT y,
323 IN LPCSTR Text)
324{
325 COORD coPos;
326 DWORD Written;
327
328 coPos.X = x;
329 coPos.Y = y;
330
332 Text,
333 (ULONG)strlen(Text),
334 coPos,
335 &Written);
336}
337
338VOID
340 IN SHORT y,
342{
343 COORD coPos;
344 DWORD Written;
345
346 coPos.X = x;
347 coPos.Y = y;
348
350 ' ',
351 Length,
352 coPos,
353 &Written);
354}
355
356VOID
358 IN SHORT x,
359 IN SHORT y,
360 IN SHORT len,
362{
363 COORD coPos;
365 DWORD Written;
366
367 coPos.X = x;
368 coPos.Y = y;
369
371 if (Length > len - 1)
372 Length = len - 1;
373
376 len,
377 coPos,
378 &Written);
379
381 Text,
382 (ULONG)Length,
383 coPos,
384 &Written);
385
386 coPos.X += Length;
387 if (len > Length)
388 {
390 ' ',
391 len - Length,
392 coPos,
393 &Written);
394 }
395}
396
397VOID
399 IN SHORT x,
400 IN SHORT y,
401 IN LPCSTR Text)
402{
403 COORD coPos;
405 DWORD Written;
406
407 coPos.X = x;
408 coPos.Y = y;
409
411
413 Text,
414 Length,
415 coPos,
416 &Written);
417
418 coPos.Y++;
421 Length,
422 coPos,
423 &Written);
424}
425
426VOID
428 IN SHORT x,
429 IN LPCSTR fmt,
431{
432 INT nLength;
433 COORD coPos;
434 DWORD Written;
435 CHAR Buffer[128];
436
437 memset(Buffer, ' ', min(sizeof(Buffer), xScreen));
439 ASSERT(x + nLength < sizeof(Buffer));
440 Buffer[x + nLength] = ' ';
441
442 coPos.X = 0;
443 coPos.Y = yScreen - 1;
446 xScreen,
447 coPos,
448 &Written);
450 Buffer,
451 min(sizeof(Buffer), xScreen),
452 coPos,
453 &Written);
454}
455
456VOID
459 IN SHORT x,
460 IN LPCSTR fmt,
461 ...)
462{
463 va_list ap;
464
465 va_start(ap, fmt);
467 va_end(ap);
468}
469
470VOID
472 IN LPCSTR fmt,
474{
476}
477
478VOID
481 IN LPCSTR fmt,
482 ...)
483{
484 va_list ap;
485
486 va_start(ap, fmt);
488 va_end(ap);
489}
490
491static
492VOID
494 IN SHORT x,
496{
497 COORD coPos;
498 DWORD Written;
499
500 coPos.X = x;
501 coPos.Y = yScreen - 1;
502
504 ' ',
505 Length,
506 coPos,
507 &Written);
508}
509
510VOID
513 IN SHORT x,
514 IN LPCSTR fmt,
515 ...)
516{
517 CHAR Buffer[128];
519 va_list ap;
520
521 va_start(ap, fmt);
523 va_end(ap);
524
526
527 if (Length + x <= 79)
528 {
530 }
531 else
532 {
534 }
535}
536
537VOID
539 IN SHORT x,
540 IN SHORT y,
541 IN LPCSTR Text)
542{
543 COORD coPos;
545 DWORD Written;
546
547 coPos.X = x;
548 coPos.Y = y;
549
551
554 Length,
555 coPos,
556 &Written);
557
559 Text,
560 Length,
561 coPos,
562 &Written);
563}
564
565VOID
567 IN SHORT x,
568 IN SHORT y,
569 IN LPCSTR Text)
570{
571 COORD coPos;
573 DWORD Written;
574
575 coPos.X = x;
576 coPos.Y = y;
577
579
582 Length,
583 coPos,
584 &Written);
585
587 Text,
588 Length,
589 coPos,
590 &Written);
591}
592
593VOID
596 IN SHORT x,
597 IN SHORT y,
598 IN LPCSTR fmt,
599 ...)
600{
601 CHAR buffer[512];
602 va_list ap;
603 COORD coPos;
604 DWORD Written;
605
606 va_start(ap, fmt);
608 va_end(ap);
609
610 coPos.X = x;
611 coPos.Y = y;
612
614 buffer,
616 coPos,
617 &Written);
618}
619
620VOID
623 IN SHORT x,
624 IN SHORT y,
625 IN SHORT len,
626 IN LPCSTR fmt,
627 ...)
628{
629 CHAR buffer[512];
630 va_list ap;
631 COORD coPos;
633 DWORD Written;
634
635 va_start(ap, fmt);
637 va_end(ap);
638
639 coPos.X = x;
640 coPos.Y = y;
641
643 if (Length > len - 1)
644 Length = len - 1;
645
647 buffer,
648 Length,
649 coPos,
650 &Written);
651
652 coPos.X += Length;
653
654 if (len > Length)
655 {
657 ' ',
658 len - Length,
659 coPos,
660 &Written);
661 }
662}
663
664VOID
666 IN SHORT x,
667 IN SHORT y,
668 IN INT Flags,
669 IN LPCSTR Text)
670{
671 COORD coPos;
672
673 coPos.X = x;
674 coPos.Y = y;
675
677 {
678 coPos.X = x;
679 coPos.Y = yScreen - 1;
680 }
681 else /* TEXT_TYPE_REGULAR (Default) */
682 {
683 coPos.X = x;
684 coPos.Y = y;
685 }
686
688 {
689 coPos.X = (xScreen - (SHORT)strlen(Text)) / 2;
690 }
691 else if(Flags & TEXT_ALIGN_RIGHT)
692 {
693 coPos.X = coPos.X - (SHORT)strlen(Text);
694
696 {
697 coPos.X -= 1;
698 }
699 else if (Flags & TEXT_PADDING_MEDIUM)
700 {
701 coPos.X -= 2;
702 }
703 else if (Flags & TEXT_PADDING_BIG)
704 {
705 coPos.X -= 3;
706 }
707 }
708 else /* TEXT_ALIGN_LEFT (Default) */
709 {
711 {
712 coPos.X += 1;
713 }
714 else if (Flags & TEXT_PADDING_MEDIUM)
715 {
716 coPos.X += 2;
717 }
718 else if (Flags & TEXT_PADDING_BIG)
719 {
720 coPos.X += 3;
721 }
722 }
723
725 {
727 }
728 else /* TEXT_TYPE_REGULAR (Default) */
729 {
731 {
732 CONSOLE_SetHighlightedTextXY(coPos.X, coPos.Y, Text);
733 }
734 else if (Flags & TEXT_STYLE_UNDERLINE)
735 {
736 CONSOLE_SetUnderlinedTextXY(coPos.X, coPos.Y, Text);
737 }
738 else /* TEXT_STYLE_NORMAL (Default) */
739 {
740 CONSOLE_SetTextXY(coPos.X, coPos.Y, Text);
741 }
742 }
743}
744
745VOID
747 IN SHORT x,
748 IN SHORT y,
749 IN INT Flags,
751{
752 COORD coPos;
753
754 coPos.X = x;
755 coPos.Y = y;
756
758 {
759 coPos.X = x;
760 coPos.Y = yScreen - 1;
761 }
762 else /* TEXT_TYPE_REGULAR (Default) */
763 {
764 coPos.X = x;
765 coPos.Y = y;
766 }
767
769 {
770 coPos.X = (xScreen - Length) / 2;
771 }
772 else if(Flags & TEXT_ALIGN_RIGHT)
773 {
774 coPos.X = coPos.X - Length;
775
777 {
778 coPos.X -= 1;
779 }
780 else if (Flags & TEXT_PADDING_MEDIUM)
781 {
782 coPos.X -= 2;
783 }
784 else if (Flags & TEXT_PADDING_BIG)
785 {
786 coPos.X -= 3;
787 }
788 }
789 else /* TEXT_ALIGN_LEFT (Default) */
790 {
792 {
793 coPos.X += 1;
794 }
795 else if (Flags & TEXT_PADDING_MEDIUM)
796 {
797 coPos.X += 2;
798 }
799 else if (Flags & TEXT_PADDING_BIG)
800 {
801 coPos.X += 3;
802 }
803 }
804
806 {
808 }
809 else if (Flags & TEXT_STYLE_UNDERLINE)
810 {
811 CONSOLE_ClearTextXY(coPos.X, coPos.Y, Length);
812 CONSOLE_ClearTextXY(coPos.X, coPos.Y + 1, Length);
813 }
814 else /* TEXT_TYPE_REGULAR (Default) */
815 {
816 CONSOLE_ClearTextXY(coPos.X, coPos.Y, Length);
817 }
818}
819
820/* EOF */
unsigned char BOOLEAN
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define __cdecl
Definition: accygwin.h:79
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
BOOL WINAPI WriteConsoleOutputCharacterA(HANDLE hConsoleOutput, IN LPCSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: console.c:407
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:220
BOOL WINAPI FillConsoleOutputCharacterA(IN HANDLE hConsoleOutput, IN CHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: console.c:560
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:641
BOOL WINAPI WriteConsoleOutputCharacterW(HANDLE hConsoleOutput, IN LPCWSTR lpCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: console.c:451
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
BOOL WINAPI FreeConsole(VOID)
Definition: console.c:156
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:618
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:525
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
#define FOREGROUND_INTENSITY
Definition: blue.h:64
#define BACKGROUND_BLUE
Definition: blue.h:65
#define FOREGROUND_BLUE
Definition: blue.h:61
Definition: bufpool.h:45
static BOOL bInsert
Definition: cmdinput.c:121
char * Text
Definition: combotst.c:136
VOID __cdecl CONSOLE_ConOutPrintf(IN LPCSTR szFormat,...)
Definition: consup.c:163
BOOL CONSOLE_Flush(VOID)
Definition: consup.c:175
VOID __cdecl CONSOLE_PrintTextXYN(IN SHORT x, IN SHORT y, IN SHORT len, IN LPCSTR fmt,...)
Definition: consup.c:622
VOID CONSOLE_SetInputTextXY(IN SHORT x, IN SHORT y, IN SHORT len, IN LPCWSTR Text)
Definition: consup.c:357
SHORT CONSOLE_GetCursorY(VOID)
Definition: consup.c:204
VOID CONSOLE_InvertTextXY(IN SHORT x, IN SHORT y, IN SHORT col, IN SHORT row)
Definition: consup.c:276
VOID CONSOLE_SetCursorXY(IN SHORT x, IN SHORT y)
Definition: consup.c:227
VOID CONSOLE_SetInvertedTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:538
VOID CONSOLE_NormalTextXY(IN SHORT x, IN SHORT y, IN SHORT col, IN SHORT row)
Definition: consup.c:298
VOID CONSOLE_GetCursorXY(OUT PSHORT x, OUT PSHORT y)
Definition: consup.c:181
VOID CONSOLE_SetStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN LPCSTR Text)
Definition: consup.c:665
VOID __cdecl CONSOLE_SetStatusTextX(IN SHORT x, IN LPCSTR fmt,...)
Definition: consup.c:458
SHORT yScreen
Definition: consup.c:40
VOID __cdecl CONSOLE_SetStatusText(IN LPCSTR fmt,...)
Definition: consup.c:480
VOID CONSOLE_SetTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:320
SHORT xScreen
Definition: consup.c:39
VOID CONSOLE_ConInKey(OUT PINPUT_RECORD Buffer)
Definition: consup.c:70
VOID __cdecl CONSOLE_SetStatusTextAutoFitX(IN SHORT x, IN LPCSTR fmt,...)
Definition: consup.c:512
VOID __cdecl CONSOLE_PrintTextXY(IN SHORT x, IN SHORT y, IN LPCSTR fmt,...)
Definition: consup.c:595
SHORT CONSOLE_GetCursorX(VOID)
Definition: consup.c:194
VOID CONSOLE_ClearStyledText(IN SHORT x, IN SHORT y, IN INT Flags, IN SHORT Length)
Definition: consup.c:746
VOID CONSOLE_SetHighlightedTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:566
VOID CONSOLE_ClearScreen(VOID)
Definition: consup.c:239
BOOLEAN CONSOLE_Init(VOID)
Definition: consup.c:45
VOID CONSOLE_SetStatusTextV(IN LPCSTR fmt, IN va_list args)
Definition: consup.c:471
BOOLEAN CONSOLE_ConInKeyPeek(OUT PINPUT_RECORD Buffer)
Definition: consup.c:89
VOID CONSOLE_SetCursorType(IN BOOL bInsert, IN BOOL bVisible)
Definition: consup.c:214
HANDLE StdOutput
Definition: consup.c:37
VOID CONSOLE_SetStatusTextXV(IN SHORT x, IN LPCSTR fmt, IN va_list args)
Definition: consup.c:427
VOID CONSOLE_ConOutPuts(IN LPCSTR szText)
Definition: consup.c:127
VOID CONSOLE_ConOutPrintfV(IN LPCSTR szFormat, IN va_list args)
Definition: consup.c:145
static VOID CONSOLE_ClearStatusTextX(IN SHORT x, IN SHORT Length)
Definition: consup.c:493
VOID CONSOLE_SetUnderlinedTextXY(IN SHORT x, IN SHORT y, IN LPCSTR Text)
Definition: consup.c:398
HANDLE StdInput
Definition: consup.c:36
VOID CONSOLE_ConOutChar(IN CHAR c)
Definition: consup.c:114
VOID CONSOLE_ClearTextXY(IN SHORT x, IN SHORT y, IN SHORT Length)
Definition: consup.c:339
#define FOREGROUND_WHITE
Definition: consup.h:29
#define TEXT_PADDING_SMALL
Definition: consup.h:49
#define TEXT_STYLE_HIGHLIGHT
Definition: consup.h:35
#define TEXT_TYPE_STATUS
Definition: consup.h:40
#define TEXT_PADDING_BIG
Definition: consup.h:51
#define TEXT_ALIGN_CENTER
Definition: consup.h:46
#define TEXT_PADDING_MEDIUM
Definition: consup.h:50
#define BACKGROUND_WHITE
Definition: consup.h:31
#define TEXT_ALIGN_RIGHT
Definition: consup.h:44
#define TEXT_STYLE_UNDERLINE
Definition: consup.h:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLenum GLsizei len
Definition: glext.h:6722
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
short SHORT
Definition: pedump.c:59
#define memset(x, y, z)
Definition: compat.h:39
_In_ BOOLEAN Read
Definition: strmini.h:479
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
Definition: match.c:390
Definition: dsound.c:943
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26
int16_t * PSHORT
Definition: typedefs.h:55
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
CHAR CharDoubleHorizontalLine
Definition: mui.c:47
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define ReadConsoleInput
Definition: wincon.h:778
#define KEY_EVENT
Definition: wincon.h:128
_In_ DWORD nLength
Definition: wincon.h:473
#define PeekConsoleInput
Definition: wincon.h:776
#define WriteConsole
Definition: wincon.h:784
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
char CHAR
Definition: xmlstorage.h:175