Class: Question::TTY

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

Defined Under Namespace

Modules: CODE, UI

Class Method Summary collapse

Class Method Details

.clearObject



52
53
54
55
# File 'lib/question/tty.rb', line 52

def self.clear
  print TTY::CODE::RESTORE
  print TTY::CODE::CLEAR_DOWN
end

.inputObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/question/tty.rb', line 57

def self.input
  input = $stdin.getch
  return input unless input == "\e"
  begin
    Timeout.timeout(0.01) do
      input += $stdin.getch
      input += $stdin.getch
    end
  rescue Timeout::Error
  end
  input
end

.interactive(&block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/question/tty.rb', line 39

def self.interactive(&block)
  begin
    print TTY::CODE::SAVE
    sync_value = $stdout.sync
    $stdout.sync = true
    print TTY::CODE::HIDE
    block.call
  ensure
    print TTY::CODE::SHOW
    $stdout.sync = sync_value
  end
end