ReactOS  0.4.13-dev-100-gc8611ae
screen.c File Reference
#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)
 

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 }
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:474
BOOL ConGetScreenInfo(IN PCON_SCREEN Screen, OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
Definition: screen.c:73
#define CON_STREAM_WRITE
Definition: screen.c:31
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:590
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
ULONG X
Definition: bl.h:1340
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:342
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IsConsoleHandle(h)
Definition: console.h:14
static const WCHAR L[]
Definition: oid.c:1250
Definition: bl.h:1338
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
Definition: console.h:34
ULONG Y
Definition: bl.h:1341
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
Definition: readwrite.c:1676

Referenced by cmd_cls().

◆ ConGetScreenInfo()

BOOL ConGetScreenInfo ( IN PCON_SCREEN  Screen,
OUT PCONSOLE_SCREEN_BUFFER_INFO  pcsbi 
)

Definition at line 73 of file screen.c.

76 {
77  BOOL Success;
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 CloseHandle
Definition: compat.h:398
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
BOOL IsTTYHandle(IN HANDLE hHandle)
Definition: utils.c:342
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
#define IsConsoleHandle(h)
Definition: console.h:14
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
#define CreateFileW
Definition: compat.h:400
Definition: console.h:34

Referenced by ConClearScreen(), and ConWritePaging().