Module: Kernel::API

Defined in:
lib/read-password.rb

Constant Summary collapse

GetStdHandle =
Win32API.new('kernel32', 'GetStdHandle', ['l'], 'p')
GetConsoleMode =
Win32API.new('kernel32', 'GetConsoleMode', ['l', 'p'], 'l')
SetConsoleMode =
Win32API.new('kernel32', 'SetConsoleMode', ['l', 'l'], 'l')
ReadConsole =
Win32API.new('kernel32', 'ReadConsole', ['l', 'p', 'l', 'p', 'p'], 'l')

Class Method Summary collapse

Class Method Details

.get_console_mode(handle) ⇒ Object



16
17
18
19
20
# File 'lib/read-password.rb', line 16

def get_console_mode(handle)
  lp_mode = ' ' * 4
  GetConsoleMode.call(handle, lp_mode)
  lp_mode.unpack('L').first
end

.get_std_handle(handle) ⇒ Object



12
13
14
# File 'lib/read-password.rb', line 12

def get_std_handle(handle)
  GetStdHandle.call(handle)
end

.read_console(handle, n) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/read-password.rb', line 26

def read_console(handle, n)
  buf = ' ' * n
  nocr = ' ' * 4
  reserved = ' ' * 4
  ReadConsole.call(handle, buf, n, nocr, reserved)
  buf
end

.set_console_mode(handle, lp_mode) ⇒ Object



22
23
24
# File 'lib/read-password.rb', line 22

def set_console_mode(handle, lp_mode)
  SetConsoleMode.call(handle, lp_mode)
end