fpdpansi.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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;var f : text) : boolean;
  18. implementation
  19. uses
  20. wutils;
  21. const
  22. { Foreground and background color constants }
  23. Black = 0;
  24. Blue = 1;
  25. Green = 2;
  26. Cyan = 3;
  27. Red = 4;
  28. Magenta = 5;
  29. Brown = 6;
  30. LightGray = 7;
  31. const ColorTab : array[0..7] of byte =
  32. (Black,Red,Green,Brown,Blue,Magenta,Cyan,LightGray);
  33. {$i-}
  34. function ExportBufferToAnsiFile(var Buffer : TVideoBuf;xmin,xmax,ymin,ymax,linesize : sw_integer;var f : text) : boolean;
  35. var
  36. CurColor : byte;
  37. CurForColor, CurBackColor : byte;
  38. CurIsBold, CurIsBlinking : boolean;
  39. procedure ChangeColor(NewColor : byte);
  40. var
  41. ForColor, BackColor : byte;
  42. IsBold, IsBlinking : boolean;
  43. begin
  44. ForColor:=NewColor and 7;
  45. BackColor:=(NewColor and $70) shr 4;
  46. IsBold:=(NewColor and 8) <> 0;
  47. IsBlinking:=(NewColor and $80) <> 0;
  48. if IsBlinking<>CurIsBlinking then
  49. begin
  50. if IsBlinking then
  51. Write(f,#27'[5m')
  52. else
  53. Write(f,#27'[25m');
  54. CurIsBlinking:=IsBlinking;
  55. end;
  56. if IsBold<>CurIsBold then
  57. begin
  58. if IsBold then
  59. Write(f,#27'[1m')
  60. else
  61. Write(f,#27'[21m');
  62. CurIsBold:=IsBold;
  63. end;
  64. if CurForColor<>ForColor then
  65. begin
  66. Write(f,#27'['+inttostr(ColorTab[ForColor]+30)+'m');
  67. CurForColor:=ForColor;
  68. end;
  69. if CurBackColor<>BackColor then
  70. begin
  71. Write(f,#27'['+inttostr(ColorTab[BackColor]+40)+'m');
  72. CurBackColor:=BackColor;
  73. end;
  74. CurColor:=NewColor;
  75. end;
  76. var
  77. Ch : char;
  78. textAttr : byte;
  79. i, j : sw_integer;
  80. begin
  81. for i:=ymin to ymax do
  82. begin
  83. for j:=xmin to xmax do
  84. begin
  85. ch:=chr(Buffer[i*linesize+j] and $ff);
  86. textattr:=Buffer[i*linesize+j] shr 8;
  87. if textattr<>CurColor then
  88. ChangeColor(textattr);
  89. Write(f,ch);
  90. end;
  91. writeln(f);
  92. end;
  93. ExportBufferToAnsiFile:=(IOResult=0);
  94. end;
  95. end.
  96. {
  97. $Log$
  98. Revision 1.1 2001-08-04 11:30:23 peter
  99. * ide works now with both compiler versions
  100. Revision 1.1.2.1 2000/11/21 17:43:24 pierre
  101. + first version of dump ansi file
  102. Revision 1.1 2000/07/13 09:48:36 michael
  103. + Initial import
  104. Revision 1.4 2000/06/07 06:17:14 pierre
  105. * New templates from Gabor
  106. Revision 1.1 1999/02/19 15:37:26 peter
  107. + init
  108. }