Sha256: a37cf8bbb0adc47f200389bbbdc3c919e31da6655f320a6cc4241750fd582cdb

Contents?: true

Size: 850 Bytes

Versions: 4

Compression:

Stored size: 850 Bytes

Contents

# encoding: utf-8

require 'io/console'

module TTY
  class Prompt
    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 # Prompt
end # TTY

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
tty-prompt-0.13.1 lib/tty/prompt/reader/mode.rb
tty-prompt-0.13.0 lib/tty/prompt/reader/mode.rb
austb-tty-prompt-0.13.0 lib/tty/prompt/reader/mode.rb
tty-prompt-0.12.0 lib/tty/prompt/reader/mode.rb