3 * Copyright (C) 2002 ReactOS Team
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.
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.
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.
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
27 /* INCLUDES ******************************************************************/
34 /* GLOBALS ******************************************************************/
36 HANDLE StdInput
= NULL
;
37 HANDLE StdOutput
= NULL
;
42 /* FUNCTIONS *****************************************************************/
47 CONSOLE_SCREEN_BUFFER_INFO csbi
;
49 /* Allocate a new console */
53 /* Get the standard handles */
54 StdInput
= GetStdHandle(STD_INPUT_HANDLE
);
55 StdOutput
= GetStdHandle(STD_OUTPUT_HANDLE
);
57 /* Retrieve the size of the console */
58 if (!GetConsoleScreenBufferInfo(StdOutput
, &csbi
))
63 xScreen
= csbi
.dwSize
.X
;
64 yScreen
= csbi
.dwSize
.Y
;
71 OUT PINPUT_RECORD Buffer
)
77 /* Wait for a key press */
78 ReadConsoleInput(StdInput
, Buffer
, 1, &Read
);
80 if ((Buffer
->EventType
== KEY_EVENT
) &&
81 (Buffer
->Event
.KeyEvent
.bKeyDown
!= FALSE
))
90 OUT PINPUT_RECORD Buffer
)
96 /* Try to get a key press without blocking */
97 if (!PeekConsoleInput(StdInput
, Buffer
, 1, &Read
))
103 ReadConsoleInput(StdInput
, Buffer
, 1, &Read
);
105 if ((Buffer
->EventType
== KEY_EVENT
) &&
106 (Buffer
->Event
.KeyEvent
.bKeyDown
!= FALSE
))
119 WriteConsole(StdOutput
,
132 WriteConsole(StdOutput
,
134 (ULONG
)strlen(szText
),
137 WriteConsole(StdOutput
,
145 CONSOLE_ConOutPrintfV(
152 vsprintf(szOut
, szFormat
, args
);
154 WriteConsole(StdOutput
,
156 (ULONG
)strlen(szOut
),
163 CONSOLE_ConOutPrintf(
169 va_start(arg_ptr
, szFormat
);
170 CONSOLE_ConOutPrintfV(szFormat
, arg_ptr
);
177 return FlushConsoleInputBuffer(StdInput
);
185 CONSOLE_SCREEN_BUFFER_INFO csbi
;
187 GetConsoleScreenBufferInfo(StdOutput
, &csbi
);
189 *x
= csbi
.dwCursorPosition
.X
;
190 *y
= csbi
.dwCursorPosition
.Y
;
194 CONSOLE_GetCursorX(VOID
)
196 CONSOLE_SCREEN_BUFFER_INFO csbi
;
198 GetConsoleScreenBufferInfo(StdOutput
, &csbi
);
200 return csbi
.dwCursorPosition
.X
;
204 CONSOLE_GetCursorY(VOID
)
206 CONSOLE_SCREEN_BUFFER_INFO csbi
;
208 GetConsoleScreenBufferInfo(StdOutput
, &csbi
);
210 return csbi
.dwCursorPosition
.Y
;
214 CONSOLE_SetCursorType(
218 CONSOLE_CURSOR_INFO cci
;
220 cci
.dwSize
= bInsert
? 10 : 99;
221 cci
.bVisible
= bVisible
;
223 SetConsoleCursorInfo(StdOutput
, &cci
);
235 SetConsoleCursorPosition(StdOutput
, coPos
);
239 CONSOLE_ClearScreen(VOID
)
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).
254 FillConsoleOutputAttribute(StdOutput
,
255 FOREGROUND_BLUE
| BACKGROUND_BLUE
,
261 FillConsoleOutputCharacterA(StdOutput
,
267 /* Reset the actual foreground & background colors */
268 FillConsoleOutputAttribute(StdOutput
,
269 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
276 CONSOLE_InvertTextXY(
285 for (coPos
.Y
= y
; coPos
.Y
< y
+ row
; coPos
.Y
++)
289 FillConsoleOutputAttribute(StdOutput
,
290 FOREGROUND_BLUE
| BACKGROUND_WHITE
,
298 CONSOLE_NormalTextXY(
307 for (coPos
.Y
= y
; coPos
.Y
< y
+ row
; coPos
.Y
++)
311 FillConsoleOutputAttribute(StdOutput
,
312 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
331 WriteConsoleOutputCharacterA(StdOutput
,
339 CONSOLE_ClearTextXY(IN SHORT x
,
349 FillConsoleOutputCharacterA(StdOutput
,
357 CONSOLE_SetInputTextXY(
370 Length
= (SHORT
)wcslen(Text
);
371 if (Length
> len
- 1)
374 FillConsoleOutputAttribute(StdOutput
,
380 WriteConsoleOutputCharacterW(StdOutput
,
389 FillConsoleOutputCharacterA(StdOutput
,
398 CONSOLE_SetUnderlinedTextXY(
410 Length
= (ULONG
)strlen(Text
);
412 WriteConsoleOutputCharacterA(StdOutput
,
419 FillConsoleOutputCharacterA(StdOutput
,
420 CharDoubleHorizontalLine
,
427 CONSOLE_SetStatusTextXV(
437 memset(Buffer
, ' ', min(sizeof(Buffer
), xScreen
));
438 nLength
= vsprintf(&Buffer
[x
], fmt
, args
);
439 ASSERT(x
+ nLength
< sizeof(Buffer
));
440 Buffer
[x
+ nLength
] = ' ';
443 coPos
.Y
= yScreen
- 1;
444 FillConsoleOutputAttribute(StdOutput
,
449 WriteConsoleOutputCharacterA(StdOutput
,
451 min(sizeof(Buffer
), xScreen
),
458 CONSOLE_SetStatusTextX(
466 CONSOLE_SetStatusTextXV(x
, fmt
, ap
);
471 CONSOLE_SetStatusTextV(
475 CONSOLE_SetStatusTextXV(0, fmt
, args
);
480 CONSOLE_SetStatusText(
487 CONSOLE_SetStatusTextV(fmt
, ap
);
493 CONSOLE_ClearStatusTextX(
501 coPos
.Y
= yScreen
- 1;
503 FillConsoleOutputCharacterA(StdOutput
,
512 CONSOLE_SetStatusTextAutoFitX(
522 vsprintf(Buffer
, fmt
, ap
);
525 Length
= (ULONG
)strlen(Buffer
);
527 if (Length
+ x
<= 79)
529 CONSOLE_SetStatusTextX(x
, Buffer
);
533 CONSOLE_SetStatusTextX(79 - Length
, Buffer
);
538 CONSOLE_SetInvertedTextXY(
550 Length
= (ULONG
)strlen(Text
);
552 FillConsoleOutputAttribute(StdOutput
,
553 FOREGROUND_BLUE
| BACKGROUND_WHITE
,
558 WriteConsoleOutputCharacterA(StdOutput
,
566 CONSOLE_SetHighlightedTextXY(
578 Length
= (ULONG
)strlen(Text
);
580 FillConsoleOutputAttribute(StdOutput
,
581 FOREGROUND_WHITE
| FOREGROUND_INTENSITY
| BACKGROUND_BLUE
,
586 WriteConsoleOutputCharacterA(StdOutput
,
607 vsprintf(buffer
, fmt
, ap
);
613 WriteConsoleOutputCharacterA(StdOutput
,
615 (ULONG
)strlen(buffer
),
622 CONSOLE_PrintTextXYN(
636 vsprintf(buffer
, fmt
, ap
);
642 Length
= (SHORT
)strlen(buffer
);
643 if (Length
> len
- 1)
646 WriteConsoleOutputCharacterA(StdOutput
,
656 FillConsoleOutputCharacterA(StdOutput
,
665 CONSOLE_SetStyledText(
676 if (Flags
& TEXT_TYPE_STATUS
)
679 coPos
.Y
= yScreen
- 1;
681 else /* TEXT_TYPE_REGULAR (Default) */
687 if (Flags
& TEXT_ALIGN_CENTER
)
689 coPos
.X
= (xScreen
- (SHORT
)strlen(Text
)) / 2;
691 else if(Flags
& TEXT_ALIGN_RIGHT
)
693 coPos
.X
= coPos
.X
- (SHORT
)strlen(Text
);
695 if (Flags
& TEXT_PADDING_SMALL
)
699 else if (Flags
& TEXT_PADDING_MEDIUM
)
703 else if (Flags
& TEXT_PADDING_BIG
)
708 else /* TEXT_ALIGN_LEFT (Default) */
710 if (Flags
& TEXT_PADDING_SMALL
)
714 else if (Flags
& TEXT_PADDING_MEDIUM
)
718 else if (Flags
& TEXT_PADDING_BIG
)
724 if (Flags
& TEXT_TYPE_STATUS
)
726 CONSOLE_SetStatusTextX(coPos
.X
, Text
);
728 else /* TEXT_TYPE_REGULAR (Default) */
730 if (Flags
& TEXT_STYLE_HIGHLIGHT
)
732 CONSOLE_SetHighlightedTextXY(coPos
.X
, coPos
.Y
, Text
);
734 else if (Flags
& TEXT_STYLE_UNDERLINE
)
736 CONSOLE_SetUnderlinedTextXY(coPos
.X
, coPos
.Y
, Text
);
738 else /* TEXT_STYLE_NORMAL (Default) */
740 CONSOLE_SetTextXY(coPos
.X
, coPos
.Y
, Text
);
746 CONSOLE_ClearStyledText(
757 if (Flags
& TEXT_TYPE_STATUS
)
760 coPos
.Y
= yScreen
- 1;
762 else /* TEXT_TYPE_REGULAR (Default) */
768 if (Flags
& TEXT_ALIGN_CENTER
)
770 coPos
.X
= (xScreen
- Length
) / 2;
772 else if(Flags
& TEXT_ALIGN_RIGHT
)
774 coPos
.X
= coPos
.X
- Length
;
776 if (Flags
& TEXT_PADDING_SMALL
)
780 else if (Flags
& TEXT_PADDING_MEDIUM
)
784 else if (Flags
& TEXT_PADDING_BIG
)
789 else /* TEXT_ALIGN_LEFT (Default) */
791 if (Flags
& TEXT_PADDING_SMALL
)
795 else if (Flags
& TEXT_PADDING_MEDIUM
)
799 else if (Flags
& TEXT_PADDING_BIG
)
805 if (Flags
& TEXT_TYPE_STATUS
)
807 CONSOLE_ClearStatusTextX(coPos
.X
, Length
);
809 else if (Flags
& TEXT_STYLE_UNDERLINE
)
811 CONSOLE_ClearTextXY(coPos
.X
, coPos
.Y
, Length
);
812 CONSOLE_ClearTextXY(coPos
.X
, coPos
.Y
+ 1, Length
);
814 else /* TEXT_TYPE_REGULAR (Default) */
816 CONSOLE_ClearTextXY(coPos
.X
, coPos
.Y
, Length
);