Class: TTY::Reader::Mode Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin) ⇒ Mode

Initialize a Terminal



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

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)


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

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)


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

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