Class: TTY::Terminal::Raw

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

Overview

A class responsible for toggling raw mode.

Instance Method Summary collapse

Instance Method Details

#offObject

Turn raw mode off



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

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

#onObject

Turn raw mode on



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

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

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

Wrap code block inside raw mode



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

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