wconsole.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. {$ifdef aros}
  41. longint
  42. {$endif aros}
  43. ;
  44. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  45. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  46. implementation
  47. {$ifdef Windows}
  48. uses
  49. wutils,
  50. windows;
  51. {$endif Windows}
  52. {$ifdef GO32V2}
  53. uses
  54. Dpmiexcp;
  55. {$endif GO32V2}
  56. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  57. Begin
  58. {$ifdef UNIX}
  59. TCGetAttr(1,ConsoleMode);
  60. {$endif UNIX}
  61. {$ifdef Windows}
  62. if not GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  63. DebugMessage('','Call to GetConsoleMode failed, GetLastError='+
  64. IntToStr(GetLastError),0,0);
  65. {$endif Windows}
  66. {$ifdef go32v2}
  67. if djgpp_set_ctrl_c(false) then
  68. ConsoleMode:=1
  69. else
  70. ConsoleMode:=0;
  71. {$endif go32v2}
  72. {$ifdef netware}
  73. ConsoleMode:=0;
  74. {$endif}
  75. End;
  76. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  77. Begin
  78. {$ifdef UNIX}
  79. TCSetAttr(1,TCSANOW,ConsoleMode);
  80. {$endif UNIX}
  81. {$ifdef Windows}
  82. if not SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  83. DebugMessage('','Call to SetConsoleMode failed, GetLastError='+
  84. IntToStr(GetLastError),0,0);
  85. {$endif Windows}
  86. {$ifdef go32v2}
  87. djgpp_set_ctrl_c((ConsoleMode and 1)<>0);
  88. {$endif go32v2}
  89. End;
  90. end.