ReactOS 0.4.16-dev-257-g6aa11ac
screen.c File Reference

Console/terminal screen management. More...

#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <strsafe.h>
#include "conutils.h"
#include "stream.h"
#include "screen.h"
Include dependency graph for screen.c:

Go to the source code of this file.

Macros

#define UNICODE
 
#define _UNICODE
 
#define CON_STREAM_WRITE   ConStreamWrite
 

Functions

BOOL ConGetScreenInfo (IN PCON_SCREEN Screen, OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
 
VOID ConClearScreen (IN PCON_SCREEN Screen)
 

Detailed Description

Console/terminal screen management.

Definition in file screen.c.

Macro Definition Documentation

◆ _UNICODE

#define _UNICODE

Definition at line 18 of file screen.c.

◆ CON_STREAM_WRITE

#define CON_STREAM_WRITE   ConStreamWrite

Definition at line 31 of file screen.c.

◆ UNICODE

Definition at line 17 of file screen.c.

Function Documentation

◆ ConClearScreen()

VOID ConClearScreen ( IN PCON_SCREEN  Screen)

Definition at line 131 of file screen.c.

132{
133 HANDLE hOutput;
134
135 /* Parameters validation */
136 if (!Screen) return;
137
138#if 0
139 /* Get the size of the visual screen */
140 if (!ConGetScreenInfo(Screen, &csbi))
141 {
142 /* We assume it's a file handle */
143 return;
144 }
145#endif
146
147 hOutput = ConStreamGetOSHandle(Screen->Stream);
148
149 if (IsConsoleHandle(hOutput))
150 {
152 COORD coPos;
153 DWORD dwWritten;
154
155 GetConsoleScreenBufferInfo(hOutput, &csbi);
156
157 coPos.X = 0;
158 coPos.Y = 0;
160 csbi.dwSize.X * csbi.dwSize.Y,
161 coPos, &dwWritten);
162 FillConsoleOutputCharacterW(hOutput, L' ',
163 csbi.dwSize.X * csbi.dwSize.Y,
164 coPos, &dwWritten);
165 SetConsoleCursorPosition(hOutput, coPos);
166 }
167 else if (IsTTYHandle(hOutput))
168 {
169 /* Clear the full screen and move the cursor to (0,0) */
170 ConPuts(Screen->Stream, L"\x1B[2J\x1B[1;1H");
171 }
172 else
173 {
174 /* Issue a Form-Feed control */
175 WCHAR ch = L'\f';
176 CON_STREAM_WRITE(Screen->Stream, &ch, 1);
177 }
178}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:641
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
@ Screen
Definition: console.h:34
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: readwrite.c:1674
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
#define IsConsoleHandle(h)
Definition: console.h:14
BOOL ConGetScreenInfo(IN PCON_SCREEN Screen, OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
Definition: screen.c:73
#define CON_STREAM_WRITE
Definition: screen.c:31
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:393
Definition: bl.h:1338
ULONG Y
Definition: bl.h:1340
ULONG X
Definition: bl.h:1339
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by cmd_cls(), and PagePrompt().

◆ ConGetScreenInfo()

BOOL ConGetScreenInfo ( IN PCON_SCREEN  Screen,
OUT PCONSOLE_SCREEN_BUFFER_INFO  pcsbi 
)

Definition at line 73 of file screen.c.

76{
78 HANDLE hOutput;
79
80 /* Parameters validation */
81 if (!Screen || !pcsbi)
82 return FALSE;
83
84 hOutput = ConStreamGetOSHandle(Screen->Stream);
85
86 /* Screen handle must be of TTY type (console or TTY) */
87 if (!IsTTYHandle(hOutput))
88 return FALSE;
89
90 /* Update cached screen information */
91 if (IsConsoleHandle(hOutput))
92 {
93 Success = GetConsoleScreenBufferInfo(hOutput, &Screen->csbi);
94 }
95 else
96 {
97#if 0
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;
102
103 // Screen->csbi.dwCursorPosition;
104 // Screen->csbi.wAttributes;
105 // Screen->csbi.srWindow;
106 Screen->csbi.dwMaximumWindowSize = Screen->csbi.dwSize;
107#else
108 hOutput = CreateFileW(L"CONOUT$", GENERIC_READ|GENERIC_WRITE,
110 OPEN_EXISTING, 0, NULL);
111
112 Success = IsConsoleHandle(hOutput) &&
113 GetConsoleScreenBufferInfo(hOutput, &Screen->csbi);
114
115 CloseHandle(hOutput);
116#endif
117 }
118
119 if (Success)
120 {
121 /* Return it to the caller */
122 *pcsbi = Screen->csbi;
123 }
124
125 return Success;
126}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90

Referenced by ConClearScreen(), ConWritePaging(), and PagePrompt().