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
9 /* FIXME: Temporary HACK before we cleanly support UNICODE functions */
15 // #include <winnls.h>
16 #include <wincon.h> // Console APIs (only if kernel32 support included)
24 #define CON_STREAM_WRITE ConStreamWrite
30 ConClearLine(IN PCON_STREAM Stream
)
32 HANDLE hOutput
= ConStreamGetOSHandle(Stream
);
35 * Erase the full line where the cursor is, and move
36 * the cursor back to the beginning of the line.
39 if (IsConsoleHandle(hOutput
))
41 CONSOLE_SCREEN_BUFFER_INFO csbi
;
44 GetConsoleScreenBufferInfo(hOutput
, &csbi
);
46 csbi
.dwCursorPosition
.X
= 0;
47 // csbi.dwCursorPosition.Y;
49 FillConsoleOutputCharacterW(hOutput
, L
' ',
51 csbi
.dwCursorPosition
,
53 SetConsoleCursorPosition(hOutput
, csbi
.dwCursorPosition
);
55 else if (IsTTYHandle(hOutput
))
57 ConPuts(Stream
, L
"\x1B[2K\x1B[1G"); // FIXME: Just use WriteFile
59 // else, do nothing for files
67 IN PCON_SCREEN Screen
,
68 OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi
)
73 /* Parameters validation */
74 if (!Screen
|| !pcsbi
)
77 hOutput
= ConStreamGetOSHandle(Screen
->Stream
);
79 /* Screen handle must be of TTY type (console or TTY) */
80 if (!IsTTYHandle(hOutput
))
83 /* Update cached screen information */
84 if (IsConsoleHandle(hOutput
))
86 Success
= GetConsoleScreenBufferInfo(hOutput
, &Screen
->csbi
);
91 /* TODO: Do something adequate for TTYs */
92 // FIXME: At the moment we return hardcoded info.
93 Screen
->csbi
.dwSize
.X
= 80;
94 Screen
->csbi
.dwSize
.Y
= 25;
96 // Screen->csbi.dwCursorPosition;
97 // Screen->csbi.wAttributes;
98 // Screen->csbi.srWindow;
99 Screen
->csbi
.dwMaximumWindowSize
= Screen
->csbi
.dwSize
;
101 hOutput
= CreateFileW(L
"CONOUT$", GENERIC_READ
|GENERIC_WRITE
,
102 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
103 OPEN_EXISTING
, 0, NULL
);
105 Success
= IsConsoleHandle(hOutput
) &&
106 GetConsoleScreenBufferInfo(hOutput
, &Screen
->csbi
);
108 CloseHandle(hOutput
);
114 /* Return it to the caller */
115 *pcsbi
= Screen
->csbi
;
121 // For real consoles, erase everything, otherwise (TTY) erase just the "screen".
122 // FIXME: Or we can add a BOOL flag?
124 ConClearScreen(IN PCON_SCREEN Screen
)
128 /* Parameters validation */
132 /* Get the size of the visual screen */
133 if (!ConGetScreenInfo(Screen
, &csbi
))
135 /* We assume it's a file handle */
140 hOutput
= ConStreamGetOSHandle(Screen
->Stream
);
142 if (IsConsoleHandle(hOutput
))
144 CONSOLE_SCREEN_BUFFER_INFO csbi
;
148 GetConsoleScreenBufferInfo(hOutput
, &csbi
);
152 FillConsoleOutputAttribute(hOutput
, csbi
.wAttributes
,
153 csbi
.dwSize
.X
* csbi
.dwSize
.Y
,
155 FillConsoleOutputCharacterW(hOutput
, L
' ',
156 csbi
.dwSize
.X
* csbi
.dwSize
.Y
,
158 SetConsoleCursorPosition(hOutput
, coPos
);
160 else if (IsTTYHandle(hOutput
))
162 /* Clear the full screen and move the cursor to (0,0) */
163 ConPuts(Screen
->Stream
, L
"\x1B[2J\x1B[1;1H");
167 /* Issue a Form-Feed control */
169 CON_STREAM_WRITE(Screen
->Stream
, &ch
, 1);