[comp.lang.pascal] Inversing Text Colors in Turbo Pascal

austin@bucsf.bu.edu (Austin Ziegler) (10/22/89)

  In article <40680@bu-cs.BU.EDU>, tasos@bu-cs.BU.EDU (Anastasiso
Kotsikonas) writes: 
AK> Does anyone know how to write characters in reverse video in Turbo Pascal
AK> using the crt unit? I know it doesn't work with the usual escape sequence.
AK> Strangly enough, the escape sequence works without the crt unit.

  In article <3341@nmtsun.nmt.edu> jrwsnsr@nmtsun.nmt.edu (Jonathan R.
Watts) responds:  
JRW>To write reverse video in TP you could use
JRW>    TextAttr := (TextAttr shr 4) + (TextAttr shl 4);
[disadvantage is that high-intensity becomes blink and blink becomes high
 intensity]

  On 18 Oct 89 16:23:15 GMT, zougas@me.utoronto.ca ("Athanasios(Tom)
Zougas") said:  
Tom> A better way is to set
Tom> 	directvideo := false;
[because it then allows ANSI to decode the strings]
 
   Even better would be to use the CRT unit, and, if you know the colors
(which most of us do), actually set the colors using TextBackground and
TextColor.  In your own unit, include the following three functions
 
FUNCTION GetBackground: BYTE;
 
 BEGIN  { Get the current background color }
  GetBackground:=TextAttr SHR 4;
 END; { GetBackground }
 
FUNCTION GetColor: BYTE;
 
 BEGIN { Get the current foreground color }
  GetColor:=(TextAttr SHL 4) SHR 4;
 END; { GetColor }
 
PROCEDURE ReverseColors;
 
  VAR Fg, Bg: BYTE;
      High, Blinc: BOOLEAN;
 
 BEGIN { Reverse the colors retaining high intensity and blink }
  Fg:=GetColor;
  Bg:=GetBackground;
  High:=FALSE;
  Blinc:=FALSE;
  IF Fg > 7 { Strip the high intensity }
   THEN 
    BEGIN
     Dec (Fg,8);
     High:=TRUE;
    END;
  IF Bg > 7 { Strip the blink }
   THEN 
    BEGIN
     Dec (Bg,8);
     Blinc:=TRUE;
    END;
  IF High
   THEN Inc (Bg,8); { High intensity if the last color was high intensity }
  IF Blinc
   THEN Inc (Fg,8); { Blink if the last color was blinking }
  TextColor (Bg);
  TextBackground (Fg);
 END; { ReverseColors }
 
  These three should fix the problem.  If you want Blink and High-intensity
ignored, change the BEGIN-ENDs in the IF Bg > 8 and IF Fg > 8 to only the
two Dec statements and remove the IF High and IF Blinc statements.
 
	  Elminster, the Sage of Shadowdale (austin@bucsf.bu.edu)
	       700 Commonwealth Box 2094, Boston, MA  02215
 
       (current .sig in question, new one to be started any day now)