2 * PROJECT: ReactOS Console Utilities Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Console/terminal screen management.
5 * COPYRIGHT: Copyright 2017-2018 ReactOS Team
6 * Copyright 2017-2018 Hermes Belusca-Maito
13 * @brief Console/terminal screen management.
16 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */
22 // #include <winnls.h>
23 #include <wincon.h> // Console APIs (only if kernel32 support included)
31 #define CON_STREAM_WRITE ConStreamWrite
37 ConClearLine(IN PCON_STREAM Stream
)
39 HANDLE hOutput
= ConStreamGetOSHandle(Stream
);
42 * Erase the full line where the cursor is, and move
43 * the cursor back to the beginning of the line.
46 if (IsConsoleHandle(hOutput
))
48 CONSOLE_SCREEN_BUFFER_INFO csbi
;
51 GetConsoleScreenBufferInfo(hOutput
, &csbi
);
53 csbi
.dwCursorPosition
.X
= 0;
54 // csbi.dwCursorPosition.Y;
56 FillConsoleOutputCharacterW(hOutput
, L
' ',
58 csbi
.dwCursorPosition
,
60 SetConsoleCursorPosition(hOutput
, csbi
.dwCursorPosition
);
62 else if (IsTTYHandle(hOutput
))
64 ConPuts(Stream
, L
"\x1B[2K\x1B[1G"); // FIXME: Just use WriteFile
66 // else, do nothing for files
74 IN PCON_SCREEN Screen
,
75 OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi
)
80 /* Parameters validation */
81 if (!Screen
|| !pcsbi
)
84 hOutput
= ConStreamGetOSHandle(Screen
->Stream
);
86 /* Screen handle must be of TTY type (console or TTY) */
87 if (!IsTTYHandle(hOutput
))
90 /* Update cached screen information */
91 if (IsConsoleHandle(hOutput
))
93 Success
= GetConsoleScreenBufferInfo(hOutput
, &Screen
->csbi
);
98 /* TODO: Do something adequate for TTYs */
99 // FIXME: At the moment we return hardcoded info.
100 Screen
->csbi
.dwSize
.X
= 80;
101 Screen
->csbi
.dwSize
.Y
= 25;
103 // Screen->csbi.dwCursorPosition;
104 // Screen->csbi.wAttributes;
105 // Screen->csbi.srWindow;
106 Screen
->csbi
.dwMaximumWindowSize
= Screen
->csbi
.dwSize
;
108 hOutput
= CreateFileW(L
"CONOUT$", GENERIC_READ
|GENERIC_WRITE
,
109 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
110 OPEN_EXISTING
, 0, NULL
);
112 Success
= IsConsoleHandle(hOutput
) &&
113 GetConsoleScreenBufferInfo(hOutput
, &Screen
->csbi
);
115 CloseHandle(hOutput
);
121 /* Return it to the caller */
122 *pcsbi
= Screen
->csbi
;
128 // For real consoles, erase everything, otherwise (TTY) erase just the "screen".
129 // FIXME: Or we can add a BOOL flag?
131 ConClearScreen(IN PCON_SCREEN Screen
)
135 /* Parameters validation */
139 /* Get the size of the visual screen */
140 if (!ConGetScreenInfo(Screen
, &csbi
))
142 /* We assume it's a file handle */
147 hOutput
= ConStreamGetOSHandle(Screen
->Stream
);
149 if (IsConsoleHandle(hOutput
))
151 CONSOLE_SCREEN_BUFFER_INFO csbi
;
155 GetConsoleScreenBufferInfo(hOutput
, &csbi
);
159 FillConsoleOutputAttribute(hOutput
, csbi
.wAttributes
,
160 csbi
.dwSize
.X
* csbi
.dwSize
.Y
,
162 FillConsoleOutputCharacterW(hOutput
, L
' ',
163 csbi
.dwSize
.X
* csbi
.dwSize
.Y
,
165 SetConsoleCursorPosition(hOutput
, coPos
);
167 else if (IsTTYHandle(hOutput
))
169 /* Clear the full screen and move the cursor to (0,0) */
170 ConPuts(Screen
->Stream
, L
"\x1B[2J\x1B[1;1H");
174 /* Issue a Form-Feed control */
176 CON_STREAM_WRITE(Screen
->Stream
, &ch
, 1);