fpdpansi.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {
  2. $Id$
  3. This file is part of text IDE
  4. Copyright (c) 2000 by Pierre Muller
  5. Unit to export current screen buffer to an ansi file
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit fpdpansi;
  13. interface
  14. uses
  15. objects,
  16. video;
  17. function ExportBufferToAnsiFile(var Buffer : TVideoBuf;xmin,xmax,ymin,ymax,linesize : sw_integer;
  18. SaveAsText : boolean;var f : text) : boolean;
  19. implementation
  20. uses
  21. wutils;
  22. const
  23. { Foreground and background color constants }
  24. Black = 0;
  25. Blue = 1;
  26. Green = 2;
  27. Cyan = 3;
  28. Red = 4;
  29. Magenta = 5;
  30. Brown = 6;
  31. LightGray = 7;
  32. const ColorTab : array[0..7] of byte =
  33. (Black,Red,Green,Brown,Blue,Magenta,Cyan,LightGray);
  34. {$i-}
  35. function ExportBufferToAnsiFile(var Buffer : TVideoBuf;xmin,xmax,ymin,ymax,linesize : sw_integer;
  36. SaveAsText : boolean;var f : text) : boolean;
  37. var
  38. CurColor : byte;
  39. CurForColor, CurBackColor : byte;
  40. CurIsBold, CurIsBlinking : boolean;
  41. procedure ChangeColor(NewColor : byte);
  42. var
  43. ForColor, BackColor : byte;
  44. IsBold, IsBlinking : boolean;
  45. begin
  46. ForColor:=NewColor and 7;
  47. BackColor:=(NewColor and $70) shr 4;
  48. IsBold:=(NewColor and 8) <> 0;
  49. IsBlinking:=(NewColor and $80) <> 0;
  50. if IsBlinking<>CurIsBlinking then
  51. begin
  52. if IsBlinking then
  53. Write(f,#27'[5m')
  54. else
  55. Write(f,#27'[25m');
  56. CurIsBlinking:=IsBlinking;
  57. end;
  58. if IsBold<>CurIsBold then
  59. begin
  60. if IsBold then
  61. Write(f,#27'[1m')
  62. else
  63. Write(f,#27'[21m');
  64. CurIsBold:=IsBold;
  65. end;
  66. if CurForColor<>ForColor then
  67. begin
  68. Write(f,#27'['+inttostr(ColorTab[ForColor]+30)+'m');
  69. CurForColor:=ForColor;
  70. end;
  71. if CurBackColor<>BackColor then
  72. begin
  73. Write(f,#27'['+inttostr(ColorTab[BackColor]+40)+'m');
  74. CurBackColor:=BackColor;
  75. end;
  76. CurColor:=NewColor;
  77. end;
  78. var
  79. Ch : char;
  80. textAttr : byte;
  81. i, j : sw_integer;
  82. begin
  83. CurColor:=0;
  84. for i:=ymin to ymax do
  85. begin
  86. for j:=xmin to xmax do
  87. begin
  88. ch:=chr(Buffer[i*linesize+j] and $ff);
  89. textattr:=Buffer[i*linesize+j] shr 8;
  90. if (textattr<>CurColor) and not SaveAsText then
  91. ChangeColor(textattr);
  92. { Escape escape, by printing two #27 PM }
  93. if (ch=#27) or (ord(ch)<=16) then
  94. Write(f,#27);
  95. Write(f,ch);
  96. end;
  97. writeln(f);
  98. end;
  99. ExportBufferToAnsiFile:=(IOResult=0);
  100. end;
  101. end.
  102. {
  103. $Log$
  104. Revision 1.3 2002-03-25 11:51:43 pierre
  105. * Escape Escape and chars ord(char)<=16
  106. Revision 1.2 2001/11/15 13:30:14 pierre
  107. + save ansi dump as text is filename suffix is '.txt'
  108. Revision 1.1 2001/08/04 11:30:23 peter
  109. * ide works now with both compiler versions
  110. Revision 1.1.2.1 2000/11/21 17:43:24 pierre
  111. + first version of dump ansi file
  112. Revision 1.1 2000/07/13 09:48:36 michael
  113. + Initial import
  114. Revision 1.4 2000/06/07 06:17:14 pierre
  115. * New templates from Gabor
  116. Revision 1.1 1999/02/19 15:37:26 peter
  117. + init
  118. }