Class: TTY

Inherits:
Object
  • Object
show all
Defined in:
lib/artoo/adaptors/keyboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTTY

Returns a new instance of TTY.



92
93
94
95
# File 'lib/artoo/adaptors/keyboard.rb', line 92

def initialize
  @in_file = File.open("/dev/tty", "r")
  @out_file = File.open("/dev/tty", "w")
end

Instance Attribute Details

#in_fileObject (readonly)

Returns the value of attribute in_file.



90
91
92
# File 'lib/artoo/adaptors/keyboard.rb', line 90

def in_file
  @in_file
end

#original_stty_stateObject (readonly)

Returns the value of attribute original_stty_state.



90
91
92
# File 'lib/artoo/adaptors/keyboard.rb', line 90

def original_stty_state
  @original_stty_state
end

#out_fileObject (readonly)

Returns the value of attribute out_file.



90
91
92
# File 'lib/artoo/adaptors/keyboard.rb', line 90

def out_file
  @out_file
end

Instance Method Details

#configureObject



109
110
111
112
113
114
115
# File 'lib/artoo/adaptors/keyboard.rb', line 109

def configure
  @original_stty_state = stty "-g"
  # raw: Disable input and output processing
  # -echo: Don't echo keys back
  # cbreak: Set up lots of standard stuff, including INTR signal on ^C
  stty "raw -echo cbreak"
end

#get_charObject



97
98
99
# File 'lib/artoo/adaptors/keyboard.rb', line 97

def get_char
  in_file.getc
end

#putsObject



101
102
103
# File 'lib/artoo/adaptors/keyboard.rb', line 101

def puts
  out_file.puts
end

#restoreObject



117
118
119
# File 'lib/artoo/adaptors/keyboard.rb', line 117

def restore
  stty "#{@original_stty_state}"
end

#stty(args) ⇒ Object



105
106
107
# File 'lib/artoo/adaptors/keyboard.rb', line 105

def stty(args)
  command("stty #{args}")
end