Sha256: 0799bb8f20a6e6aa78dac931230acc8a62a1d906fdc404a1a8bc2b00b6deef85

Contents?: true

Size: 741 Bytes

Versions: 2

Compression:

Stored size: 741 Bytes

Contents

# -*- encoding: utf-8 -*-

module TTY
  class Terminal

    # A class responsible for toggling echo.
    class Echo

      # Turn echo on
      #
      # @api public
      def on
        %x{stty echo} if TTY::System.unix?
      end

      # Turn echo off
      #
      # @api public
      def off
        %x{stty -echo} if TTY::System.unix?
      end

      # Wrap code block inside echo
      #
      # @api public
      def echo(is_on=true, &block)
        value = nil
        begin
          self.off unless is_on
          value = block.call if block_given?
          self.on
          return value
        rescue NoMethodError, Interrupt
          self.on
          exit
        end
      end

    end # Echo
  end # Terminal
end # TTY

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 lib/tty/terminal/echo.rb
tty-0.0.10 lib/tty/terminal/echo.rb