Sha256: e8d3381a905596e730cee931804d8dae30059c5ef7be4d6e471c403e30fda9f3

Contents?: true

Size: 764 Bytes

Versions: 8

Compression:

Stored size: 764 Bytes

Contents

# frozen_string_literal: true

require 'io/console'

module TTY
  class Reader
    class Mode
      # Initialize a Terminal
      #
      # @api public
      def initialize(input = $stdin)
        @input = input
      end

      # Echo given block
      #
      # @param [Boolean] is_on
      #
      # @api public
      def echo(is_on = true, &block)
        if is_on || !@input.tty?
          yield
        else
          @input.noecho(&block)
        end
      end

      # Use raw mode in the given block
      #
      # @param [Boolean] is_on
      #
      # @api public
      def raw(is_on = true, &block)
        if is_on && @input.tty?
          @input.raw(&block)
        else
          yield
        end
      end
    end # Mode
  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/mode.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/mode.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/mode.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/mode.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/lib/tty/reader/mode.rb
tty-reader-0.7.0 lib/tty/reader/mode.rb
tty-reader-0.6.0 lib/tty/reader/mode.rb
tty-reader-0.5.0 lib/tty/reader/mode.rb