ReactOS  0.4.14-dev-614-gbfd8a84
CConsole Class Reference

#include <Console.h>

Collaboration diagram for CConsole:

Public Member Functions

void EnableWrite ()
 
void DisableWrite ()
 
void SetReplaceCompletionCallback (ReplaceCompletionCallback pfCallback)
 
BOOL SetInsertMode (BOOL blnInsetMode)
 
void BeginScrollingOperation ()
 
TCHARInit (DWORD dwBufferSize, DWORD dwMaxHistoryLines=0)
 
BOOL ReadLine ()
 
BOOL FlushInputBuffer ()
 
BOOL SetTextAttribute (WORD wAttributes)
 
BOOL GetTextAttribute (WORD &rwAttributes)
 
BOOL SetTitle (const TCHAR *p)
 
BOOL Write (const TCHAR *p, DWORD dwChars=0)
 
 CConsole ()
 
virtual ~CConsole ()
 
unsigned int GetTabWidth ()
 

Private Member Functions

BOOL WriteString (const TCHAR *pchString, COORD Position)
 
BOOL WriteChar (TCHAR ch)
 

Private Attributes

HANDLE m_hStdOut
 
HANDLE m_hStdIn
 
HANDLE m_hStdError
 
COORD m_CursorPosition
 
COORD m_BufferSize
 
WORD m_wAttributes
 
SHORT m_Lines
 
BOOL m_blnInsetMode
 
DWORD m_dwInsertModeCursorHeight
 
DWORD m_dwOverwriteModeCursorHeight
 
TCHARm_pchBuffer
 
TCHARm_pchBuffer1
 
TCHARm_pchBuffer2
 
DWORD m_dwBufferSize
 
ReplaceCompletionCallback m_pfReplaceCompletionCallback
 
SHORT m_LinesScrolled
 
BOOL m_blnMoreMode
 
CTextHistory m_History
 
BOOL m_blnDisableWrite
 
DWORD m_dwOldOutputMode
 
DWORD m_dwOldInputMode
 
BOOL m_blnOldInputModeSaved
 
BOOL m_blnOldOutputModeSaved
 

Detailed Description

Definition at line 12 of file Console.h.

Constructor & Destructor Documentation

◆ CConsole()

CConsole::CConsole ( )

Definition at line 50 of file Console.cpp.

51 {
54  m_blnInsetMode = TRUE; // Insert
55 // m_blnInsetMode = FALSE; // Overwrite
58 // m_Lines = 0;
59  m_pchBuffer = NULL;
64  m_dwOldInputMode = 0;
68 }
BOOL m_blnOldOutputModeSaved
Definition: Console.h:57
#define TRUE
Definition: types.h:120
ReplaceCompletionCallback m_pfReplaceCompletionCallback
Definition: Console.h:49
DWORD m_dwOverwriteModeCursorHeight
Definition: Console.h:44
DWORD m_dwInsertModeCursorHeight
Definition: Console.h:43
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
TCHAR * m_pchBuffer1
Definition: Console.h:46
HANDLE m_hStdIn
Definition: Console.h:34
smooth NULL
Definition: ftsmooth.c:416
DWORD m_dwOldOutputMode
Definition: Console.h:54
TCHAR * m_pchBuffer2
Definition: Console.h:47
HANDLE m_hStdOut
Definition: Console.h:33
DWORD m_dwOldInputMode
Definition: Console.h:55
TCHAR * m_pchBuffer
Definition: Console.h:45
BOOL m_blnOldInputModeSaved
Definition: Console.h:56
BOOL m_blnMoreMode
Definition: Console.h:51
BOOL m_blnInsetMode
Definition: Console.h:42

◆ ~CConsole()

CConsole::~CConsole ( )
virtual

Definition at line 70 of file Console.cpp.

71 {
72  if (m_pchBuffer)
73  delete[] m_pchBuffer;
74  if (m_pchBuffer1)
75  delete[] m_pchBuffer1;
76  if (m_pchBuffer2)
77  delete[] m_pchBuffer2;
78 
83 
88 }
BOOL m_blnOldOutputModeSaved
Definition: Console.h:57
#define CloseHandle
Definition: compat.h:406
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
TCHAR * m_pchBuffer1
Definition: Console.h:46
HANDLE m_hStdIn
Definition: Console.h:34
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
DWORD m_dwOldOutputMode
Definition: Console.h:54
TCHAR * m_pchBuffer2
Definition: Console.h:47
#define VERIFY(e)
Definition: ph.h:34
HANDLE m_hStdOut
Definition: Console.h:33
DWORD m_dwOldInputMode
Definition: Console.h:55
TCHAR * m_pchBuffer
Definition: Console.h:45
BOOL m_blnOldInputModeSaved
Definition: Console.h:56

Member Function Documentation

◆ BeginScrollingOperation()

void CConsole::BeginScrollingOperation ( )

Definition at line 1007 of file Console.cpp.

1008 {
1009  m_Lines = 0;
1010 }
SHORT m_Lines
Definition: Console.h:39

Referenced by main().

◆ DisableWrite()

void CConsole::DisableWrite ( )

Definition at line 1064 of file Console.cpp.

1065 {
1067  INPUT_RECORD InputRecord;
1068  DWORD dwRecordsWriten;
1069  InputRecord.EventType = KEY_EVENT;
1070  InputRecord.Event.KeyEvent.bKeyDown = TRUE;
1071 #ifdef UNICODE
1072  InputRecord.Event.KeyEvent.uChar.UnicodeChar = L' ';
1073 #else
1074  InputRecord.Event.KeyEvent.uChar.AsciiChar = ' ';
1075 #endif
1076  BOOL ret = WriteConsoleInput(m_hStdIn,&InputRecord,1,&dwRecordsWriten);
1077  ASSERT(ret);
1078 }
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
#define WriteConsoleInput
Definition: wincon.h:773
union _KEY_EVENT_RECORD::@3176 uChar
union _INPUT_RECORD::@3177 Event
HANDLE m_hStdIn
Definition: Console.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define KEY_EVENT
Definition: wincon.h:122
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
int ret
static const WCHAR L[]
Definition: oid.c:1250
BOOL m_blnDisableWrite
Definition: Console.h:53
WORD EventType
Definition: wincon.h:261

Referenced by HandlerRoutine().

◆ EnableWrite()

void CConsole::EnableWrite ( )

Definition at line 1080 of file Console.cpp.

1081 {
1083 }
BOOL m_blnDisableWrite
Definition: Console.h:53

Referenced by main().

◆ FlushInputBuffer()

BOOL CConsole::FlushInputBuffer ( )

Definition at line 243 of file Console.cpp.

244 {
245  if (m_hStdIn == INVALID_HANDLE_VALUE) return FALSE;
247 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:191
HANDLE m_hStdIn
Definition: Console.h:34

Referenced by main(), and Write().

◆ GetTabWidth()

unsigned int CConsole::GetTabWidth ( )

Definition at line 217 of file Console.cpp.

218 {
219  return TAB_WIDTH;
220 }
#define TAB_WIDTH
Definition: Console.cpp:29

Referenced by CShellCommandDir::Execute().

◆ GetTextAttribute()

BOOL CConsole::GetTextAttribute ( WORD rwAttributes)

Definition at line 858 of file Console.cpp.

859 {
860  rwAttributes = m_wAttributes;
861  return TRUE;
862 }
#define TRUE
Definition: types.h:120
WORD m_wAttributes
Definition: Console.h:38

Referenced by main().

◆ Init()

TCHAR * CConsole::Init ( DWORD  dwBufferSize,
DWORD  dwMaxHistoryLines = 0 
)

Definition at line 870 of file Console.cpp.

871 {
874 
876 
878  {
879 // _ftprintf(stderr,_T("GetStdHandle(STD_INPUT_HANDLE) failed. GetLastError return 0x%X\n"),(unsigned)GetLastError());
880  goto Abort;
881  }
882 
884 
886  {
887 // _ftprintf(stderr,_T("GetStdHandle(STD_OUTPUT_HANDLE) failed. GetLastError return 0x%X\n"),(unsigned)GetLastError());
888  goto Abort;
889  }
890 
893  {
894 // _ftprintf(stderr,_T("GetConsoleScreenBufferInfo(m_hStdOut,&info) failed. GetLastError return 0x%X\n"),(unsigned)GetLastError());
895  if (GetLastError() == 6) // redirected output
896  _ftprintf(stderr,_T("Redirection is not supported.\n"));
897 
898  goto Abort;
899  }
900  m_wAttributes = info.wAttributes;
901 
903  {
905  {
906  if (GetLastError() == 6) // redirected input
907  _ftprintf(stderr,_T("Redirection is not supported.\n"));
908 // _ftprintf(stderr,_T("GetConsoleMode(0x%X,&m_dwOldINputMode) failed. GetLastError() returns 0x%X\n"),(int)m_hStdIn,GetLastError());
909  goto Abort;
910  }
911 
913  }
914 
915 // _ftprintf(stderr,_T("Calling GetConsoleMode(0x%X,&m_dwOldOutputMode) ...\n"),(int)m_hStdOut);
917  {
919  goto Abort;
920 // _ftprintf(stderr,_T("Calling GetConsoleMode(0x%X,&m_dwOldOutputMode) done.\n"),(int)m_hStdOut);
922  }
923 
924 // _ftprintf(stderr,_T("Calling SetConsoleMode(0x%X,0) ...\n"),(int)m_hStdIn);
925  if (!SetConsoleMode(m_hStdIn,0))
926  goto Abort;
927  if (!SetConsoleMode(m_hStdOut,0))
928  goto Abort;
929 
930  m_CursorPosition = info.dwCursorPosition;
931  m_BufferSize = info.dwSize;
932 
934  cci.bVisible = TRUE;
936 
937  if (!SetConsoleCursorInfo(m_hStdOut,&cci)) goto Abort;
938 
939  m_dwBufferSize = dwBufferSize;
940 
941  if (m_pchBuffer) delete m_pchBuffer;
942  m_pchBuffer = NULL;
943 
944  if (m_pchBuffer1) delete m_pchBuffer1;
945  m_pchBuffer1 = NULL;
946 
947  if (m_pchBuffer2) delete m_pchBuffer2;
948  m_pchBuffer2 = NULL;
949 
950  m_pchBuffer = new (std::nothrow) TCHAR [dwBufferSize];
951  if (!m_pchBuffer) goto Abort;
952  m_pchBuffer[dwBufferSize-1] = 0;
953 
954  m_pchBuffer1 = new (std::nothrow) TCHAR [dwBufferSize];
955  if (!m_pchBuffer1) goto Abort;
956  m_pchBuffer1[dwBufferSize-1] = 0;
957 
958  m_pchBuffer2 = new (std::nothrow) TCHAR [dwBufferSize];
959  if (!m_pchBuffer2) goto Abort;
960  m_pchBuffer2[dwBufferSize-1] = 0;
961 
962  if (dwMaxHistoryLines)
963  {
964  if (!m_History.Init(dwBufferSize,dwMaxHistoryLines)) goto Abort;
965  }
966 
967  return m_pchBuffer;
968 
969 Abort:
972 
975 
976  if (m_pchBuffer) delete[] m_pchBuffer;
977  m_pchBuffer = NULL;
978 
979  if (m_pchBuffer1) delete[] m_pchBuffer1;
980  m_pchBuffer1 = NULL;
981 
982  if (m_pchBuffer2) delete[] m_pchBuffer2;
983  m_pchBuffer2 = NULL;
984 
985  m_dwBufferSize = 0;
986 
987  return NULL;
988 }
BOOL m_blnOldOutputModeSaved
Definition: Console.h:57
COORD m_BufferSize
Definition: Console.h:37
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
DWORD m_dwOverwriteModeCursorHeight
Definition: Console.h:44
DWORD m_dwInsertModeCursorHeight
Definition: Console.h:43
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
TCHAR * m_pchBuffer1
Definition: Console.h:46
DWORD m_dwBufferSize
Definition: Console.h:48
struct _test_info info[]
Definition: SetCursorPos.c:19
HANDLE m_hStdIn
Definition: Console.h:34
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
smooth NULL
Definition: ftsmooth.c:416
COORD m_CursorPosition
Definition: Console.h:36
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define _ftprintf
Definition: tchar.h:518
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:566
DWORD m_dwOldOutputMode
Definition: Console.h:54
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:589
TCHAR * m_pchBuffer2
Definition: Console.h:47
BOOL Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
Definition: TextHistory.cpp:44
#define VERIFY(e)
Definition: ph.h:34
HANDLE m_hStdOut
Definition: Console.h:33
DWORD m_dwOldInputMode
Definition: Console.h:55
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
TCHAR * m_pchBuffer
Definition: Console.h:45
BOOL m_blnOldInputModeSaved
Definition: Console.h:56
CTextHistory m_History
Definition: Console.h:52
WORD m_wAttributes
Definition: Console.h:38
FILE * stderr
BOOL m_blnInsetMode
Definition: Console.h:42

Referenced by main().

◆ ReadLine()

BOOL CConsole::ReadLine ( )

Definition at line 249 of file Console.cpp.

250 {
251  if (m_hStdIn == INVALID_HANDLE_VALUE) return FALSE;
252  if (m_hStdOut == INVALID_HANDLE_VALUE) return FALSE;
253  if (m_dwBufferSize == 0)
254  {
255  ASSERT(FALSE);
256  return FALSE;
257  }
258  if (m_pchBuffer == NULL)
259  {
260  ASSERT(FALSE);
261  return FALSE;
262  }
263  if (m_pchBuffer1 == NULL)
264  {
265  ASSERT(FALSE);
266  return FALSE;
267  }
268  if (!FlushConsoleInputBuffer(m_hStdIn)) return FALSE;
269 
270  COORD FristCharCursorPosition = m_CursorPosition;
271 #define X_CURSOR_POSITION_FROM_OFFSET(ofs) USHORT(((FristCharCursorPosition.X + ofs)%m_BufferSize.X))
272 #define Y_CURSOR_POSITION_FROM_OFFSET(ofs) USHORT((FristCharCursorPosition.Y + (FristCharCursorPosition.X + ofs)/m_BufferSize.X))
273 //#define OFFSET_FROM_CURSOR_POSITION(pos) ((pos.Y-FristCharCursorPosition.Y)*m_BufferSize.X+pos.X-FristCharCursorPosition.X)
274 
275  DWORD dwRecordsReaded;
276  DWORD dwCurrentCharOffset = 0;
277  DWORD dwLastCharOffset = 0;
278  BOOL ret;
279 
280  BOOL blnCompletionMode = FALSE;
281 // unsigned __int64 nCompletionIndex = 0;
282  unsigned long long nCompletionIndex = 0;
283  DWORD dwCompletionOffset = 0;
284  DWORD dwCompletionStringSize = 0;
285  COORD CompletionPosition = FristCharCursorPosition;
286 
287  m_LinesScrolled = 0;
288  BOOL blnOldMoreMode = m_blnMoreMode;
290 
291  DWORD dwHistoryIndex = 0;
292 
293  INPUT_RECORD InputRecord;
294  while ((ret = ReadConsoleInput(m_hStdIn,&InputRecord,1,&dwRecordsReaded)) != FALSE)
295  {
296  ASSERT(dwRecordsReaded == 1);
297  if (dwRecordsReaded != 1) return FALSE;
298  if (InputRecord.EventType != KEY_EVENT) continue;
299  if (!InputRecord.Event.KeyEvent.bKeyDown) continue;
300 #ifdef UNICODE
301  TCHAR ch = InputRecord.Event.KeyEvent.uChar.UnicodeChar;
302 #else
303  TCHAR ch = InputRecord.Event.KeyEvent.uChar.AsciiChar;
304 #endif
305 KeyRepeat:
306  if (m_LinesScrolled)
307  {
308  if (m_LinesScrolled > FristCharCursorPosition.Y) return FALSE;
309  FristCharCursorPosition.Y = SHORT(FristCharCursorPosition.Y - m_LinesScrolled);
310  if (m_LinesScrolled > CompletionPosition.Y) return FALSE;
311  CompletionPosition.Y = SHORT(CompletionPosition.Y - m_LinesScrolled);
312  m_LinesScrolled = 0;
313  }
314 // char Buf[1024];
315 // sprintf(Buf,"wVirtualKeyCode = %u\nchar = %u\n\n",InputRecord.Event.KeyEvent.wVirtualKeyCode,ch);
316 // OutputDebugString(Buf);
317 
318 #ifndef NO_PASTE
319  if ((ch == 0x16)&&(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'V'))
320  {
321  goto Paste;
322  }
323  else
324 #endif
325  if (ch == 0)
326  {
327 #ifndef NO_PASTE
328  if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_INSERT)
329  {
330  if (!(InputRecord.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED))
331  {
333  }
334  else
335  {
336  if (blnCompletionMode) blnCompletionMode = FALSE;
337 
338 Paste:
340 #ifdef UNICODE
342 #else
343  CF_TEXT
344 #endif
345  ))
346  continue;
347  if (!OpenClipboard(NULL))
348  continue;
349 
350  const TCHAR *pch = NULL;
351 
352  HANDLE hglb = GetClipboardData(
353 #ifdef UNICODE
355 #else
356  CF_TEXT
357 #endif
358  );
359  if (hglb != NULL)
360  {
361  LPTSTR lptstr = (LPTSTR)GlobalLock(hglb);
362  if (lptstr != NULL)
363  {
366  pch = m_pchBuffer1;
367  GlobalUnlock(hglb);
368  }
369  }
370  CloseClipboard();
371 
372  if (pch == NULL) continue;
373 
374  while (*pch)
375  {
376  if (_istprint(*pch))
377  {
378  if (dwLastCharOffset >= m_dwBufferSize-1)
379  {
380  ASSERT(dwLastCharOffset == m_dwBufferSize-1);
381  // Beep(1000,100);
382  break;
383  }
384  TCHAR ch1;
385  //if (m_blnInsetMode)
386  ch1 = m_pchBuffer[dwCurrentCharOffset];
387  m_pchBuffer[dwCurrentCharOffset] = *pch;
388  if ((m_blnInsetMode)||(dwCurrentCharOffset == dwLastCharOffset)) dwLastCharOffset++;
389  dwCurrentCharOffset++;
390  if (!Write(pch,1)) return FALSE;
391  if (m_blnInsetMode)
392  {
393  COORD Cursor = m_CursorPosition;
394  DWORD ofs = dwCurrentCharOffset;
395 
396  while(ofs <= dwLastCharOffset)
397  {
398  ch = m_pchBuffer[ofs];
399  m_pchBuffer[ofs] = ch1;
400  ch1 = ch;
401  ofs++;
402  }
403 
404  if (dwCurrentCharOffset < dwLastCharOffset)
405  {
406  if (!Write(m_pchBuffer+dwCurrentCharOffset,dwLastCharOffset-dwCurrentCharOffset)) return FALSE;
407 
408  if (m_LinesScrolled)
409  {
410  if (m_LinesScrolled > FristCharCursorPosition.Y) return FALSE;
411  Cursor.Y = SHORT(Cursor.Y - m_LinesScrolled);
412  }
413  // Update cursor position
414  m_CursorPosition = Cursor;
416  }
417  }
418  }
419  pch++;
420  }
421  }
422  }
423  else
424 #endif
425  if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT)
426  {
427  if (blnCompletionMode) blnCompletionMode = FALSE;
428  if (dwCurrentCharOffset)
429  {
431  {
432  TCHAR *pchWordBegin = m_pchBuffer+dwCurrentCharOffset-1;
433 
434  while (pchWordBegin > m_pchBuffer)
435  {
436  if (!_istspace(*pchWordBegin)) break;
437  pchWordBegin--;
438  }
439 
440  while (pchWordBegin > m_pchBuffer)
441  {
442  if (_istspace(*(pchWordBegin-1))) break;
443  pchWordBegin--;
444  }
445 
446  ASSERT(pchWordBegin >= m_pchBuffer);
447  dwCurrentCharOffset = pchWordBegin - m_pchBuffer;
448 
449  ASSERT(dwCurrentCharOffset < dwLastCharOffset);
450 
451  m_CursorPosition.X = X_CURSOR_POSITION_FROM_OFFSET(dwCurrentCharOffset);
452  m_CursorPosition.Y = Y_CURSOR_POSITION_FROM_OFFSET(dwCurrentCharOffset);
454  }
455  else
456  {
457  dwCurrentCharOffset--;
458  if (m_CursorPosition.X)
459  {
461  }
462  else
463  {
467  }
469  }
470  }
471  }
472  else if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT)
473  {
474  if (blnCompletionMode) blnCompletionMode = FALSE;
475  if (dwCurrentCharOffset < dwLastCharOffset)
476  {
478  {
479  TCHAR *pchWordBegin = m_pchBuffer+dwCurrentCharOffset;
480 
481  while ((DWORD)(pchWordBegin - m_pchBuffer) < dwLastCharOffset)
482  {
483  if (_istspace(*pchWordBegin)) break;
484  pchWordBegin++;
485  }
486 
487  while ((DWORD)(pchWordBegin - m_pchBuffer) < dwLastCharOffset)
488  {
489  if (!_istspace(*pchWordBegin)) break;
490  pchWordBegin++;
491  }
492 
493  dwCurrentCharOffset = pchWordBegin - m_pchBuffer;
494  ASSERT(dwCurrentCharOffset <= dwLastCharOffset);
495  m_CursorPosition.X = X_CURSOR_POSITION_FROM_OFFSET(dwCurrentCharOffset);
496  m_CursorPosition.Y = Y_CURSOR_POSITION_FROM_OFFSET(dwCurrentCharOffset);
498  }
499  else
500  {
501  dwCurrentCharOffset++;
504  {
506  m_CursorPosition.X = 0;
507  }
509  }
510  }
511  }
512  else if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_HOME)
513  {
514  if (blnCompletionMode) blnCompletionMode = FALSE;
515  dwCurrentCharOffset = 0;
516  m_CursorPosition = FristCharCursorPosition;
518  }
519  else if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_END)
520  {
521  if (blnCompletionMode) blnCompletionMode = FALSE;
522  dwCurrentCharOffset = dwLastCharOffset;
526  }
527  else if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP)
528  {
529  if (blnCompletionMode) blnCompletionMode = FALSE;
530  dwHistoryIndex++;
531  const TCHAR *pchHistoryLine = m_History.GetHistoryLine(dwHistoryIndex-1);
532  if (pchHistoryLine)
533  {
534  if (dwLastCharOffset)
535  {
536  _tcsnset(m_pchBuffer,_T(' '),dwLastCharOffset);
537  m_CursorPosition = FristCharCursorPosition;
539  VERIFY(Write(m_pchBuffer,dwLastCharOffset));
540  dwCurrentCharOffset = dwLastCharOffset = 0;
541  m_CursorPosition = FristCharCursorPosition;
543  }
544  dwCurrentCharOffset = dwLastCharOffset = _tcslen(pchHistoryLine);
545  if (dwLastCharOffset >= m_dwBufferSize)
546  {
547  ASSERT(FALSE);
548  return FALSE;
549  }
550  _tcscpy(m_pchBuffer,pchHistoryLine);
551  if (!Write(m_pchBuffer)) return FALSE;
552  }
553  else
554  {
555  dwHistoryIndex--;
556  }
557  }
558  else if (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN)
559  {
560  if (blnCompletionMode) blnCompletionMode = FALSE;
561  if (dwHistoryIndex)
562  {
563  dwHistoryIndex--;
564  const TCHAR *pchHistoryLine = m_History.GetHistoryLine(dwHistoryIndex-1);
565  if (dwLastCharOffset)
566  {
567  _tcsnset(m_pchBuffer,_T(' '),dwLastCharOffset);
568  m_CursorPosition = FristCharCursorPosition;
570  VERIFY(Write(m_pchBuffer,dwLastCharOffset));
571  dwCurrentCharOffset = dwLastCharOffset = 0;
572  m_CursorPosition = FristCharCursorPosition;
574  }
575  if (pchHistoryLine)
576  {
577  dwCurrentCharOffset = dwLastCharOffset = _tcslen(pchHistoryLine);
578  if (dwLastCharOffset >= m_dwBufferSize)
579  {
580  ASSERT(FALSE);
581  return FALSE;
582  }
583  _tcscpy(m_pchBuffer,pchHistoryLine);
584  if (!Write(m_pchBuffer)) return FALSE;
585  }
586  }
587  }
588  else if ((InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DELETE)&&
589  (dwLastCharOffset))
590  {
591  // Move the characters if any...
592  ASSERT(dwLastCharOffset);
593  DWORD dwCharOffset = dwCurrentCharOffset;
594  if (dwCharOffset < dwLastCharOffset)
595  {
596  while(dwCharOffset < dwLastCharOffset)
597  {
598  m_pchBuffer[dwCharOffset] = m_pchBuffer[dwCharOffset+1];
599  dwCharOffset++;
600  }
601 
602  m_pchBuffer[dwLastCharOffset-1] = _T(' ');
603 
604  // Save cursor position
605  COORD Cursor = m_CursorPosition;
606 
607  if (!Write(m_pchBuffer+dwCurrentCharOffset,dwLastCharOffset-dwCurrentCharOffset)) return FALSE;
608 
609  dwLastCharOffset--;
610 
611  // Update cursor position
612  m_CursorPosition = Cursor;
614  }
615 
616  }
617 // else if ((InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_PAUSE)&&
618 // (InputRecord.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)))
619 // {
620 // if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,0)) return FALSE;
621 // }
622  }
623  else if ((ch == 27) && dwLastCharOffset &&
624  (InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE))
625  {
626  if (blnCompletionMode) blnCompletionMode = FALSE;
627  _tcsnset(m_pchBuffer,_T(' '),dwLastCharOffset);
628  m_CursorPosition = FristCharCursorPosition;
630  VERIFY(Write(m_pchBuffer,dwLastCharOffset));
631  dwCurrentCharOffset = dwLastCharOffset = 0;
632  m_CursorPosition = FristCharCursorPosition;
634  }
635  else if (ch == _T('\r'))
636  { // carriage return
637  if (!SetConsoleCursorPosition(m_hStdOut,m_CursorPosition = FristCharCursorPosition)) return FALSE;
638  ASSERT(dwLastCharOffset <= m_dwBufferSize);
639  m_pchBuffer[dwLastCharOffset] = 0; // terminate string in buffer
640  ret = Write(m_pchBuffer);
642  static TCHAR strLF[] = _T("\n");
643  ret = Write(strLF);
644  break;
645  }
646  else if (ch == _T('\b'))
647  { // backspace
648  if (blnCompletionMode) blnCompletionMode = FALSE;
649  if ((dwCurrentCharOffset) && ((m_CursorPosition.X != 0) || (m_CursorPosition.Y != 0)))
650  {
651  // Calculate new cursor position
652  COORD NewCursorPosition;
653  if (m_CursorPosition.X)
654  {
655  NewCursorPosition.X = SHORT(m_CursorPosition.X-1);
656  NewCursorPosition.Y = m_CursorPosition.Y;
657  }
658  else
659  {
661  NewCursorPosition.X = SHORT(m_BufferSize.X-1);
663  NewCursorPosition.Y = SHORT(m_CursorPosition.Y-1);
664  }
665 
666  // Move the characters if any...
667  ASSERT(dwLastCharOffset);
668  DWORD dwCharOffset = dwCurrentCharOffset-1;
669  while(dwCharOffset < dwLastCharOffset-1)
670  {
671  m_pchBuffer[dwCharOffset] = m_pchBuffer[dwCharOffset+1];
672  dwCharOffset++;
673  }
674 
675  m_pchBuffer[dwLastCharOffset-1] = _T(' ');
676 
677  dwCurrentCharOffset--;
678  m_CursorPosition = NewCursorPosition;
679  if (!Write(m_pchBuffer+dwCurrentCharOffset,dwLastCharOffset-dwCurrentCharOffset)) return FALSE;
680 
681  // Update cursor position
682  m_CursorPosition = NewCursorPosition;
684 
685  dwLastCharOffset--;
686  }
687  }
688  else if (ch == _T('\t'))
689  { // Tab
690 
691  if (!blnCompletionMode) // If tab was pressed after non-tab. We enter in completion mode.
692  {
693  // Initialize completion index
694  if (InputRecord.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) // If shift was pressed
695  nCompletionIndex = (unsigned long long) -1; // Last completion
696  else
697  nCompletionIndex = 0; // First completion
698 
699  // Find completion offset. It points at char after first non-quoted whitespace.
700  dwCompletionOffset = dwCurrentCharOffset;
701  BOOL blnQuotedParameter = FALSE;
702  while(dwCompletionOffset)
703  {
704  dwCompletionOffset--;
705  if (m_pchBuffer[dwCompletionOffset] == _T('\"'))
706  {
707  blnQuotedParameter = !blnQuotedParameter;
708  }
709  else if (!blnQuotedParameter && _istspace(m_pchBuffer[dwCompletionOffset]))
710  { // Found ! We are not inside quored parameter and we are on whitespace.
711  dwCompletionOffset++; // dwCompletionOffset must point at char AFTER first non-quoted whitespace.
712  break;
713  }
714  }
715 
716  ASSERT(dwCompletionOffset <= dwCurrentCharOffset);
717 
718  // Save not changing part (context) of completion in m_pchBuffer1
719 
720  // FIXME: dwCompletionOffset is always 0 here
721  // _tcsncpy(m_pchBuffer1,m_pchBuffer,dwCompletionOffset);
722  m_pchBuffer1[dwCompletionOffset] = 0;
723 
724  // Size of changing part
725  dwCompletionStringSize = dwCurrentCharOffset-dwCompletionOffset;
726 
727  // Save intial changing part of completion in m_pchBuffer2
728  if (dwCompletionStringSize)
729  _tcsncpy(m_pchBuffer2,m_pchBuffer+dwCompletionOffset,dwCompletionStringSize);
730  m_pchBuffer2[dwCompletionStringSize] = 0;
731 
732  // Calculate cursor position of point between changing and not changing ports
733  CompletionPosition.X = X_CURSOR_POSITION_FROM_OFFSET(dwCompletionOffset);
734  CompletionPosition.Y = Y_CURSOR_POSITION_FROM_OFFSET(dwCompletionOffset);
735  } // if first time tab
736 
737  const TCHAR *pchCompletion = NULL;
738 
739  // Direction
740  BOOL blnForward = !(InputRecord.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED);
741 
742  if (m_pfReplaceCompletionCallback) // If we are using replace completion callback
743  pchCompletion = m_pfReplaceCompletionCallback(nCompletionIndex,
744  blnCompletionMode?&blnForward:NULL, // If this is first time we call the completion callback, do not change completion index
746 
747  if (pchCompletion) // If completion found
748  {
749  // Set cursor position to compeltion position
750  m_CursorPosition = CompletionPosition;
752  return FALSE;
753 
754  // Calculate buffer free space
755  ASSERT(m_dwBufferSize > dwCompletionOffset);
756  DWORD dwFree = m_dwBufferSize - dwCompletionOffset - 1;
757 
758  // Save old completion string size
759  DWORD dwOldCompletionStringSize = dwCompletionStringSize;
760 
761  // Write completion string to buffer
762  dwCompletionStringSize = _tcslen(pchCompletion);
763 
764  // If there is not enough space in buffer, so we truncate the completion
765  if (dwCompletionStringSize > dwFree)
766  dwCompletionStringSize = dwFree;
767 
768  if (dwCompletionStringSize)
769  {
770  // Copy competion into main buffer
771  _tcsncpy(m_pchBuffer+dwCompletionOffset,pchCompletion,dwCompletionStringSize);
772 
773  // Write completion string to console
774  if (!Write(m_pchBuffer+dwCompletionOffset,dwCompletionStringSize))
775  return FALSE;
776 
777  // Set new offsets
778  dwCurrentCharOffset = dwLastCharOffset = dwCompletionOffset + dwCompletionStringSize;
779 
780  ASSERT(dwLastCharOffset < m_dwBufferSize);
781  }
782 
783  // Erase rest from previous completion string, if the new completion is shorter than old
784  if (dwOldCompletionStringSize > dwCompletionStringSize)
785  {
786  _tcsnset(m_pchBuffer+dwCompletionOffset+dwCompletionStringSize,_T(' '),
787  dwOldCompletionStringSize - dwCompletionStringSize);
788 
789  // Save cursor position
791 
792  if (!Write(m_pchBuffer+dwCompletionOffset+dwCompletionStringSize,
793  dwOldCompletionStringSize - dwCompletionStringSize))
794  return FALSE;
795 
796  // Set cursor position
799  return FALSE;
800  }
801  } // If completion found
802 
803  // Ok, we are in completion mode
804  blnCompletionMode = TRUE;
805  }
806  else if (_istprint(ch))
807  {
808  if (blnCompletionMode) blnCompletionMode = FALSE;
809  if (dwLastCharOffset >= m_dwBufferSize-1)
810  {
811  ASSERT(dwLastCharOffset == m_dwBufferSize-1);
812 // Beep(1000,100);
813  continue;
814  }
815  TCHAR ch1;
816  //if (m_blnInsetMode)
817  ch1 = m_pchBuffer[dwCurrentCharOffset];
818  m_pchBuffer[dwCurrentCharOffset] = ch;
819  if ((m_blnInsetMode)||(dwCurrentCharOffset == dwLastCharOffset)) dwLastCharOffset++;
820  dwCurrentCharOffset++;
821  if (!Write(&ch,1)) return FALSE;
822  if (m_blnInsetMode)
823  {
824  COORD Cursor = m_CursorPosition;
825  DWORD ofs = dwCurrentCharOffset;
826 
827  while(ofs <= dwLastCharOffset)
828  {
829  ch = m_pchBuffer[ofs];
830  m_pchBuffer[ofs] = ch1;
831  ch1 = ch;
832  ofs++;
833  }
834 
835  if (dwCurrentCharOffset < dwLastCharOffset)
836  {
837  if (!Write(m_pchBuffer+dwCurrentCharOffset,dwLastCharOffset-dwCurrentCharOffset)) return FALSE;
838 
839  if (m_LinesScrolled)
840  {
841  if (m_LinesScrolled > FristCharCursorPosition.Y) return FALSE;
842  Cursor.Y = SHORT(Cursor.Y - m_LinesScrolled);
843  }
844  // Update cursor position
845  m_CursorPosition = Cursor;
847  }
848  }
849  }
850  ASSERT(InputRecord.Event.KeyEvent.wRepeatCount);
851  if (!InputRecord.Event.KeyEvent.wRepeatCount) return FALSE;
852  if (--InputRecord.Event.KeyEvent.wRepeatCount) goto KeyRepeat;
853  }
854  m_blnMoreMode = blnOldMoreMode;
855  return TRUE;
856 }
COORD m_BufferSize
Definition: Console.h:37
wchar_t UNICODE
Definition: ms-dtyp.idl:111
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
ReplaceCompletionCallback m_pfReplaceCompletionCallback
Definition: Console.h:49
BOOL WINAPI IsClipboardFormatAvailable(_In_ UINT)
static VOID Paste(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:1983
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
DWORD dwControlKeyState
Definition: wincon.h:233
SHORT m_LinesScrolled
Definition: Console.h:50
#define VK_LEFT
Definition: winuser.h:2199
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:191
union _KEY_EVENT_RECORD::@3176 uChar
#define VK_DOWN
Definition: winuser.h:2202
#define VK_INSERT
Definition: winuser.h:2207
#define Y_CURSOR_POSITION_FROM_OFFSET(ofs)
#define SHIFT_PRESSED
Definition: wincon.h:135
#define VK_ESCAPE
Definition: winuser.h:2189
union _INPUT_RECORD::@3177 Event
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define pch(ap)
Definition: match.c:418
TCHAR * m_pchBuffer1
Definition: Console.h:46
DWORD m_dwBufferSize
Definition: Console.h:48
WORD wVirtualKeyCode
Definition: wincon.h:227
#define VK_HOME
Definition: winuser.h:2198
WORD wRepeatCount
Definition: wincon.h:226
#define VK_UP
Definition: winuser.h:2200
HANDLE m_hStdIn
Definition: Console.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ReadConsoleInput
Definition: wincon.h:766
short SHORT
Definition: pedump.c:59
#define KEY_EVENT
Definition: wincon.h:122
#define CF_UNICODETEXT
Definition: constants.h:408
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
BOOL SetInsertMode(BOOL blnInsetMode)
Definition: Console.cpp:1043
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:612
COORD m_CursorPosition
Definition: Console.h:36
#define VK_DELETE
Definition: winuser.h:2208
#define CF_TEXT
Definition: constants.h:396
const TCHAR * GetHistoryLine(DWORD dwIndex)
Definition: TextHistory.cpp:83
ULONG X
Definition: bl.h:1340
#define X_CURSOR_POSITION_FROM_OFFSET(ofs)
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
void AddHistoryLine(const TCHAR *pchLine)
Definition: TextHistory.cpp:62
TCHAR * m_pchBuffer2
Definition: Console.h:47
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
#define VERIFY(e)
Definition: ph.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE m_hStdOut
Definition: Console.h:33
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
int ret
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
#define _istprint
Definition: tchar.h:1500
TCHAR * m_pchBuffer
Definition: Console.h:45
Definition: bl.h:1338
#define VK_RIGHT
Definition: winuser.h:2201
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
#define long
Definition: qsort.c:33
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HANDLE WINAPI GetClipboardData(_In_ UINT)
BOOL m_blnMoreMode
Definition: Console.h:51
WORD EventType
Definition: wincon.h:261
CTextHistory m_History
Definition: Console.h:52
#define _istspace
Definition: tchar.h:1504
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
ULONG Y
Definition: bl.h:1341
BOOL m_blnInsetMode
Definition: Console.h:42
#define VK_END
Definition: winuser.h:2197
#define _tcsnset
Definition: tchar.h:1419

Referenced by main().

◆ SetInsertMode()

BOOL CConsole::SetInsertMode ( BOOL  blnInsetMode)

Definition at line 1043 of file Console.cpp.

1044 {
1045  if (m_hStdOut == INVALID_HANDLE_VALUE) return FALSE;
1046 
1047  CONSOLE_CURSOR_INFO cci;
1048  cci.bVisible = TRUE;
1050 
1052  if (ret) m_blnInsetMode = blnInsetMode;
1053  return ret;
1054 }
#define TRUE
Definition: types.h:120
DWORD m_dwOverwriteModeCursorHeight
Definition: Console.h:44
DWORD m_dwInsertModeCursorHeight
Definition: Console.h:43
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:589
HANDLE m_hStdOut
Definition: Console.h:33
int ret
BOOL m_blnInsetMode
Definition: Console.h:42

Referenced by ReadLine().

◆ SetReplaceCompletionCallback()

void CConsole::SetReplaceCompletionCallback ( ReplaceCompletionCallback  pfCallback)

Definition at line 1058 of file Console.cpp.

1059 {
1060  m_pfReplaceCompletionCallback = pfCallback;
1061 }
ReplaceCompletionCallback m_pfReplaceCompletionCallback
Definition: Console.h:49

Referenced by main().

◆ SetTextAttribute()

BOOL CConsole::SetTextAttribute ( WORD  wAttributes)

Definition at line 227 of file Console.cpp.

228 {
229  m_wAttributes = wAttributes;
230  return TRUE;
231 }
#define TRUE
Definition: types.h:120
WORD m_wAttributes
Definition: Console.h:38

Referenced by main().

◆ SetTitle()

BOOL CConsole::SetTitle ( const TCHAR p)

Definition at line 222 of file Console.cpp.

223 {
224  return SetConsoleTitle(p);
225 }
#define SetConsoleTitle
Definition: wincon.h:771
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by main().

◆ Write()

BOOL CConsole::Write ( const TCHAR p,
DWORD  dwChars = 0 
)

Definition at line 90 of file Console.cpp.

91 {
93  return FALSE;
95  return FALSE;
96  if (p == NULL)
97  {
98  ASSERT(FALSE);
99  return FALSE;
100  }
101  DWORD dwCharsToWrite = (dwChars)?dwChars:_tcslen(p);
102  DWORD dwCharsWrittenAdd = 0;
103  BOOL ret = TRUE;
104  while (dwCharsToWrite && (!m_blnDisableWrite))
105  {
106  switch(p[dwCharsWrittenAdd])
107  {
108  case _T('\n'):
110  m_CursorPosition.X = 0;
111  break;
112  case _T('\r'):
113  dwCharsWrittenAdd++;
114  dwCharsToWrite--;
115  continue;
116  case _T('\t'):
117  do
118  {
119  if (!Write(_T(" "))) return FALSE;
120  }
121  while ((m_CursorPosition.X % TAB_WIDTH) && (!m_blnDisableWrite));
122  dwCharsWrittenAdd++;
123  dwCharsToWrite--;
124  continue;
125  default:
126  {
127  if (!WriteChar(p[dwCharsWrittenAdd])) return FALSE;
129  }
130  }
132  {
134  m_CursorPosition.X = 0;
135  }
137  {
138  ASSERT(m_CursorPosition.X == 0);
139  SMALL_RECT Src;
140  Src.Left = 0;
141  Src.Right = (SHORT)(m_BufferSize.X-1);
142  Src.Top = 1;
143  Src.Bottom = (SHORT)(m_BufferSize.Y-1);
144  CHAR_INFO ci;
145 #ifdef UNICODE
146  ci.Char.UnicodeChar = L' ';
147 #else
148  ci.Char.AsciiChar = ' ';
149 #endif
150  ci.Attributes = 0;
151  COORD Dest;
152  Dest.X = 0;
153  Dest.Y = 0;
154  if (!ScrollConsoleScreenBuffer(m_hStdOut,&Src,NULL,Dest,&ci)) return FALSE;
156  m_LinesScrolled++;
157  }
159  VERIFY(WriteChar(_T(' ')));
160  if ((m_blnMoreMode)&&(m_CursorPosition.X == 0))
161  {
162  m_Lines++;
163  if (m_Lines >= m_BufferSize.Y-1)
164  {
166  m_Lines = 0;
169 
171  cci.bVisible = FALSE;
172  cci.dwSize = 100;
174 
175  INPUT_RECORD InputRecord;
176  DWORD dwRecordsReaded;
177  while ((ret = ReadConsoleInput(m_hStdIn,&InputRecord,1,&dwRecordsReaded)) != FALSE)
178  {
179  ASSERT(dwRecordsReaded == 1);
180  if (dwRecordsReaded != 1)
181  break;
182  if (InputRecord.EventType != KEY_EVENT)
183  continue;
184  if (!InputRecord.Event.KeyEvent.bKeyDown)
185  continue;
186 
187  if ((InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_CANCEL)||
188  (InputRecord.Event.KeyEvent.wVirtualKeyCode == _T('Q')))
189  {
191  continue;
192  }
193 #ifdef UNICODE
194  TCHAR ch = InputRecord.Event.KeyEvent.uChar.UnicodeChar;
195 #else
196  TCHAR ch = InputRecord.Event.KeyEvent.uChar.AsciiChar;
197 #endif
198  if (ch)
199  break;
200  }
201 
202  // delete "more" msg
204  m_CursorPosition.X = 0;
205 
206  cci.bVisible = TRUE;
209  }
210  }
211  dwCharsWrittenAdd++;
212  dwCharsToWrite--;
213  }
214  return ret;
215 }
COORD m_BufferSize
Definition: Console.h:37
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
SHORT m_Lines
Definition: Console.h:39
DWORD m_dwOverwriteModeCursorHeight
Definition: Console.h:44
CHAR AsciiChar
Definition: wincon.h:170
#define Y(I)
DWORD m_dwInsertModeCursorHeight
Definition: Console.h:43
WCHAR UnicodeChar
Definition: wincon.h:169
#define CTRL_C_EVENT
Definition: wincon.h:65
SHORT m_LinesScrolled
Definition: Console.h:50
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define MORE_EMPTY_STRING
Definition: Console.cpp:31
union _KEY_EVENT_RECORD::@3176 uChar
#define MORE_STRING
Definition: Console.cpp:30
union _INPUT_RECORD::@3177 Event
WORD wVirtualKeyCode
Definition: wincon.h:227
BOOL WINAPI DECLSPEC_HOTPATCH GenerateConsoleCtrlEvent(DWORD dwCtrlEvent, DWORD dwProcessGroupId)
Definition: console.c:2134
HANDLE m_hStdIn
Definition: Console.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ReadConsoleInput
Definition: wincon.h:766
short SHORT
Definition: pedump.c:59
#define KEY_EVENT
Definition: wincon.h:122
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:612
BOOL FlushInputBuffer()
Definition: Console.cpp:243
COORD m_CursorPosition
Definition: Console.h:36
do
Definition: dirsup.c:1173
SHORT Left
Definition: blue.h:32
ULONG X
Definition: bl.h:1340
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
SHORT Bottom
Definition: blue.h:35
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:589
WORD Attributes
Definition: wincon.h:172
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
#define VERIFY(e)
Definition: ph.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
HANDLE m_hStdOut
Definition: Console.h:33
SHORT Top
Definition: blue.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define VK_CANCEL
Definition: winuser.h:2167
int ret
static const WCHAR L[]
Definition: oid.c:1250
BOOL m_blnDisableWrite
Definition: Console.h:53
Definition: bl.h:1338
#define TAB_WIDTH
Definition: Console.cpp:29
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
#define ScrollConsoleScreenBuffer
Definition: wincon.h:770
BOOL WriteChar(TCHAR ch)
Definition: Console.cpp:990
BOOL m_blnMoreMode
Definition: Console.h:51
WORD EventType
Definition: wincon.h:261
GLfloat GLfloat p
Definition: glext.h:8902
SHORT Right
Definition: blue.h:34
union _CHAR_INFO::@3175 Char
ULONG Y
Definition: bl.h:1341
BOOL m_blnInsetMode
Definition: Console.h:42
BOOL WriteString(const TCHAR *pchString, COORD Position)
Definition: Console.cpp:1012

Referenced by CShellCommandExit::Execute(), CShellCommandVersion::Execute(), CShellCommandValue::Execute(), CShellCommandDeleteKey::Execute(), CShellCommandSACL::Execute(), CShellCommandOwner::Execute(), CShellCommandNewKey::Execute(), CShellCommandHelp::Execute(), CShellCommandSetValue::Execute(), CShellCommandDOKA::Execute(), CShellCommandDeleteValue::Execute(), CShellCommandDir::Execute(), CShellCommandChangeKey::Execute(), CShellCommandDACL::Execute(), CShellCommandConnect::Execute(), HandlerRoutine(), main(), ReadLine(), and CPrompt::ShowPrompt().

◆ WriteChar()

BOOL CConsole::WriteChar ( TCHAR  ch)
private

Definition at line 990 of file Console.cpp.

991 {
992  CHAR_INFO ci;
994 #ifdef UNICODE
995  ci.Char.UnicodeChar = ch;
996 #else
997  ci.Char.AsciiChar = ch;
998 #endif
999  static COORD BufferSize = {1,1};
1000  static COORD BufferCoord = {0,0};
1001  SMALL_RECT Dest;
1002  Dest.Bottom = Dest.Top = m_CursorPosition.Y;
1003  Dest.Left = Dest.Right = m_CursorPosition.X;
1004  return WriteConsoleOutput(m_hStdOut,&ci,BufferSize,BufferCoord,&Dest);
1005 }
CHAR AsciiChar
Definition: wincon.h:170
WCHAR UnicodeChar
Definition: wincon.h:169
#define WriteConsoleOutput
Definition: wincon.h:775
COORD m_CursorPosition
Definition: Console.h:36
SHORT Left
Definition: blue.h:32
ULONG X
Definition: bl.h:1340
SHORT Bottom
Definition: blue.h:35
WORD Attributes
Definition: wincon.h:172
#define BufferSize
Definition: classpnp.h:419
HANDLE m_hStdOut
Definition: Console.h:33
SHORT Top
Definition: blue.h:33
Definition: bl.h:1338
WORD m_wAttributes
Definition: Console.h:38
SHORT Right
Definition: blue.h:34
union _CHAR_INFO::@3175 Char
ULONG Y
Definition: bl.h:1341

Referenced by Write().

◆ WriteString()

BOOL CConsole::WriteString ( const TCHAR pchString,
COORD  Position 
)
private

Definition at line 1012 of file Console.cpp.

1013 {
1014  CHAR_INFO ciBuffer[256];
1015  int nSize = _tcslen(pchString);
1016  if ((nSize > 256)||(nSize <= 0))
1017  {
1018  ASSERT(FALSE);
1019  return FALSE;
1020  }
1021 
1022  COORD BufferSize;
1023  BufferSize.X = (SHORT)nSize;
1024  BufferSize.Y = 1;
1025  static COORD BufferCoord = {0,0};
1026  SMALL_RECT Dest;
1027  Dest.Bottom = Dest.Top = Position.Y;
1028  Dest.Right = SHORT((Dest.Left = Position.X) + nSize - 1);
1029 
1030  while(nSize--)
1031  {
1032  ciBuffer[nSize].Attributes = m_wAttributes;
1033 #ifdef UNICODE
1034  ciBuffer[nSize].Char.UnicodeChar = pchString[nSize];
1035 #else
1036  ciBuffer[nSize].Char.AsciiChar = pchString[nSize];
1037 #endif
1038  }
1039 
1040  return WriteConsoleOutput(m_hStdOut,ciBuffer,BufferSize,BufferCoord,&Dest);
1041 }
CHAR AsciiChar
Definition: wincon.h:170
static COORD Position
Definition: mouse.c:34
WCHAR UnicodeChar
Definition: wincon.h:169
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2031
#define WriteConsoleOutput
Definition: wincon.h:775
short SHORT
Definition: pedump.c:59
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
SHORT Left
Definition: blue.h:32
ULONG X
Definition: bl.h:1340
SHORT Bottom
Definition: blue.h:35
WORD Attributes
Definition: wincon.h:172
#define BufferSize
Definition: classpnp.h:419
HANDLE m_hStdOut
Definition: Console.h:33
SHORT Top
Definition: blue.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: bl.h:1338
WORD m_wAttributes
Definition: Console.h:38
SHORT Right
Definition: blue.h:34
union _CHAR_INFO::@3175 Char
ULONG Y
Definition: bl.h:1341

Referenced by Write().

Member Data Documentation

◆ m_blnDisableWrite

BOOL CConsole::m_blnDisableWrite
private

Definition at line 53 of file Console.h.

Referenced by DisableWrite(), EnableWrite(), and Write().

◆ m_blnInsetMode

BOOL CConsole::m_blnInsetMode
private

Definition at line 42 of file Console.h.

Referenced by CConsole(), Init(), ReadLine(), SetInsertMode(), and Write().

◆ m_blnMoreMode

BOOL CConsole::m_blnMoreMode
private

Definition at line 51 of file Console.h.

Referenced by CConsole(), ReadLine(), and Write().

◆ m_blnOldInputModeSaved

BOOL CConsole::m_blnOldInputModeSaved
private

Definition at line 56 of file Console.h.

Referenced by CConsole(), Init(), and ~CConsole().

◆ m_blnOldOutputModeSaved

BOOL CConsole::m_blnOldOutputModeSaved
private

Definition at line 57 of file Console.h.

Referenced by CConsole(), Init(), and ~CConsole().

◆ m_BufferSize

COORD CConsole::m_BufferSize
private

Definition at line 37 of file Console.h.

Referenced by Init(), ReadLine(), and Write().

◆ m_CursorPosition

COORD CConsole::m_CursorPosition
private

Definition at line 36 of file Console.h.

Referenced by Init(), ReadLine(), Write(), and WriteChar().

◆ m_dwBufferSize

DWORD CConsole::m_dwBufferSize
private

Definition at line 48 of file Console.h.

Referenced by Init(), and ReadLine().

◆ m_dwInsertModeCursorHeight

DWORD CConsole::m_dwInsertModeCursorHeight
private

Definition at line 43 of file Console.h.

Referenced by CConsole(), Init(), SetInsertMode(), and Write().

◆ m_dwOldInputMode

DWORD CConsole::m_dwOldInputMode
private

Definition at line 55 of file Console.h.

Referenced by CConsole(), Init(), and ~CConsole().

◆ m_dwOldOutputMode

DWORD CConsole::m_dwOldOutputMode
private

Definition at line 54 of file Console.h.

Referenced by CConsole(), Init(), and ~CConsole().

◆ m_dwOverwriteModeCursorHeight

DWORD CConsole::m_dwOverwriteModeCursorHeight
private

Definition at line 44 of file Console.h.

Referenced by CConsole(), Init(), SetInsertMode(), and Write().

◆ m_History

CTextHistory CConsole::m_History
private

Definition at line 52 of file Console.h.

Referenced by Init(), and ReadLine().

◆ m_hStdError

HANDLE CConsole::m_hStdError
private

Definition at line 35 of file Console.h.

◆ m_hStdIn

HANDLE CConsole::m_hStdIn
private

Definition at line 34 of file Console.h.

Referenced by CConsole(), DisableWrite(), FlushInputBuffer(), Init(), ReadLine(), Write(), and ~CConsole().

◆ m_hStdOut

HANDLE CConsole::m_hStdOut
private

Definition at line 33 of file Console.h.

Referenced by CConsole(), Init(), ReadLine(), SetInsertMode(), Write(), WriteChar(), WriteString(), and ~CConsole().

◆ m_Lines

SHORT CConsole::m_Lines
private

Definition at line 39 of file Console.h.

Referenced by BeginScrollingOperation(), and Write().

◆ m_LinesScrolled

SHORT CConsole::m_LinesScrolled
private

Definition at line 50 of file Console.h.

Referenced by ReadLine(), and Write().

◆ m_pchBuffer

TCHAR* CConsole::m_pchBuffer
private

Definition at line 45 of file Console.h.

Referenced by CConsole(), Init(), ReadLine(), and ~CConsole().

◆ m_pchBuffer1

TCHAR* CConsole::m_pchBuffer1
private

Definition at line 46 of file Console.h.

Referenced by CConsole(), Init(), ReadLine(), and ~CConsole().

◆ m_pchBuffer2

TCHAR* CConsole::m_pchBuffer2
private

Definition at line 47 of file Console.h.

Referenced by CConsole(), Init(), ReadLine(), and ~CConsole().

◆ m_pfReplaceCompletionCallback

ReplaceCompletionCallback CConsole::m_pfReplaceCompletionCallback
private

Definition at line 49 of file Console.h.

Referenced by CConsole(), ReadLine(), and SetReplaceCompletionCallback().

◆ m_wAttributes

WORD CConsole::m_wAttributes
private

Definition at line 38 of file Console.h.

Referenced by GetTextAttribute(), Init(), SetTextAttribute(), WriteChar(), and WriteString().


The documentation for this class was generated from the following files: