Sha256: a8c765296426cc482f4f0699dcfa45534f18245ccfbd119cb4477253061ae1dc

Contents?: true

Size: 866 Bytes

Versions: 15

Compression:

Stored size: 866 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

15 entries across 15 versions & 1 rubygems

Version Path
vedeu-0.8.16 lib/vedeu/input/raw.rb
vedeu-0.8.15 lib/vedeu/input/raw.rb
vedeu-0.8.14 lib/vedeu/input/raw.rb
vedeu-0.8.13 lib/vedeu/input/raw.rb
vedeu-0.8.12 lib/vedeu/input/raw.rb
vedeu-0.8.10 lib/vedeu/input/raw.rb
vedeu-0.8.9 lib/vedeu/input/raw.rb
vedeu-0.8.8 lib/vedeu/input/raw.rb
vedeu-0.8.7 lib/vedeu/input/raw.rb
vedeu-0.8.6 lib/vedeu/input/raw.rb
vedeu-0.8.5 lib/vedeu/input/raw.rb
vedeu-0.8.4 lib/vedeu/input/raw.rb
vedeu-0.8.3 lib/vedeu/input/raw.rb
vedeu-0.8.2 lib/vedeu/input/raw.rb
vedeu-0.8.1 lib/vedeu/input/raw.rb