Class: TTY::Reader::Mode

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/reader/mode.rb

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin) ⇒ Mode

Initialize a Terminal



11
12
13
# File 'lib/tty/reader/mode.rb', line 11

def initialize(input = $stdin)
  @input = input
end

Instance Method Details

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

Echo given block

Parameters:

  • is_on (Boolean) (defaults to: true)


20
21
22
23
24
25
26
# File 'lib/tty/reader/mode.rb', line 20

def echo(is_on = true, &block)
  if is_on || !@input.tty?
    yield
  else
    @input.noecho(&block)
  end
end

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

Use raw mode in the given block

Parameters:

  • is_on (Boolean) (defaults to: true)


33
34
35
36
37
38
39
# File 'lib/tty/reader/mode.rb', line 33

def raw(is_on = true, &block)
  if is_on && @input.tty?
    @input.raw(&block)
  else
    yield
  end
end