home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
MAI
/
ANSISAVE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
3KB
|
87 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 90 of 132
From : Eric Miller 1:387/307.0 02 May 93 20:29
To : Steven Tallent
Subj : Screen to ansi
────────────────────────────────────────────────────────────────────────────────
{ quoted from carbon unit Steven Tallent to Stephen Cheok
about Re: Screen to ansi on 04-30-93 06:47
ST> This is a procedure I translated from one of my old QuickBASIC
ST> programs. This color processing is, to say the least, unoptimized, but
ST> it'll give you the basic idea and you can go from there... like adding
ST> more than 25-line support, adding maximum line depths, and optimizing
ST> the color code output.
I rewrote your code into a procedure that actually works in
TP (just to save you time...not!) Now it works well, but the
only probably I have is setting the max line length for the output
file (like TheDraw does) }
PROGRAM Ansi_Save_Screen;
{ This program saves a color text screen to an ANSI text file.
}
Uses Dos;
PROCEDURE SaveANSI (Filename: PathStr);
CONST Esc = #27;
MaxCol = 80;
AnsiCols: array[0..7] of char = '04261537';
TYPE
TCell = RECORD C: Char; A: byte; END;
TScreen = array[1..25, 1..80] of TCell;
VAR
Screen: TSCreen ABSOLUTE $B800:0;
F: text;
X, Y, LastF, LastB, TempF, TempB: byte;
S: String;
Blink, Bright: boolean;
BEGIN
Assign(F, filename);
Rewrite(F);
S := Esc+'[2J'+Esc+'[0m';
Write(F, S);
LastF := Screen[Y, X].A MOD 16;
LastB := Screen[Y, X].A SHR 4;
Blink := (LastB AND 8) = 8;
Bright := (LAstF AND 8) = 8;
S := '';
FOR Y := 1 TO 25 DO
BEGIN
FOR X := 1 TO 80 DO
BEGIN
TempF := Screen[Y, X].A MOD 16;
TempB := Screen[Y, X].A SHR 4;
IF (LastB <> TempB) OR (LastF <> TempF) THEN
BEGIN
LastB := TempB;
LastF := TempF;
S := Concat(S, Esc+'[0;');
IF (LastF AND 8) = 8 THEN
IF NOT Bright THEN
BEGIN
S := Concat(S, '1;');
Bright := True;
END;
IF (LastB AND 8) = 8 THEN S := Concat(S, '5;');
LastF := LastF AND 7;
LastB := LAstB AND 7;
S := Concat(S, '3'+AnsiCols[LastF]+';4'+AnsiCols[LastB]+'m');
END;
S := Concat(S, Screen[Y, X].C);
IF Length(S) >= MaxCol THEN
BEGIN
Write(F, S);
Writeln(F,Esc+'[s');
Write(F, Esc+'[u');
S := '';
END;
END;
END;
Write(F, Esc+'[0;37;40m');
Close(F);
END;
BEGIN
SaveANSI('test3.ans');
END.