Sha256: 5bcc98792461b92b27d9739b75d33bc6fbcb868422cdd6d2e220ae2f93fc2c1c

Contents?: true

Size: 782 Bytes

Versions: 4

Compression:

Stored size: 782 Bytes

Contents

# encoding: utf-8
# 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

4 entries across 4 versions & 1 rubygems

Version Path
tty-reader-0.4.0 lib/tty/reader/mode.rb
tty-reader-0.3.0 lib/tty/reader/mode.rb
tty-reader-0.2.0 lib/tty/reader/mode.rb
tty-reader-0.1.0 lib/tty/reader/mode.rb