This library is based of HighLine's SystemExtensions by James Edward Gray II.
Copyright 2006 Gray Productions
Distributed under the tems of the Ruby software license.
# File lib/ansi/terminal/win32.rb, line 78 def GetConsoleMode( console_handle ) @@apiGetConsoleMode ||= Win32API.new( "kernel32", "GetConsoleMode", ['L', 'P'], 'I' ) mode = ' ' * 4 @@apiGetConsoleMode.call(console_handle, mode) mode.unpack('L')[0] end
# File lib/ansi/terminal/win32.rb, line 94 def GetConsoleScreenBufferInfo( console_handle ) @@apiGetConsoleScreenBufferInfo ||= Win32API.new( "kernel32", "GetConsoleScreenBufferInfo", ['L', 'P'], 'L' ) format = 'SSSSSssssSS' buf = ([0] * format.size).pack(format) @@apiGetConsoleScreenBufferInfo.call(console_handle, buf) buf.unpack(format) end
# File lib/ansi/terminal/win32.rb, line 71 def GetStdHandle( handle_type ) @@apiGetStdHandle ||= Win32API.new( "kernel32", "GetStdHandle", ['L'], 'L' ) @@apiGetStdHandle.call( handle_type ) end
windows savvy console echo toggler
# File lib/ansi/terminal/win32.rb, line 38 def SetConsoleEcho( console_handle, on ) mode = GetConsoleMode(console_handle) # toggle the console echo bit if on mode |= ENABLE_ECHO_INPUT else mode &= ~ENABLE_ECHO_INPUT end ok = SetConsoleMode(console_handle, mode) end
# File lib/ansi/terminal/win32.rb, line 87 def SetConsoleMode( console_handle, mode ) @@apiSetConsoleMode ||= Win32API.new( "kernel32", "SetConsoleMode", ['L', 'L'], 'I' ) @@apiSetConsoleMode.call(console_handle, mode) != 0 end
Curses savvy getc().
# File lib/ansi/terminal/curses.rb, line 14 def get_character(input = STDIN) Curses.getch() end
Switched the input mode to raw and disables echo.
WARNING: This method requires the external "stty" program!
# File lib/ansi/terminal/stty.rb, line 31 def raw_no_echo_mode @state = `stty -g` system "stty raw -echo cbreak isig" end
Restores a previously saved input mode.
WARNING: This method requires the external "stty" program!
# File lib/ansi/terminal/stty.rb, line 41 def restore_mode system "stty #{@state}" end
Console screen width (taken from progress bar)
NOTE: Don't know how portable screen_width is. TODO: How to fit into system?
# File lib/ansi/terminal/termios.rb, line 50 def screen_width(out=STDERR) default_width = ENV['COLUMNS'] || 76 begin tiocgwinsz = 0x5413 data = [0, 0, 0, 0].pack("SSSS") if out.ioctl(tiocgwinsz, data) >= 0 then rows, cols, xpixels, ypixels = data.unpack("SSSS") if cols >= 0 then cols else default_width end else default_width end rescue Exception default_width end end
Get the height of the terminal window.
# File lib/ansi/terminal.rb, line 37 def terminal_height terminal_size.last end
Generated with the Darkfish Rdoc Generator 2.