Class: TTY
- Inherits:
-
Object
- Object
- TTY
- Defined in:
- lib/artoo/adaptors/keyboard.rb
Instance Attribute Summary collapse
-
#in_file ⇒ Object
readonly
Returns the value of attribute in_file.
-
#original_stty_state ⇒ Object
readonly
Returns the value of attribute original_stty_state.
-
#out_file ⇒ Object
readonly
Returns the value of attribute out_file.
Instance Method Summary collapse
- #configure ⇒ Object
- #get_char ⇒ Object
-
#initialize ⇒ TTY
constructor
A new instance of TTY.
- #puts ⇒ Object
- #restore ⇒ Object
- #stty(args) ⇒ Object
Constructor Details
#initialize ⇒ TTY
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_file ⇒ Object (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_state ⇒ Object (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_file ⇒ Object (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
#configure ⇒ Object
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_char ⇒ Object
97 98 99 |
# File 'lib/artoo/adaptors/keyboard.rb', line 97 def get_char in_file.getc end |
#puts ⇒ Object
101 102 103 |
# File 'lib/artoo/adaptors/keyboard.rb', line 101 def puts out_file.puts end |
#restore ⇒ Object
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 |