diff options
Diffstat (limited to 'lib/highline/terminal/windows_dl_import.rb')
-rw-r--r-- | lib/highline/terminal/windows_dl_import.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/highline/terminal/windows_dl_import.rb b/lib/highline/terminal/windows_dl_import.rb new file mode 100644 index 0000000..721f048 --- /dev/null +++ b/lib/highline/terminal/windows_dl_import.rb @@ -0,0 +1,37 @@ +# coding: utf-8 + +class HighLine + module SystemExtensions + module WindowsDlImport + require "dl/import" + + module WinAPI + if defined?(DL::Importer) + # Ruby 1.9 + extend DL::Importer + else + # Ruby 1.8 + extend DL::Importable + end + begin + dlload "msvcrt", "kernel32" + rescue DL::DLError + dlload "crtdll", "kernel32" + end + extern "unsigned long _getch()" + extern "unsigned long GetConsoleScreenBufferInfo(unsigned long, void*)" + extern "unsigned long GetStdHandle(unsigned long)" + + # Ruby 1.8 DL::Importable.import does mname[0,1].downcase so FooBar becomes fooBar + if defined?(getConsoleScreenBufferInfo) + alias_method :GetConsoleScreenBufferInfo, :getConsoleScreenBufferInfo + module_function :GetConsoleScreenBufferInfo + end + if defined?(getStdHandle) + alias_method :GetStdHandle, :getStdHandle + module_function :GetStdHandle + end + end + end + end +end |