Sha256: 3fa326587d48cd86afbc411fd6f2f5f63ab96903c1ba4a8bffdd542677018191

Contents?: true

Size: 867 Bytes

Versions: 16

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Input

    # Handle input when terminal is in :raw (character at a time)
    # mode.
    #
    # @api private
    #
    class Raw

      # @see Vedeu::Input::Raw#initialize
      def self.read
        new.read
      end

      # Returns a new instance of Vedeu::Input::Raw.
      #
      # @return [Vedeu::Input::Raw]
      def initialize; end

      # @return [String]
      def read
        keys = console.getch

        if keys.ord == Vedeu::ESCAPE_KEY_CODE
          keys << console.read_nonblock(4) rescue nil
          keys << console.read_nonblock(3) rescue nil
          keys << console.read_nonblock(2) rescue nil
        end

        keys
      end

      private

      # @return [IO]
      def console
        @_console ||= Vedeu::Terminal.console
      end

    end # Raw

  end # Input

end # Vedeu

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/input/raw.rb
vedeu-0.8.31 lib/vedeu/input/raw.rb
vedeu-0.8.30 lib/vedeu/input/raw.rb
vedeu-0.8.29 lib/vedeu/input/raw.rb
vedeu-0.8.28 lib/vedeu/input/raw.rb
vedeu-0.8.27 lib/vedeu/input/raw.rb
vedeu-0.8.26 lib/vedeu/input/raw.rb
vedeu-0.8.25 lib/vedeu/input/raw.rb
vedeu-0.8.24 lib/vedeu/input/raw.rb
vedeu-0.8.23 lib/vedeu/input/raw.rb
vedeu-0.8.22 lib/vedeu/input/raw.rb
vedeu-0.8.21 lib/vedeu/input/raw.rb
vedeu-0.8.20 lib/vedeu/input/raw.rb
vedeu-0.8.19 lib/vedeu/input/raw.rb
vedeu-0.8.18 lib/vedeu/input/raw.rb
vedeu-0.8.17 lib/vedeu/input/raw.rb