Class: TTY::Terminal::Echo

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/terminal/echo.rb

Overview

A class responsible for toggling echo.

Instance Method Summary collapse

Instance Method Details

#echo(is_on = true, &block) ⇒ Object

Wrap code block inside echo



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tty/terminal/echo.rb', line 24

def echo(is_on=true, &block)
  value = nil
  begin
    off unless is_on
    value = block.call if block_given?
    on
    return value
  rescue NoMethodError, Interrupt
    on
    exit
  end
end

#offObject

Turn echo off



17
18
19
# File 'lib/tty/terminal/echo.rb', line 17

def off
  %x{stty -echo} if TTY::Platform.unix?
end

#onObject

Turn echo on



10
11
12
# File 'lib/tty/terminal/echo.rb', line 10

def on
  %x{stty echo} if TTY::Platform.unix?
end