wconsole.pas 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 2001 by Pierre Muller
  4. This unit is used to save and restore console modes
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit WConsole;
  12. interface
  13. {$ifdef UNIX}
  14. uses
  15. termio;
  16. {$endif UNIX}
  17. type
  18. TConsoleMode =
  19. {$ifdef OS2}
  20. dword
  21. {$endif OS2}
  22. {$ifdef UNIX}
  23. TermIos
  24. {$endif UNIX}
  25. {$ifdef Windows}
  26. dword
  27. {$endif Windows}
  28. {$ifdef go32v2}
  29. longint
  30. {$endif go32v2}
  31. {$ifdef netware}
  32. longint
  33. {$endif netware}
  34. {$ifdef amiga}
  35. longint
  36. {$endif amiga}
  37. {$ifdef morphos}
  38. longint
  39. {$endif morphos}
  40. ;
  41. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  42. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  43. implementation
  44. {$ifdef Windows}
  45. uses
  46. wutils,
  47. windows;
  48. {$endif Windows}
  49. {$ifdef GO32V2}
  50. uses
  51. Dpmiexcp;
  52. {$endif GO32V2}
  53. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  54. Begin
  55. {$ifdef UNIX}
  56. TCGetAttr(1,ConsoleMode);
  57. {$endif UNIX}
  58. {$ifdef Windows}
  59. if not GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  60. DebugMessage('','Call to GetConsoleMode failed, GetLastError='+
  61. IntToStr(GetLastError),0,0);
  62. {$endif Windows}
  63. {$ifdef go32v2}
  64. if djgpp_set_ctrl_c(false) then
  65. ConsoleMode:=1
  66. else
  67. ConsoleMode:=0;
  68. {$endif go32v2}
  69. {$ifdef netware}
  70. ConsoleMode:=0;
  71. {$endif}
  72. End;
  73. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  74. Begin
  75. {$ifdef UNIX}
  76. TCSetAttr(1,TCSANOW,ConsoleMode);
  77. {$endif UNIX}
  78. {$ifdef Windows}
  79. if not SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  80. DebugMessage('','Call to SetConsoleMode failed, GetLastError='+
  81. IntToStr(GetLastError),0,0);
  82. {$endif Windows}
  83. {$ifdef go32v2}
  84. djgpp_set_ctrl_c((ConsoleMode and 1)<>0);
  85. {$endif go32v2}
  86. End;
  87. end.