Sha256: 17e8aef01112abd1b0b56c5a05f1d03bee1269a53cb6f648d766c9eacbe784f9

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'fiddle'

module TTY
  class Reader
    module WinAPI
      include Fiddle

      CRT_HANDLE = Fiddle::Handle.new("msvcrt") rescue Fiddle::Handle.new("crtdll")

      # Get a character from the console without echo.
      #
      # @return [String]
      #   return the character read
      #
      # @api public
      def getch
        @@getch ||= Fiddle::Function.new(CRT_HANDLE["_getch"], [], TYPE_INT)
        @@getch.call
      end
      module_function :getch

      # Gets a character from the console with echo.
      #
      # @return [String]
      #   return the character read
      #
      # @api public
      def getche
        @@getche ||= Fiddle::Function.new(CRT_HANDLE["_getche"], [], TYPE_INT)
        @@getche.call
      end
      module_function :getche

      # Check the console for recent keystroke. If the function
      # returns a nonzero value, a keystroke is waiting in the buffer.
      #
      # @return [Integer]
      #   return a nonzero value if a key has been pressed. Otherwirse,
      #   it returns 0.
      #
      # @api public
      def kbhit
        @@kbhit ||= Fiddle::Function.new(CRT_HANDLE["_kbhit"], [], TYPE_INT)
        @@kbhit.call
      end
      module_function :kbhit
    end # WinAPI
  end # Reader
end # TTY

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/win_api.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/win_api.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/win_api.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/win_api.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/win_api.rb
tty-reader-0.7.0 lib/tty/reader/win_api.rb
tty-reader-0.6.0 lib/tty/reader/win_api.rb
tty-reader-0.5.0 lib/tty/reader/win_api.rb