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



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

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

#offObject

Turn echo off



19
20
21
# File 'lib/tty/terminal/echo.rb', line 19

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

#onObject

Turn echo on



12
13
14
# File 'lib/tty/terminal/echo.rb', line 12

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