ReactOS  0.4.12-dev-57-g7050ac4
tconsole.cpp
Go to the documentation of this file.
1 //Telnet Win32 : an ANSI telnet client.
3 //Copyright (C) 1998-2000 Paul Brannan
4 //Copyright (C) 1998 I.Ioannou
5 //Copyright (C) 1997 Brad Johnson
6 //
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
11 //
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
16 //
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 //I.Ioannou
22 //roryt@hol.gr
23 //
25 
27 //
28 // Module: tconsole.cpp
29 //
30 // Contents: screen functions
31 //
32 // Product: telnet
33 //
34 //
35 // Revisions: Mar. 29, 2000 pbranna@clemson (Paul Brannan)
36 // June 15, 1998 pbranna@clemson.edu
37 // May 16, 1998 pbranna@clemson.edu
38 // 05. Sep.1997 roryt@hol.gr (I.Ioannou)
39 // 11.May,1997 roryt@hol.gr
40 // 06.April,1997 roryt@hol.gr
41 // 30.Mrz.1997 Titus_Boxberg@public.uni-hamburg.de
42 // 5.Dec.1996 jbj@nounname.com
43 // Version 2.0
44 // 02.Apr.1995 igor.milavec@uni-lj.si
45 // Original code
46 //
48 
49 #include "precomp.h"
50 
51 // argsused doesn't work on MSVC++
52 #ifdef __BORLANDC__
53 #pragma argsused
54 #endif
55 
57  hConsole = h;
58 
60 
61  // Start with correct colors
62  int color_fg = ini.get_normal_fg();
63  int color_bg = ini.get_normal_bg();
64  if(color_fg == -1)
65  color_fg = defaultfg = origfg = ConsoleInfo.wAttributes & 0xF;
66  else
67  defaultfg = origfg = color_fg;
68  if(color_bg == -1)
69  color_bg = defaultbg = origbg = (ConsoleInfo.wAttributes >> 4) & 0xF;
70  else
71  defaultbg = origbg = color_bg;
72  wAttributes = color_fg | (color_bg << 4);
73  reverse = blink = underline = false;
75 
76  insert_mode = 0;
77 
78  // Set the screen size
80 
81  iScrollStart = -1;
82  iScrollEnd = -1;
83 }
84 
86  wAttributes = origfg | (origbg << 4);
89  WriteCtrlChar('\x0a');
90 }
91 
92 // Paul Brannan 8/2/98
94  SMALL_RECT sr = {
95  CON_LEFT,
96  CON_TOP,
97  (width == -1) ? CON_RIGHT : CON_LEFT + width - 1,
98  (height == -1) ? CON_BOTTOM : CON_TOP + height - 1
99  };
101  if(ConsoleInfo.dwSize.Y < height) ConsoleInfo.dwSize.Y = height;
105  sync();
106 }
107 
108 // Paul Brannan 5/15/98
111 }
112 
114  wAttributes = wAttributes | (unsigned char) 8;
115 }
116 
118  wAttributes = wAttributes & (unsigned char) (0xff-8);
119 }
120 
122  // I.Ioannou 11 May 1997
123  // Color 7 is correct on some systems (for example Linux)
124  // but not with others (for example SCO)
125  // we must preserve the colors :
126  // 06/04/98 thanks to Paul a .ini parameter from now on
127 
128  BlinkOff();
129  UnderlineOff();
130  if(ini.get_preserve_colors()) {
131  ReverseOff();
132  LowVideo();
133  } else {
134  fg = defaultfg;
135  bg = defaultbg;
136  wAttributes = (unsigned char)fg | (bg << 4);
137  reverse = false;
138  }
139 }
140 
141 void TConsole::SetForeground(unsigned char wAttrib) {
142  if(reverse) bg = wAttrib; else fg = wAttrib;
143  wAttributes = (wAttributes & (unsigned char)0x88) |
144  (unsigned char)fg | (bg << 4);
145 }
146 
147 void TConsole::SetBackground(unsigned char wAttrib) {
148  if(reverse) fg = wAttrib; else bg = wAttrib;
149  wAttributes = (wAttributes & (unsigned char)0x88) |
150  (unsigned char)fg | (bg << 4);
151 }
152 
153 // As far as I can tell, there's no such thing as blink in Windows Console.
154 // I tried using some inline asm to turn off high-intensity backgrounds,
155 // but I got a BSOD. Perhaps there is an undocumented function?
156 // (Paul Brannan 6/27/98)
158  blink = 1;
159  if(underline) {
160  UlBlinkOn();
161  } else {
162  if(ini.get_blink_bg() != -1) {
163  wAttributes &= 0x8f; // turn off bg
164  wAttributes |= ini.get_blink_bg() << 4;
165  }
166  if(ini.get_blink_fg() != -1) {
167  wAttributes &= 0xf8; // turn off fg
169  }
170  if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
171  wAttributes |= 0x80;
172  }
173 }
174 
175 // Added by I.Ioannou 06 April, 1997
177  blink = 0;
178  if(underline) {
179  UlBlinkOff();
180  } else {
181  if(ini.get_blink_bg() != -1) {
182  wAttributes &= 0x8f; // turn off bg
183  wAttributes |= defaultbg << 4;
184  }
185  if(ini.get_blink_fg() != -1) {
186  wAttributes &= 0xf8; // turn off fg
188  }
189  if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
190  wAttributes &= 0x7f;
191  }
192 }
193 
194 // Paul Brannan 6/27/98
196  underline = 1;
197  if(blink) {
198  UlBlinkOn();
199  } else {
200  if(ini.get_underline_bg() != -1) {
201  wAttributes &= 0x8f; // turn off bg
202  wAttributes |= ini.get_underline_bg() << 4;
203  }
204  if(ini.get_underline_fg() != -1) {
205  wAttributes &= 0xf8; // turn off fg
207  }
208  if(ini.get_underline_bg() == -1 && ini.get_underline_fg() == -1)
209  wAttributes |= 0x80;
210  }
211 }
212 
213 // Paul Brannan 6/27/98
215  underline = 0;
216  if(blink) {
217  UlBlinkOff();
218  } else {
219  if(ini.get_blink_bg() != -1) {
220  wAttributes &= 0x8f; // turn off bg
221  wAttributes |= defaultbg << 4;
222  }
223  if(ini.get_blink_fg() != -1) {
224  wAttributes &= 0xf8; // turn off fg
226  }
227  if(ini.get_blink_bg() == -1 && ini.get_blink_fg() == -1)
228  wAttributes &= 0x7f;
229  }
230 }
231 
232 // Paul Brannan 6/27/98
234  if(ini.get_ulblink_bg() != -1) {
235  wAttributes &= 0x8f; // turn off bg
236  wAttributes |= ini.get_ulblink_bg() << 4;
237  }
238  if(ini.get_ulblink_fg() != -1) {
239  wAttributes &= 0xf8; // turn off fg
241  }
242  if(ini.get_ulblink_bg() == -1 && ini.get_ulblink_fg() == -1)
243  wAttributes |= 0x80;
244 }
245 
246 // Paul Brannan 6/27/98
248  if(blink) {
249  BlinkOn();
250  } else if(underline) {
251  UnderlineOn();
252  } else {
253  Normal();
254  }
255 }
256 
257 // Paul Brannan 6/26/98
259  WORD *pAttributes = new WORD[CON_COLS];
260  DWORD Result;
261 
262  // Paul Brannan 8/5/98
263  // Correction: processing more than one line at a time causes a segfault
264  // if the screen width != 80
265  for(int i = CON_TOP; i <= CON_BOTTOM; i++) {
266  COORD Coord = {CON_LEFT, i};
267 
269  Coord, &Result);
270 
271  for(DWORD j = 0; j < Result; j++) pAttributes[j] |= 0x80;
272 
273  WriteConsoleOutputAttribute(hConsole, pAttributes, Result, Coord,
274  &Result);
275  }
276 
277  delete[] pAttributes; // clean up
278 
279  wAttributes |= (unsigned char)0x80;
280  bg |= 8;
281 }
282 
283 // Paul Brannan 6/26/98
285  WORD *pAttributes = new WORD[CON_COLS];
286  DWORD Result;
287 
288  // Paul Brannan 8/5/98
289  // Correction: processing more than one line at a time causes a segfault
290  // if the screen width != 80
291  for(int i = CON_TOP; i <= CON_BOTTOM; i++) {
292  COORD Coord = {CON_LEFT, i};
293 
295  Coord, &Result);
296 
297  for(DWORD j = 0; j < Result; j++) pAttributes[j] &= 0x7f;
298 
299  WriteConsoleOutputAttribute(hConsole, pAttributes, Result, Coord,
300  &Result);
301  }
302 
303  delete[] pAttributes; // clean up
304 
305 
306  wAttributes &= (unsigned char)0x7f;
307  bg &= 7;
308 }
309 
310 // Added by I.Ioannou 11.May,1997
312  if (!reverse) {
313  reverse = true;
314 
315  // atl : forground attributes without the intensity
316  // ath : backgound attributes without the blink
317  // bl : the blink state
318  // ints : the intensity
319  unsigned char atl = wAttributes & (unsigned char) 0x07;
320  unsigned char ath = wAttributes & (unsigned char) 0x70;
321  unsigned char bl = wAttributes & (unsigned char) 0x80;
322  unsigned char ints = wAttributes & (unsigned char) 0x08;
323  wAttributes = bl | (atl << 4) | ints | (ath >> 4);
324  }
325 }
326 
327 // Added by I.Ioannou 11.May,1997
329  if (reverse) {
330  reverse = false;
331  wAttributes = fg | (bg << 4);
332  }
333 }
334 
335 unsigned long TConsole::WriteText(const char *pszString, unsigned long cbString) {
336  DWORD Result;
337 
338  if(insert_mode) {
339  InsertCharacter(cbString);
340  }
341 
342  WriteConsoleOutputCharacter(hConsole, (char *)pszString, cbString,
343  ConsoleInfo.dwCursorPosition, &Result);
345  ConsoleInfo.dwCursorPosition, &Result);
346  return Result;
347 }
348 
349 // Formerly ConWriteString (Paul Brannan 6/28/98)
350 unsigned long TConsole::WriteStringFast(const char* pszString, unsigned long cbString) {
351  DWORD Result;
352 
354 
355  //check to see if the line is longer than the display
356  if (!getLineWrap() && ((unsigned)CON_CUR_X + cbString) >= (unsigned)CON_COLS) {
357  // Take care of the last line last colum exception...
358  // The display scrolls up if you use the normal char out
359  // function even if you only write to the last place
360  // on the line. :-(
361  if ((unsigned)CON_CUR_Y >= (unsigned)CON_HEIGHT) {
362  unsigned long iFakeResult = cbString;
363  cbString = CON_COLS - CON_CUR_X - 1;
364 
365  // FIX ME !!! This will avoid the exception when cbString
366  // is <= 0 but still doesn't work :-(
367  if (cbString > 0)
368  WriteConsole(hConsole, pszString, cbString, &Result, 0);
369 
370  COORD dwBufferCoord;
371  dwBufferCoord.X = 0;
372  dwBufferCoord.Y = 0;
373 
374  CHAR_INFO ciBuffer;
375  ciBuffer.Char.AsciiChar = *(pszString+cbString);
376  ciBuffer.Attributes = wAttributes;
377  SMALL_RECT srWriteRegion;
378  srWriteRegion.Top = (SHORT) CON_BOTTOM;
379  srWriteRegion.Bottom = (SHORT) CON_BOTTOM;
380  srWriteRegion.Left = (SHORT) CON_RIGHT;
381  srWriteRegion.Right = (SHORT) CON_RIGHT;
382 
383  COORD bufSize = {1,1};
384 
385  WriteConsoleOutput(hConsole, &ciBuffer, bufSize,
386  dwBufferCoord, &srWriteRegion);
387 
388  // We need to update the ConsoleInfo struct now (Paul Brannan 5/9/98)
390 
391  return iFakeResult; // Skip the chars that did not fit
392  }
393  // just write the line up to the end
394  else {
395  int iFakeResult = cbString;
396  cbString = CON_COLS - CON_CUR_X;
397 
398  if(cbString > 0) {
399  WriteConsole(hConsole, pszString, cbString, &Result, 0);
400 
401  // We need to update the ConsoleInfo struct now (Paul Brannan 5/9/98)
402  ConsoleInfo.dwCursorPosition.X += (unsigned short)Result;
403  }
404 
405  return iFakeResult; // Skip the chars that did not fit
406  }
407  } else {
408  // If custom scrolling is enabled we must take care of it
409  if(iScrollStart != -1 || iScrollEnd != -1) {
410  return WriteString(pszString, cbString);
411  }
412 
413  // Apparently VT100 terminals have an invisible "81st" column that
414  // can hold a cursor until another character is printed. I'm not sure
415  // exactly how to handle this, but here's a hack (Paul Brannan 5/28/98)
416  if(ini.get_vt100_mode() && cbString + (unsigned)CON_CUR_X == (unsigned)CON_COLS) {
417 
418  cbString--;
419  if((long)cbString >= 0) WriteConsole(hConsole, pszString, cbString, &Result, 0);
420 
421  COORD dwBufferCoord;
422  dwBufferCoord.X = 0;
423  dwBufferCoord.Y = 0;
424 
425  CHAR_INFO ciBuffer;
426  ciBuffer.Char.AsciiChar = *(pszString+cbString);
427  ciBuffer.Attributes = wAttributes;
428  SMALL_RECT srWriteRegion;
429  srWriteRegion.Top = (SHORT) ConsoleInfo.dwCursorPosition.Y;
430  srWriteRegion.Bottom = (SHORT) ConsoleInfo.dwCursorPosition.Y;
431  srWriteRegion.Left = (SHORT) CON_RIGHT;
432  srWriteRegion.Right = (SHORT) CON_RIGHT;
433 
434  COORD bufSize = {1,1};
435 
436  WriteConsoleOutput(hConsole, &ciBuffer, bufSize,
437  dwBufferCoord, &srWriteRegion);
438 
439  // Update the ConsoleInfo struct
441 
442  return Result + 1;
443  }
444 
445  // normal line will wrap normally or not to the end of buffer
446  WriteConsole(hConsole, pszString, cbString, &Result, 0);
447 
448  // We need to update the ConsoleInfo struct now (Paul Brannan 5/9/98)
449  // FIX ME!!! This is susceptible to the same problem as above.
450  // (e.g. we write out 160 characters)
451  ConsoleInfo.dwCursorPosition.X += (unsigned short)Result;
452  while(CON_CUR_X > CON_WIDTH) {
454  if((unsigned)CON_CUR_Y < (unsigned)CON_HEIGHT) {
456  } else {
457  // If we aren't at the bottom of the window, then we need to
458  // scroll down (Paul Brannan 4/14/2000)
464  }
465  }
466  }
467  }
468 
469  return Result;
470 
471 }
472 
473 unsigned long TConsole::WriteString(const char* pszString, unsigned long cbString) {
474  DWORD Result = 0;
475 
477 
478  //check to see if the line is longer than the display
479  if (!getLineWrap()){
480  unsigned long iFakeResult = cbString;
481  if((CON_CUR_X + cbString) >= (unsigned int)CON_COLS)
482  cbString = CON_COLS - CON_CUR_X;
483  if(cbString > 0)
484  Result = WriteText(pszString, cbString);
485 
486  // We need to update the ConsoleInfo struct now (Paul Brannan 5/9/98)
487  ConsoleInfo.dwCursorPosition.X += (unsigned short)Result;
489 
490  return iFakeResult; // Skip the chars that did not fit
491  } else {
492  // Write up to the end of the line
493  unsigned long temp = cbString;
494  if((CON_CUR_X + temp) > (unsigned int)CON_COLS) {
495  temp = CON_COLS - CON_CUR_X;
496  } else {
497  Result = WriteText(pszString, temp);
498  ConsoleInfo.dwCursorPosition.X += (unsigned short)Result;
500  return Result;
501  }
502  if(temp > 0) {
503  Result = WriteText(pszString, temp);
504  ConsoleInfo.dwCursorPosition.X += (unsigned short)Result;
505  temp = (unsigned short)Result;
506  }
507 
508  // keep writing lines until we get to less than 80 chars left
509  while((temp + (unsigned int)CON_COLS) < cbString) {
510  index(); // LF
511  ConsoleInfo.dwCursorPosition.X = 0; // CR
512  Result = WriteText(&pszString[temp], CON_COLS);
513  temp += (unsigned short)Result;
514  }
515 
516  // write out the last bit
517  if(temp < cbString) {
518  index();
520  Result = WriteText(&pszString[temp], cbString - temp);
521  temp += (unsigned short)Result;
522  }
523 
524  // Apparently VT100 terminals have an invisible "81st" column that
525  // can hold a cursor until another character is printed. I'm not sure
526  // exactly how to handle this, but here's a hack (Paul Brannan 5/28/98)
527  if(!ini.get_vt100_mode() && cbString + (unsigned)ConsoleInfo.dwCursorPosition.X
528  == (unsigned int)CON_COLS) {
529  index();
531  }
532 
534 
535  return temp;
536  }
537 
538  return 0;
539 }
540 
541 // This is for multi-character control strings (Paul Brannan 6/26/98)
542 unsigned long TConsole::WriteCtrlString(const char *pszString, unsigned long cbString) {
543  unsigned long total = 0;
544  while(total < cbString) {
545  unsigned long Result = WriteCtrlChar(*(pszString + total));
546  if(Result == 0) {
547  Result = WriteStringFast(pszString + total, 1);
548  if(Result == 0) return total;
549  }
550  total += Result;
551  }
552  return total;
553 }
554 
555 // This is for printing single control characters
556 // WriteCtrlString uses this (Paul Brannan 6/26/98)
557 unsigned long TConsole::WriteCtrlChar(char c) {
558  // The console does not handel the CR/LF chars as we might expect
559  // when using color. The attributes are not set correctly, so we
560  // must interpret them manualy to preserve the colors on the screen.
561 
562  unsigned long Result = 0; // just in case (Paul Brannan 6/26/98)
563  switch (c) {
564  case '\x09': // horizontal tab
565  SetCursorPosition((((CON_CUR_X/8)+1)*8), CON_CUR_Y);
566  Result = 1;
567  break;
568 
569  case '\x0a': // line feed
570  index();
571  Result = 1;
572  break;
573  case '\x0d': // carrage return
574  SetCursorPosition(CON_LEFT, CON_CUR_Y); // move to beginning of line
575  Result = 1;
576  break;
577  case '\b': // backspace
578  // Added support for backspace so the cursor position can be changed
579  // (Paul Brannan 5/25/98)
580  MoveCursorPosition(-1, 0);
581  Result = 1;
582  default : // else just write it like normal
583  break;
584  }
585 
586  return Result;
587 }
588 
590  // if on the last line scroll up
591  // This must work with scrolling (Paul Brannan 5/13/98)
592  if(iScrollEnd != -1 && (signed)CON_CUR_Y >= iScrollEnd) {
594  } else if ((iScrollEnd == -1 && (signed)CON_CUR_Y >= (signed)CON_HEIGHT)) {
595  DWORD Result;
596  WriteConsole(hConsole, "\n", 1, &Result, NULL);
597 
598  // If we aren't at the bottom of the buffer, then we need to
599  // scroll down (Paul Brannan 4/14/2000)
604  // SetConsoleWindowInfo(hConsole, TRUE, &ConsoleInfo.srWindow);
605  } else {
606  ClearLine();
607  }
608  } else { // else move cursor down to the next line
610  }
611 }
612 
614  // if on the top line scroll down
615  // This must work with scrolling (Paul Brannan 5/13/98)
616  // We should be comparing against iScrollStart, not iScrollEnd (PB 12/2/98)
617  if (iScrollStart == -1 && (signed)CON_CUR_Y <= 0) {
618  ScrollDown(iScrollStart, -1, 1);
619  } else if (iScrollStart != -1 && (signed)CON_CUR_Y <= iScrollStart) {
621  } else // else move cursor up to the previous line
623 }
624 
625 void TConsole::ScrollDown( int iStartRow , int iEndRow, int bUp ){
626  CHAR_INFO ciChar;
627  SMALL_RECT srScrollWindow;
628 
629  // Correction from I.Ioannou 11 May 1997
630  // check the scroll region
631  if (iStartRow < iScrollStart) iStartRow = iScrollStart;
632 
633  // Correction from I.Ioannou 11 May 1997
634  // this will make Top the CON_TOP
635  if ( iStartRow == -1) iStartRow = 0;
636 
637  // Correction from I.Ioannou 18 Aug 97
638  if ( iEndRow == -1) {
639  if ( iScrollEnd == -1 )
640  iEndRow = CON_HEIGHT;
641  else
642  iEndRow = ((CON_HEIGHT <= iScrollEnd) ? CON_HEIGHT : iScrollEnd);
643  }
644  //
645 
646  if ( iStartRow > CON_HEIGHT) iStartRow = CON_HEIGHT;
647  if ( iEndRow > CON_HEIGHT) iEndRow = CON_HEIGHT;
648 
649  srScrollWindow.Left = (CON_LEFT);
650  srScrollWindow.Right = (SHORT) (CON_RIGHT);
651  srScrollWindow.Top = (SHORT) (CON_TOP + iStartRow );
652  srScrollWindow.Bottom = (SHORT) (CON_TOP + iEndRow); // don't subtract 1 (PB 5/28)
653 
654  ciChar.Char.AsciiChar = ' '; // fill with spaces
655  ciChar.Attributes = wAttributes; // fill with current attrib
656 
657  // This should speed things up (Paul Brannan 9/2/98)
658  COORD dwDestOrg = {srScrollWindow.Left, srScrollWindow.Top + bUp};
659 
660  // Note that iEndRow and iStartRow had better not be equal to -1 at this
661  // point. There are four cases to consider for out of bounds. Two of
662  // these cause the scroll window to be cleared; the others cause the
663  // scroll region to be modified. (Paul Brannan 12/3/98)
664  if(dwDestOrg.Y > CON_TOP + iEndRow) {
665  // We are scrolling past the end of the scroll region, so just
666  // clear the window instead (Paul Brannan 12/3/98)
667  ClearWindow(CON_TOP + iStartRow, CON_TOP + iEndRow);
668  return;
669  } else if(dwDestOrg.Y + (iEndRow-iStartRow+1) < CON_TOP + iStartRow) {
670  // We are scrolling past the end of the scroll region, so just
671  // clear the window instead (Paul Brannan 12/3/98)
672  ClearWindow(CON_TOP + iStartRow, CON_TOP + iEndRow);
673  return;
674  } else if(dwDestOrg.Y < CON_TOP + iStartRow) {
675  // Modify the scroll region (Paul Brannan 12/3/98)
676  dwDestOrg.Y = CON_TOP + iStartRow;
677  srScrollWindow.Top -= bUp;
678  } else if(dwDestOrg.Y + (iEndRow-iStartRow+1) > CON_TOP + iEndRow) {
679  // Modify the scroll region (Paul Brannan 12/3/98)
680  srScrollWindow.Bottom -= bUp;
681  }
682 
683  ScrollConsoleScreenBuffer(hConsole, &srScrollWindow,
684  0, dwDestOrg, &ciChar);
685 }
686 
687 // This allows us to clear the screen with an arbitrary character
688 // (Paul Brannan 6/26/98)
690  DWORD dwWritten;
691  COORD Coord = {CON_LEFT, CON_TOP};
693  (DWORD)(CON_LINES), Coord, &dwWritten);
695  (DWORD)(CON_LINES), Coord, &dwWritten);
696 }
697 
698 // Same as clear screen, but only affects the scroll region
699 void TConsole::ClearWindow(int iStartRow, int iEndRow, char c) {
700  DWORD dwWritten;
701  COORD Coord = {CON_LEFT, CON_TOP + iStartRow};
703  (DWORD)(iEndRow-iStartRow+1), Coord, &dwWritten);
705  (DWORD)(CON_LINES), Coord, &dwWritten);
706 }
707 
708 // Clear from cursor to end of screen
710 {
711  DWORD dwWritten;
712  COORD Coord = {CON_LEFT, CON_TOP + CON_CUR_Y + 1};
714  (DWORD)(CON_HEIGHT - CON_CUR_Y), Coord, &dwWritten);
716  (DWORD)(CON_LINES - CON_CUR_Y), Coord, &dwWritten);
717  ClearEOLine();
718 }
719 
720 // Clear from beginning of screen to cursor
722 {
723  DWORD dwWritten;
724  COORD Coord = {CON_LEFT, CON_TOP};
726  (DWORD)(CON_CUR_Y), Coord, &dwWritten);
728  (DWORD)(CON_CUR_Y), Coord, &dwWritten);
729  ClearBOLine();
730 }
731 
733 {
734  DWORD dwWritten;
735  COORD Coord = {CON_LEFT, CON_TOP + CON_CUR_Y};
737  Coord, &dwWritten);
739  Coord, &dwWritten);
741 }
742 
744 {
745  DWORD dwWritten;
746  COORD Coord = {CON_LEFT + CON_CUR_X, CON_TOP + CON_CUR_Y};
748  (DWORD)(CON_RIGHT - CON_CUR_X) +1, Coord, &dwWritten);
750  Coord, &dwWritten);
752 }
753 
755 {
756  DWORD dwWritten;
757  COORD Coord = {CON_LEFT, CON_TOP + CON_CUR_Y};
759  &dwWritten);
761  Coord, &dwWritten);
763 }
764 
765 
766 // Inserts blank lines to the cursor-y-position
767 // scrolls down the rest. CURSOR MOVEMENT (to Col#1) ???
768 void TConsole::InsertLine(int numlines)
769 {
770  COORD to;
772  SMALL_RECT clip;
773  CHAR_INFO fill;
774  int acty;
775 
776  // Rest of screen would be deleted
777  if ( (acty = GetCursorY()) >= CON_LINES - numlines ) {
778  ClearEOScreen(); // delete rest of screen
779  return;
780  } /* IF */
781 
782  // Else scroll down the part of the screen which is below the
783  // cursor.
784  from.Left = CON_LEFT;
785  from.Top = CON_TOP + (SHORT)acty;
786  from.Right = CON_LEFT + (SHORT)CON_COLS;
787  from.Bottom = CON_TOP + (SHORT)CON_LINES;
788 
789  clip = from;
790  to.X = 0;
791  to.Y = (SHORT)(from.Top + numlines);
792 
793  fill.Char.AsciiChar = ' ';
794  fill.Attributes = 7; // WHICH ATTRIBUTES TO TAKE FOR BLANK LINE ??
795 
796  ScrollConsoleScreenBuffer(hConsole, &from, &clip, to, &fill);
797 } /* InsertLine */
798 
799 // Inserts blank characters under the cursor
800 void TConsole::InsertCharacter(int numchar)
801 {
802  int actx;
804  SMALL_RECT clip;
805  COORD to;
806  CHAR_INFO fill;
807 
808  if ( (actx = GetCursorX()) >= CON_COLS - numchar ) {
809  ClearEOLine();
810  return;
811  } /* IF */
812 
813  from.Left = CON_LEFT + (SHORT)actx;
814  from.Top = CON_TOP + (SHORT)GetCursorY();
815  from.Right = CON_LEFT + (SHORT)CON_COLS;
816  from.Bottom = CON_TOP + (SHORT)from.Top;
817 
818  clip = from;
819  to.X = (SHORT)(actx + numchar);
820  to.Y = from.Top;
821 
822  fill.Char.AsciiChar = ' ';
823  fill.Attributes = wAttributes; // WHICH ATTRIBUTES TO TAKE FOR BLANK CHAR ??
824 
825  ScrollConsoleScreenBuffer(hConsole, &from, &clip, to, &fill);
826 } /* InsertCharacter */
827 
828 // Deletes characters under the cursor
829 // Note that there are cases in which all the following lines should shift by
830 // a character, but we don't handle these. This could break some
831 // VT102-applications, but it shouldn't be too much of an issue.
832 void TConsole::DeleteCharacter(int numchar)
833 {
834  int actx;
836  SMALL_RECT clip;
837  COORD to;
838  CHAR_INFO fill;
839 
840  if ( (actx = GetCursorX()) >= CON_COLS - numchar ) {
841  ClearEOLine();
842  return;
843  } /* IF */
844 
845  from.Left = CON_LEFT + (SHORT)actx;
846  from.Top = CON_TOP + (SHORT)GetCursorY();
847  from.Right = CON_LEFT + (SHORT)CON_COLS;
848  from.Bottom = CON_TOP + from.Top;
849 
850  clip = from;
851  to.X = (SHORT)(actx - numchar);
852  to.Y = from.Top;
853 
854  fill.Char.AsciiChar = ' ';
855  fill.Attributes = wAttributes; // WHICH ATTRIBUTES TO TAKE FOR BLANK CHAR ??
856 
857  ScrollConsoleScreenBuffer(hConsole, &from, &clip, to, &fill);
858 } /* DeleteCharacter */
859 
861  if (x > CON_WIDTH) x = CON_WIDTH;
862  if (x < 0) x = 0;
863  if (y > CON_HEIGHT) y = CON_HEIGHT;
864  if (y < 0) y = 0;
865  COORD Coord = {(short)(CON_LEFT + x), (short)(CON_TOP + y)};
867 
868  // Update the ConsoleInfo struct (Paul Brannan 5/9/98)
871 
872  // bug fix in case we went too far (Paul Brannan 5/25/98)
881 }
882 
883 // The new SetCursorPosition takes scroll regions into consideration
884 // (Paul Brannan 6/27/98)
886  if (x > CON_WIDTH) x = CON_WIDTH;
887  if (x < 0) x = 0;
888  if(iScrollEnd != -1) {
889  if(y > iScrollEnd) y = iScrollEnd;
890  } else {
891  if(y > CON_HEIGHT) y = CON_HEIGHT;
892  }
893  if(iScrollStart != -1) {
894  if(y < iScrollStart) y = iScrollStart;
895  } else {
896  if(y < 0) y = 0;
897  }
898 
899  COORD Coord = {(short)(CON_LEFT + x), (short)(CON_TOP + y)};
901 
902  // Update the ConsoleInfo struct
905 }
906 
909 }
910 
912 {
913  // Probably should do something here...
914  // Should change the screen mode, but do we need this?
915 }
916 
917 void TConsole::SetScroll(int start, int end) {
919  iScrollEnd = end;
920 }
921 
923  if(ini.get_do_beep()) {
924  if(!ini.get_speaker_beep()) printit("\a");
925  else ::Beep(400, 100);
926  }
927 }
928 
929 void TConsole::SetCursorSize(int pct) {
930  CONSOLE_CURSOR_INFO ci = {(pct != 0)?pct:1, pct != 0};
932 }
933 
934 void saveScreen(CHAR_INFO *chiBuffer) {
935  HANDLE hStdout;
937  SMALL_RECT srctReadRect;
938  COORD coordBufSize;
939  COORD coordBufCoord;
940 
941  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
942  GetConsoleScreenBufferInfo(hStdout, &ConsoleInfo);
943 
944  srctReadRect.Top = CON_TOP; /* top left: row 0, col 0 */
945  srctReadRect.Left = CON_LEFT;
946  srctReadRect.Bottom = CON_BOTTOM; /* bot. right: row 1, col 79 */
947  srctReadRect.Right = CON_RIGHT;
948 
949  coordBufSize.Y = CON_BOTTOM-CON_TOP+1;
950  coordBufSize.X = CON_RIGHT-CON_LEFT+1;
951 
952  coordBufCoord.X = CON_TOP;
953  coordBufCoord.Y = CON_LEFT;
954 
956  hStdout, /* screen buffer to read from */
957  chiBuffer, /* buffer to copy into */
958  coordBufSize, /* col-row size of chiBuffer */
959 
960  coordBufCoord, /* top left dest. cell in chiBuffer */
961  &srctReadRect); /* screen buffer source rectangle */
962 }
963 
964 void restoreScreen(CHAR_INFO *chiBuffer) {
965  HANDLE hStdout;
967  SMALL_RECT srctReadRect;
968  COORD coordBufSize;
969  COORD coordBufCoord;
970 
971  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
972  GetConsoleScreenBufferInfo(hStdout, &ConsoleInfo);
973 
974  // restore screen
975  srctReadRect.Top = CON_TOP; /* top left: row 0, col 0 */
976  srctReadRect.Left = CON_LEFT;
977  srctReadRect.Bottom = CON_BOTTOM; /* bot. right: row 1, col 79 */
978  srctReadRect.Right = CON_RIGHT;
979 
980  coordBufSize.Y = CON_BOTTOM-CON_TOP+1;
981  coordBufSize.X = CON_RIGHT-CON_LEFT+1;
982 
983  coordBufCoord.X = CON_TOP;
984  coordBufCoord.Y = CON_LEFT;
986  hStdout, /* screen buffer to write to */
987  chiBuffer, /* buffer to copy from */
988  coordBufSize, /* col-row size of chiBuffer */
989  coordBufCoord, /* top left src cell in chiBuffer */
990  &srctReadRect); /* dest. screen buffer rectangle */
991  // end restore screen
992 
993 }
994 
998  GetConsoleScreenBufferInfo(hStdout, &ConsoleInfo);
999  CHAR_INFO * chiBuffer;
1000  chiBuffer = new CHAR_INFO[(CON_BOTTOM-CON_TOP+1)*(CON_RIGHT-CON_LEFT+1)];
1001  return chiBuffer;
1002 }
1003 
1004 void deleteBuffer(CHAR_INFO* chiBuffer) {
1005  delete[] chiBuffer;
1006 }
1007 
void deleteBuffer(CHAR_INFO *chiBuffer)
Definition: tconsole.cpp:1004
unsigned char fg
Definition: tconsole.h:152
#define CON_LEFT
Definition: tconsole.h:48
void SetBackground(unsigned char wAttrib)
Definition: tconsole.cpp:147
void ClearBOScreen(char c=' ')
Definition: tconsole.cpp:721
GLint GLint GLsizei width
Definition: gl.h:1546
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
int insert_mode
Definition: tconsole.h:162
bool reverse
Definition: tconsole.h:158
CHAR AsciiChar
Definition: wincon.h:170
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: console.c:474
int iScrollEnd
Definition: tconsole.h:161
void ClearScreen(char c=' ')
Definition: tconsole.cpp:689
void DeleteCharacter(int numchar)
Definition: tconsole.cpp:832
int get_blink_bg() const
Definition: tnconfig.h:65
TConsole(HANDLE hConsole)
Definition: tconsole.cpp:56
void sync()
Definition: tconsole.cpp:109
unsigned char defaultfg
Definition: tconsole.h:153
int get_underline_fg() const
Definition: tnconfig.h:68
int get_term_width() const
Definition: tnconfig.h:56
unsigned long WriteCtrlString(const char *pszString, unsigned long cbString)
Definition: tconsole.cpp:542
void UnderlineOn()
Definition: tconsole.cpp:195
void ClearEOLine(char c=' ')
Definition: tconsole.cpp:743
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define CON_LINES
Definition: tconsole.h:53
void SetRawCursorPosition(int x, int y)
Definition: tconsole.cpp:860
#define CON_TOP
Definition: tconsole.h:45
void LowVideo()
Definition: tconsole.cpp:117
#define CON_HEIGHT
Definition: tconsole.h:51
GLuint GLuint end
Definition: gl.h:1545
void Normal()
Definition: tconsole.cpp:121
void index()
Definition: tconsole.cpp:589
#define WriteConsoleOutput
Definition: wincon.h:775
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
Definition: console.c:1857
INT INT y
Definition: msvc.h:62
bool get_vt100_mode() const
Definition: tnconfig.h:47
unsigned long WriteString(const char *pszString, unsigned long cbString)
Definition: tconsole.cpp:473
void saveScreen(CHAR_INFO *chiBuffer)
Definition: tconsole.cpp:934
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
GLuint GLsizei bufSize
Definition: glext.h:6040
GLenum GLclampf GLint i
Definition: glfuncs.h:14
void InsertCharacter(int numchar)
Definition: tconsole.cpp:800
short SHORT
Definition: pedump.c:59
bool get_preserve_colors() const
Definition: tnconfig.h:51
#define CON_WIDTH
Definition: tconsole.h:52
void BlinkOff()
Definition: tconsole.cpp:176
static const struct encodedInt ints[]
Definition: encode.c:48
void UlBlinkOff()
Definition: tconsole.cpp:247
smooth NULL
Definition: ftsmooth.c:416
unsigned char
Definition: typeof.h:27
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
Definition: console.c:590
void Lightbg()
Definition: tconsole.cpp:258
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void SetCursorSize(int pct)
Definition: tconsole.cpp:929
void Darkbg()
Definition: tconsole.cpp:284
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
SHORT Left
Definition: blue.h:25
ULONG X
Definition: bl.h:1340
TConfig ini
Definition: tnconfig.cpp:45
BOOL WINAPI SetConsoleTextAttribute(IN HANDLE hConsoleOutput, IN WORD wAttributes)
Definition: console.c:621
void SetCursorPosition(int x, int y)
Definition: tconsole.cpp:885
int GetCursorY()
Definition: tconsole.h:70
int get_underline_bg() const
Definition: tnconfig.h:67
HANDLE hConsole
Definition: tconsole.h:147
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned char origfg
Definition: tconsole.h:154
void MoveCursorPosition(int x, int y)
Definition: tconsole.cpp:907
SHORT Bottom
Definition: blue.h:28
BOOL WINAPI SetConsoleCursorInfo(IN HANDLE hConsoleOutput, IN const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
Definition: console.c:567
unsigned long WriteStringFast(const char *pszString, unsigned long cbString)
Definition: tconsole.cpp:350
unsigned char origbg
Definition: tconsole.h:154
void BlinkOn()
Definition: tconsole.cpp:157
_STLP_MOVE_TO_STD_NAMESPACE void fill(_ForwardIter __first, _ForwardIter __last, const _Tp &__val)
Definition: _algobase.h:449
void SetForeground(unsigned char wAttrib)
Definition: tconsole.cpp:141
unsigned char defaultbg
Definition: tconsole.h:153
void UlBlinkOn()
Definition: tconsole.cpp:233
BOOL WINAPI DECLSPEC_HOTPATCH ReadConsoleOutputAttribute(IN HANDLE hConsoleOutput, OUT LPWORD lpAttribute, IN DWORD nLength, IN COORD dwReadCoord, OUT LPDWORD lpNumberOfAttrsRead)
Definition: readwrite.c:1424
WORD Attributes
Definition: wincon.h:172
void ScrollDown(int iStartRow, int iEndRow, int bUp)
Definition: tconsole.cpp:625
#define CON_BOTTOM
Definition: tconsole.h:46
CHAR_INFO * newBuffer()
Definition: tconsole.cpp:995
unsigned char bg
Definition: tconsole.h:152
const GLubyte * c
Definition: glext.h:8905
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
int printit(const char *it)
Definition: tnerror.cpp:58
SHORT Top
Definition: blue.h:26
void restoreScreen(CHAR_INFO *chiBuffer)
Definition: tconsole.cpp:964
void ClearBOLine(char c=' ')
Definition: tconsole.cpp:754
void ClearWindow(int start, int end, char c=' ')
Definition: tconsole.cpp:699
void ReverseOn()
Definition: tconsole.cpp:311
void ClearEOScreen(char c=' ')
Definition: tconsole.cpp:709
union _CHAR_INFO::@3144 Char
#define CON_CUR_X
Definition: tconsole.h:56
unsigned long WriteCtrlChar(char c)
Definition: tconsole.cpp:557
int get_term_height() const
Definition: tnconfig.h:57
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
static stack_node_t temp
Definition: rpn.c:18
#define FillConsoleOutputCharacter
Definition: wincon.h:776
void SetWindowSize(int width, int height)
Definition: tconsole.cpp:93
Definition: bl.h:1338
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
int get_normal_bg() const
Definition: tnconfig.h:71
#define ReadConsoleOutput
Definition: wincon.h:768
_In_ BOOL bEnable
Definition: winddi.h:3426
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: tconsole.h:149
#define ScrollConsoleScreenBuffer
Definition: wincon.h:770
INT x
Definition: msvc.h:62
GLuint start
Definition: gl.h:1545
unsigned long WriteText(const char *pszString, unsigned long cbString)
Definition: tconsole.cpp:335
void SetExtendedMode(int iFunction, BOOL bEnable)
Definition: tconsole.cpp:911
#define WriteConsole
Definition: wincon.h:772
bool blink
Definition: tconsole.h:156
int iScrollStart
Definition: tconsole.h:160
bool getLineWrap()
Definition: tconsole.h:135
void HighVideo()
Definition: tconsole.cpp:113
HANDLE hStdout
Definition: ctm.c:56
int GetCursorX()
Definition: tconsole.h:69
void InsertLine(int numlines)
Definition: tconsole.cpp:768
#define CON_RIGHT
Definition: tconsole.h:49
int get_ulblink_bg() const
Definition: tnconfig.h:69
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
#define CON_CUR_Y
Definition: tconsole.h:57
unsigned char wAttributes
Definition: tconsole.h:151
bool underline
Definition: tconsole.h:157
int get_ulblink_fg() const
Definition: tnconfig.h:70
void SetScroll(int start, int end)
Definition: tconsole.cpp:917
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN CONST WORD *lpAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
Definition: readwrite.c:1655
SHORT Right
Definition: blue.h:27
BOOL WINAPI SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, CONST SMALL_RECT *lpConsoleWindow)
Definition: console.c:1972
CardRegion * from
Definition: spigame.cpp:19
#define WriteConsoleOutputCharacter
Definition: wincon.h:777
void reverse_index()
Definition: tconsole.cpp:613
void UnderlineOff()
Definition: tconsole.cpp:214
void ClearLine(char c=' ')
Definition: tconsole.cpp:732
ULONG Y
Definition: bl.h:1341
int get_blink_fg() const
Definition: tnconfig.h:66
void ReverseOff()
Definition: tconsole.cpp:328
bool get_do_beep() const
Definition: tnconfig.h:50
void Beep()
Definition: tconsole.cpp:922
int get_normal_fg() const
Definition: tnconfig.h:72
~TConsole()
Definition: tconsole.cpp:85
bool get_speaker_beep() const
Definition: tnconfig.h:49
#define CON_COLS
Definition: tconsole.h:54
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4507