wconsole.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. {$H-}
  13. interface
  14. {$ifdef UNIX}
  15. uses
  16. termio;
  17. {$endif UNIX}
  18. type
  19. TConsoleMode =
  20. {$ifdef OS2}
  21. dword
  22. {$endif OS2}
  23. {$ifdef UNIX}
  24. TermIos
  25. {$endif UNIX}
  26. {$ifdef Windows}
  27. dword
  28. {$endif Windows}
  29. {$ifdef go32v2}
  30. longint
  31. {$endif go32v2}
  32. {$ifdef netware}
  33. longint
  34. {$endif netware}
  35. {$ifdef amiga}
  36. longint
  37. {$endif amiga}
  38. {$ifdef morphos}
  39. longint
  40. {$endif morphos}
  41. {$ifdef aros}
  42. longint
  43. {$endif aros}
  44. ;
  45. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  46. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  47. implementation
  48. {$ifdef Windows}
  49. uses
  50. wutils,
  51. windows;
  52. {$endif Windows}
  53. {$ifdef GO32V2}
  54. uses
  55. Dpmiexcp;
  56. {$endif GO32V2}
  57. Procedure SaveConsoleMode(var ConsoleMode : TConsoleMode);
  58. Begin
  59. {$ifdef UNIX}
  60. TCGetAttr(1,ConsoleMode);
  61. {$endif UNIX}
  62. {$ifdef Windows}
  63. if not GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  64. DebugMessage('','Call to GetConsoleMode failed, GetLastError='+
  65. IntToStr(GetLastError),0,0);
  66. {$endif Windows}
  67. {$ifdef go32v2}
  68. if djgpp_set_ctrl_c(false) then
  69. ConsoleMode:=1
  70. else
  71. ConsoleMode:=0;
  72. {$endif go32v2}
  73. {$ifdef netware}
  74. ConsoleMode:=0;
  75. {$endif}
  76. End;
  77. Procedure RestoreConsoleMode(const ConsoleMode : TConsoleMode);
  78. Begin
  79. {$ifdef UNIX}
  80. TCSetAttr(1,TCSANOW,ConsoleMode);
  81. {$endif UNIX}
  82. {$ifdef Windows}
  83. if not SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ConsoleMode) then
  84. DebugMessage('','Call to SetConsoleMode failed, GetLastError='+
  85. IntToStr(GetLastError),0,0);
  86. {$endif Windows}
  87. {$ifdef go32v2}
  88. djgpp_set_ctrl_c((ConsoleMode and 1)<>0);
  89. {$endif go32v2}
  90. End;
  91. end.